@modern-js/plugin-testing 1.3.4 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/js/modern/cli/index.js +83 -29
  3. package/dist/js/modern/cli/test.js +5 -35
  4. package/dist/js/modern/constant.js +1 -1
  5. package/dist/js/modern/runtime-testing/app.js +2 -2
  6. package/dist/js/modern/runtime-testing/reduck.js +2 -2
  7. package/dist/js/node/cli/index.js +91 -31
  8. package/dist/js/node/cli/test.js +5 -39
  9. package/dist/js/node/constant.js +3 -3
  10. package/dist/js/node/runtime-testing/app.js +1 -1
  11. package/dist/js/node/runtime-testing/reduck.js +1 -1
  12. package/dist/js/treeshaking/cli/index.js +117 -38
  13. package/dist/js/treeshaking/cli/test.js +11 -59
  14. package/dist/js/treeshaking/constant.js +1 -1
  15. package/dist/js/treeshaking/runtime-testing/app.js +2 -2
  16. package/dist/js/treeshaking/runtime-testing/reduck.js +2 -2
  17. package/dist/types/cli/index.d.ts +5 -1
  18. package/dist/types/cli/test.d.ts +3 -10
  19. package/dist/types/constant.d.ts +1 -1
  20. package/dist/types/runtime-testing/app.d.ts +1 -1
  21. package/dist/types/runtime-testing/resolvePlugins.d.ts +1 -1
  22. package/jest.config.js +0 -1
  23. package/package.json +16 -10
  24. package/{dist/js/modern/cli/plugins/modern.test.js → tests/merge-config.test.ts} +22 -25
  25. package/type.d.ts +0 -11
  26. package/dist/js/modern/cli/plugins/modern.js +0 -43
  27. package/dist/js/modern/cli/resolver.js +0 -15
  28. package/dist/js/node/cli/plugins/modern.js +0 -57
  29. package/dist/js/node/cli/plugins/modern.test.js +0 -60
  30. package/dist/js/node/cli/resolver.js +0 -20
  31. package/dist/js/treeshaking/cli/plugins/modern.js +0 -70
  32. package/dist/js/treeshaking/cli/plugins/modern.test.js +0 -53
  33. package/dist/js/treeshaking/cli/resolver.js +0 -17
  34. package/dist/types/cli/plugins/modern.d.ts +0 -6
  35. package/dist/types/cli/plugins/modern.test.d.ts +0 -1
  36. package/dist/types/cli/resolver.d.ts +0 -1
  37. package/tests/resolver.test.ts +0 -30
@@ -1,60 +0,0 @@
1
- "use strict";
2
-
3
- var _modern = require("./modern");
4
-
5
- describe('modern plugin', () => {
6
- test('mergeUserJestConfig support object', () => {
7
- const testUtils = {
8
- _jestConfig: {
9
- a: 1
10
- },
11
-
12
- get jestConfig() {
13
- return this._jestConfig;
14
- },
15
-
16
- testConfig: {
17
- jest: {
18
- b: 1
19
- }
20
- },
21
-
22
- mergeJestConfig(config) {
23
- Object.assign(this._jestConfig, config);
24
- }
25
-
26
- };
27
- (0, _modern.mergeUserJestConfig)(testUtils);
28
- expect(testUtils.jestConfig).toEqual({
29
- a: 1,
30
- b: 1
31
- });
32
- });
33
- test('mergeUserJestConfig support function', () => {
34
- const testUtils = {
35
- _jestConfig: {
36
- a: 1
37
- },
38
-
39
- get jestConfig() {
40
- return this._jestConfig;
41
- },
42
-
43
- testConfig: {
44
- jest: jestConfig => {
45
- jestConfig.b = 1;
46
- }
47
- },
48
-
49
- mergeJestConfig(config) {
50
- Object.assign(this._jestConfig, config);
51
- }
52
-
53
- };
54
- (0, _modern.mergeUserJestConfig)(testUtils);
55
- expect(testUtils.jestConfig).toEqual({
56
- a: 1,
57
- b: 1
58
- });
59
- });
60
- });
@@ -1,20 +0,0 @@
1
- "use strict";
2
-
3
- var _enhancedResolve = _interopRequireDefault(require("enhanced-resolve"));
4
-
5
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
6
-
7
- const resolver = _enhancedResolve.default.create.sync({
8
- conditionNames: ['require', 'node', 'default'],
9
- extensions: ['.js', '.json', '.node', '.ts', '.tsx']
10
- });
11
-
12
- const shouldResolveByEnhance = url => /^@[^/]+\/[^/]+\/.*/.test(url);
13
-
14
- module.exports = function (request, options) {
15
- if (shouldResolveByEnhance(request)) {
16
- return resolver(options.basedir, request);
17
- }
18
-
19
- return options.defaultResolver(request, options);
20
- };
@@ -1,70 +0,0 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
- import _regeneratorRuntime from "@babel/runtime/regenerator";
4
-
5
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
-
7
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
8
-
9
- import { createPlugin, getModuleNameMapper } from '@modern-js/testing';
10
- import { modernjs_config_key } from "../../constant";
11
- export var mergeUserJestConfig = /*#__PURE__*/function () {
12
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(testUtils) {
13
- var resolveJestConfig;
14
- return _regeneratorRuntime.wrap(function _callee$(_context) {
15
- while (1) {
16
- switch (_context.prev = _context.next) {
17
- case 0:
18
- resolveJestConfig = testUtils.testConfig.jest;
19
-
20
- if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
21
- testUtils.mergeJestConfig(resolveJestConfig);
22
- }
23
-
24
- if (!(typeof resolveJestConfig === 'function')) {
25
- _context.next = 5;
26
- break;
27
- }
28
-
29
- _context.next = 5;
30
- return resolveJestConfig(testUtils.jestConfig);
31
-
32
- case 5:
33
- case "end":
34
- return _context.stop();
35
- }
36
- }
37
- }, _callee);
38
- }));
39
-
40
- return function mergeUserJestConfig(_x) {
41
- return _ref.apply(this, arguments);
42
- };
43
- }();
44
- export default (function (webpackConfig, userConfig, pwd) {
45
- return createPlugin(function () {
46
- var _webpackConfig$resolv = webpackConfig.resolve.alias,
47
- alias = _webpackConfig$resolv === void 0 ? {} : _webpackConfig$resolv;
48
- return {
49
- jestConfig: function jestConfig(utils, next) {
50
- utils.mergeJestConfig({
51
- globals: _defineProperty({}, modernjs_config_key, userConfig),
52
- moduleNameMapper: getModuleNameMapper(alias),
53
- testEnvironment: 'jsdom',
54
- resolver: require.resolve("../resolver")
55
- });
56
- utils.setJestConfig({
57
- rootDir: pwd || process.cwd(),
58
- // todo: diffrent test root for diffrent solutions
59
- // testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
60
- // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
61
- testMatch: ["<rootDir>/src/**/*.test.[jt]s?(x)", "<rootDir>/tests/**/*.test.[jt]s?(x)", "<rootDir>/electron/**/*.test.[jt]s?(x)"]
62
- });
63
- mergeUserJestConfig(utils);
64
- return next(utils);
65
- }
66
- };
67
- }, {
68
- name: '@modern-js/testing-plugin-modern'
69
- });
70
- });
@@ -1,53 +0,0 @@
1
- import { mergeUserJestConfig } from "./modern";
2
- describe('modern plugin', function () {
3
- test('mergeUserJestConfig support object', function () {
4
- var testUtils = {
5
- _jestConfig: {
6
- a: 1
7
- },
8
-
9
- get jestConfig() {
10
- return this._jestConfig;
11
- },
12
-
13
- testConfig: {
14
- jest: {
15
- b: 1
16
- }
17
- },
18
- mergeJestConfig: function mergeJestConfig(config) {
19
- Object.assign(this._jestConfig, config);
20
- }
21
- };
22
- mergeUserJestConfig(testUtils);
23
- expect(testUtils.jestConfig).toEqual({
24
- a: 1,
25
- b: 1
26
- });
27
- });
28
- test('mergeUserJestConfig support function', function () {
29
- var testUtils = {
30
- _jestConfig: {
31
- a: 1
32
- },
33
-
34
- get jestConfig() {
35
- return this._jestConfig;
36
- },
37
-
38
- testConfig: {
39
- jest: function jest(jestConfig) {
40
- jestConfig.b = 1;
41
- }
42
- },
43
- mergeJestConfig: function mergeJestConfig(config) {
44
- Object.assign(this._jestConfig, config);
45
- }
46
- };
47
- mergeUserJestConfig(testUtils);
48
- expect(testUtils.jestConfig).toEqual({
49
- a: 1,
50
- b: 1
51
- });
52
- });
53
- });
@@ -1,17 +0,0 @@
1
- import enhanceResolve from 'enhanced-resolve';
2
- var resolver = enhanceResolve.create.sync({
3
- conditionNames: ['require', 'node', 'default'],
4
- extensions: ['.js', '.json', '.node', '.ts', '.tsx']
5
- });
6
-
7
- var shouldResolveByEnhance = function shouldResolveByEnhance(url) {
8
- return /^@[^/]+\/[^/]+\/.*/.test(url);
9
- };
10
-
11
- module.exports = function (request, options) {
12
- if (shouldResolveByEnhance(request)) {
13
- return resolver(options.basedir, request);
14
- }
15
-
16
- return options.defaultResolver(request, options);
17
- };
@@ -1,6 +0,0 @@
1
- import type { NormalizedConfig } from '@modern-js/core';
2
- export declare const mergeUserJestConfig: (testUtils: any) => Promise<void>;
3
-
4
- declare const _default: (webpackConfig: any, userConfig: NormalizedConfig, pwd: string) => any;
5
-
6
- export default _default;
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,30 +0,0 @@
1
- import path from 'path';
2
- import { fs } from '@modern-js/utils';
3
-
4
- const resolver = require('../src/cli/resolver');
5
-
6
- describe('plugin-testing', () => {
7
- it('resolver', () => {
8
- const moduleDir = path.join(
9
- __dirname,
10
- 'node_modules/@modern-js/runtime/module',
11
- );
12
- fs.ensureDirSync(moduleDir);
13
- fs.writeJSONSync(
14
- path.join(moduleDir, 'package.json'),
15
- {
16
- name: '@modern-js/runtime/module',
17
- main: './index.js',
18
- },
19
- 'utf-8',
20
- );
21
- fs.writeFileSync(
22
- path.join(moduleDir, 'index.js'),
23
- 'module.exports = "@modern-js/runtime/module"',
24
- 'utf-8',
25
- );
26
- expect(
27
- resolver('@modern-js/runtime/module', { basedir: __dirname }),
28
- ).toContain('module');
29
- });
30
- });