@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,3 +1,5 @@
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
+
1
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
4
 
3
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); } }
@@ -5,50 +7,127 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
5
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); }); }; }
6
8
 
7
9
  import path from 'path';
8
- import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
9
- import { createPlugin, useAppContext } from '@modern-js/core';
10
+ import { fs, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from '@modern-js/utils';
11
+ import { jestConfigHook, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from '@modern-js/testing';
12
+ import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
13
+ import TestingBffPlugin from '@modern-js/testing-plugin-bff';
14
+ import { MODERNJS_CONFIG_KEY } from "../constant";
10
15
  import test from "./test";
11
- export default createPlugin(function () {
12
- var testingExportsUtils;
16
+ export var mergeUserJestConfig = function mergeUserJestConfig(testUtils) {
17
+ var resolveJestConfig = testUtils.testConfig.jest;
18
+
19
+ if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
20
+ testUtils.mergeJestConfig(resolveJestConfig);
21
+ }
22
+
23
+ if (typeof resolveJestConfig === 'function') {
24
+ resolveJestConfig(testUtils.jestConfig);
25
+ }
26
+ };
27
+ export default (function () {
28
+ var BffPlugin = TestingBffPlugin();
13
29
  return {
14
- commands: function commands(_ref) {
15
- var program = _ref.program;
16
- program.command('test').allowUnknownOption().usage('[options]').action( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
17
- return _regeneratorRuntime.wrap(function _callee$(_context) {
18
- while (1) {
19
- switch (_context.prev = _context.next) {
20
- case 0:
21
- _context.next = 2;
22
- return test();
23
-
24
- case 2:
25
- case "end":
26
- return _context.stop();
27
- }
28
- }
29
- }, _callee);
30
- })));
30
+ name: '@modern-js/plugin-testing',
31
+ usePlugins: [BffPlugin],
32
+ post: [BffPlugin.name],
33
+ registerHook: {
34
+ jestConfig: jestConfigHook
31
35
  },
32
- validateSchema: function validateSchema() {
33
- return PLUGIN_SCHEMAS['@modern-js/plugin-testing'];
34
- },
35
- config: function config() {
36
- // eslint-disable-next-line react-hooks/rules-of-hooks
37
- var appContext = useAppContext();
38
- testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'testing');
36
+ setup: function setup(api) {
37
+ var testingExportsUtils;
38
+ var appContext = api.useAppContext();
39
+ var userConfig = api.useResolvedConfigContext();
39
40
  return {
40
- source: {
41
- alias: {
42
- '@modern-js/runtime/testing': testingExportsUtils.getPath()
41
+ commands: function commands(_ref) {
42
+ var program = _ref.program;
43
+ program.command('test').allowUnknownOption().usage('[options]').action( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
44
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
45
+ while (1) {
46
+ switch (_context.prev = _context.next) {
47
+ case 0:
48
+ _context.next = 2;
49
+ return test(api);
50
+
51
+ case 2:
52
+ case "end":
53
+ return _context.stop();
54
+ }
55
+ }
56
+ }, _callee);
57
+ })));
58
+ },
59
+ validateSchema: function validateSchema() {
60
+ return PLUGIN_SCHEMAS['@modern-js/plugin-testing'];
61
+ },
62
+ config: function config() {
63
+ testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'testing');
64
+ return {
65
+ source: {
66
+ alias: {
67
+ '@modern-js/runtime/testing': testingExportsUtils.getPath()
68
+ }
69
+ }
70
+ };
71
+ },
72
+ addRuntimeExports: function addRuntimeExports() {
73
+ var testingPath = path.resolve(__dirname, '../');
74
+ testingExportsUtils.addExport("export * from '".concat(testingPath, "'"));
75
+ },
76
+ jestConfig: function () {
77
+ var _jestConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(utils, next) {
78
+ var existSrc, webpackConfig, _webpackConfig$resolv, alias;
79
+
80
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
81
+ while (1) {
82
+ switch (_context2.prev = _context2.next) {
83
+ case 0:
84
+ _context2.next = 2;
85
+ return fs.pathExists(appContext.srcDirectory);
86
+
87
+ case 2:
88
+ existSrc = _context2.sent;
89
+
90
+ if (existSrc) {
91
+ _context2.next = 5;
92
+ break;
93
+ }
94
+
95
+ return _context2.abrupt("return", next(utils));
96
+
97
+ case 5:
98
+ webpackConfig = getWebpackConfig(WebpackConfigTarget.CLIENT);
99
+ _webpackConfig$resolv = webpackConfig.resolve.alias, alias = _webpackConfig$resolv === void 0 ? {} : _webpackConfig$resolv;
100
+ utils.mergeJestConfig({
101
+ globals: _defineProperty({}, MODERNJS_CONFIG_KEY, userConfig),
102
+ moduleNameMapper: getModuleNameMapper(alias),
103
+ testEnvironment: 'jsdom',
104
+ resolver: DEFAULT_RESOLVER_PATH
105
+ });
106
+ utils.setJestConfig({
107
+ rootDir: appContext.appDirectory || process.cwd(),
108
+ // todo: diffrent test root for diffrent solutions
109
+ // testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
110
+ // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
111
+ testMatch: ["<rootDir>/src/**/*.test.[jt]s?(x)", "<rootDir>/tests/**/*.test.[jt]s?(x)", "<rootDir>/electron/**/*.test.[jt]s?(x)"]
112
+ });
113
+ mergeUserJestConfig(utils);
114
+ return _context2.abrupt("return", next(utils));
115
+
116
+ case 11:
117
+ case "end":
118
+ return _context2.stop();
119
+ }
120
+ }
121
+ }, _callee2);
122
+ }));
123
+
124
+ function jestConfig(_x, _x2) {
125
+ return _jestConfig.apply(this, arguments);
43
126
  }
44
- }
127
+
128
+ return jestConfig;
129
+ }()
45
130
  };
46
- },
47
- addRuntimeExports: function addRuntimeExports() {
48
- var testingPath = path.resolve(__dirname, '../');
49
- testingExportsUtils.addExport("export * from '".concat(testingPath, "'"));
50
131
  }
51
132
  };
52
- }, {
53
- name: '@modern-js/plugin-testing'
54
133
  });
@@ -1,47 +1,22 @@
1
1
  import _regeneratorRuntime from "@babel/runtime/regenerator";
2
2
 
3
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
-
5
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
-
7
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
-
9
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
-
11
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
12
-
13
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
14
-
15
3
  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); } }
16
4
 
17
5
  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); }); }; }
18
6
 
19
7
  import path from 'path';
20
8
  import { compiler } from '@modern-js/babel-compiler';
21
- import { useAppContext, useResolvedConfigContext } from '@modern-js/core';
22
9
  import { runTest } from '@modern-js/testing';
23
- import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
24
- import testingBffPlugin from '@modern-js/testing-plugin-bff';
25
- import { fs } from '@modern-js/utils';
26
- import modernTestPlugin from "./plugins/modern";
27
10
 
28
11
  var test = /*#__PURE__*/function () {
29
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
30
- var userConfig, config, srcDirectory, existSrc, jest, webpackConfigs, runtimeExportsPath;
12
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(api) {
13
+ var userConfig, appContext, jest, runtimeExportsPath;
31
14
  return _regeneratorRuntime.wrap(function _callee$(_context) {
32
15
  while (1) {
33
16
  switch (_context.prev = _context.next) {
34
17
  case 0:
35
- // eslint-disable-next-line react-hooks/rules-of-hooks
36
- userConfig = useResolvedConfigContext(); // eslint-disable-next-line react-hooks/rules-of-hooks
37
-
38
- config = useAppContext();
39
- srcDirectory = config.srcDirectory;
40
- _context.next = 5;
41
- return fs.pathExists(srcDirectory);
42
-
43
- case 5:
44
- existSrc = _context.sent;
18
+ userConfig = api.useResolvedConfigContext();
19
+ appContext = api.useAppContext();
45
20
  userConfig.testing = userConfig.testing || {};
46
21
  jest = userConfig.testing.jest || userConfig.tools.jest;
47
22
 
@@ -50,31 +25,8 @@ var test = /*#__PURE__*/function () {
50
25
  }
51
26
 
52
27
  userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
53
-
54
- if (existSrc) {
55
- // todo: consider lib-tools ...
56
- webpackConfigs = getWebpackConfig(WebpackConfigTarget.CLIENT);
57
- userConfig.testing.plugins = [].concat(_toConsumableArray(userConfig.testing.plugins || []), [modernTestPlugin(webpackConfigs, userConfig, config.appDirectory), testingBffPlugin({
58
- pwd: config.appDirectory,
59
- userConfig: userConfig,
60
- plugins: config.plugins.map(function (p) {
61
- return p.server;
62
- }).filter(Boolean),
63
- routes: config.serverRoutes
64
- })]);
65
- } else {
66
- userConfig.testing.plugins = [].concat(_toConsumableArray(userConfig.testing.plugins || []), [testingBffPlugin({
67
- pwd: config.appDirectory,
68
- userConfig: userConfig,
69
- plugins: config.plugins.map(function (p) {
70
- return p.server;
71
- }).filter(Boolean),
72
- routes: config.serverRoutes
73
- })]);
74
- }
75
-
76
- runtimeExportsPath = path.join(config.internalDirectory, '.runtime-exports');
77
- _context.next = 14;
28
+ runtimeExportsPath = path.join(appContext.internalDirectory, '.runtime-exports');
29
+ _context.next = 9;
78
30
  return compiler({
79
31
  sourceDir: runtimeExportsPath,
80
32
  rootDir: runtimeExportsPath,
@@ -86,11 +38,11 @@ var test = /*#__PURE__*/function () {
86
38
  }]]
87
39
  });
88
40
 
89
- case 14:
90
- _context.next = 16;
91
- return runTest(userConfig.testing);
41
+ case 9:
42
+ _context.next = 11;
43
+ return runTest(api, userConfig.testing);
92
44
 
93
- case 16:
45
+ case 11:
94
46
  case "end":
95
47
  return _context.stop();
96
48
  }
@@ -98,7 +50,7 @@ var test = /*#__PURE__*/function () {
98
50
  }, _callee);
99
51
  }));
100
52
 
101
- return function test() {
53
+ return function test(_x) {
102
54
  return _ref.apply(this, arguments);
103
55
  };
104
56
  }();
@@ -1 +1 @@
1
- export var modernjs_config_key = '__modernjs_config__';
1
+ export var MODERNJS_CONFIG_KEY = '__modernjs_config__';
@@ -11,7 +11,7 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
11
11
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
12
12
 
13
13
  import { createApp as _createApp } from '@modern-js/runtime-core';
14
- import { modernjs_config_key } from "../constant";
14
+ import { MODERNJS_CONFIG_KEY } from "../constant";
15
15
  import resolvePlugins from "./resolvePlugins";
16
16
 
17
17
  var ModernRuntime = /*#__PURE__*/function () {
@@ -61,4 +61,4 @@ var ModernRuntime = /*#__PURE__*/function () {
61
61
  return ModernRuntime;
62
62
  }();
63
63
 
64
- export default new ModernRuntime(global[modernjs_config_key] || {});
64
+ export default new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
@@ -8,7 +8,7 @@ import { createStore as originCreateStore } from '@modern-js-reduck/store';
8
8
  import effectsPlugin from '@modern-js-reduck/plugin-effects';
9
9
  import autoActionsPlugin from '@modern-js-reduck/plugin-auto-actions';
10
10
  import immerPlugin from '@modern-js-reduck/plugin-immutable';
11
- import { modernjs_config_key } from "../constant";
11
+ import { MODERNJS_CONFIG_KEY } from "../constant";
12
12
  export var effects = function effects() {
13
13
  return effectsPlugin;
14
14
  };
@@ -22,7 +22,7 @@ export var createStore = function createStore(props) {
22
22
  var createStatePlugins = function createStatePlugins() {
23
23
  var _modernConfig$runtime;
24
24
 
25
- var modernConfig = global[modernjs_config_key];
25
+ var modernConfig = global[MODERNJS_CONFIG_KEY];
26
26
  var stateConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig$runtime = modernConfig.runtime) === null || _modernConfig$runtime === void 0 ? void 0 : _modernConfig$runtime.state;
27
27
  var plugins = [];
28
28
 
@@ -1,3 +1,7 @@
1
- declare const _default: any;
1
+ import type { CliPlugin } from '@modern-js/core';
2
+ import { TestConfigOperator } from '@modern-js/testing';
3
+ export declare const mergeUserJestConfig: (testUtils: TestConfigOperator) => void;
4
+
5
+ declare const _default: () => CliPlugin;
2
6
 
3
7
  export default _default;
@@ -1,10 +1,3 @@
1
- declare const test: () => Promise<void>;
2
- export default test;
3
- declare module '@modern-js/core' {
4
- interface UserConfig {
5
- testing?: import('@modern-js/testing').TestConfig;
6
- }
7
- interface ToolsConfig {
8
- jest?: import('@modern-js/testing').TestConfig['jest'];
9
- }
10
- }
1
+ import type { PluginAPI } from '@modern-js/core';
2
+ declare const test: (api: PluginAPI) => Promise<void>;
3
+ export default test;
@@ -1 +1 @@
1
- export declare const modernjs_config_key = "__modernjs_config__";
1
+ export declare const MODERNJS_CONFIG_KEY = "__modernjs_config__";
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { UserConfig } from '@modern-js/core';
2
+ import type { UserConfig } from '@modern-js/core';
3
3
  interface CreateAppProps {
4
4
  entry?: string;
5
5
  children?: React.ReactElement;
@@ -1,2 +1,2 @@
1
- import { NormalizedConfig } from '@modern-js/core';
1
+ import type { NormalizedConfig } from '@modern-js/core';
2
2
  export default function resolvePlugins(features: NormalizedConfig['runtime']): any[];
package/jest.config.js CHANGED
@@ -2,7 +2,6 @@ const sharedConfig = require('@scripts/jest-config');
2
2
 
3
3
  /** @type {import('@jest/types').Config.InitialOptions} */
4
4
  module.exports = {
5
- // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
5
  ...sharedConfig,
7
6
  rootDir: __dirname,
8
7
  };
package/package.json CHANGED
@@ -11,13 +11,17 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.3.4",
14
+ "version": "1.4.2",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
18
18
  "module": "./dist/js/treeshaking/index.js",
19
19
  "jsnext:modern": "./dist/js/modern/index.js",
20
20
  "exports": {
21
+ "./types": {
22
+ "jsnext:source": "./type.d.ts",
23
+ "default": "./type.d.ts"
24
+ },
21
25
  "./type": {
22
26
  "jsnext:source": "./type.d.ts",
23
27
  "default": "./type.d.ts"
@@ -68,6 +72,9 @@
68
72
  "type": [
69
73
  "./type.d.ts"
70
74
  ],
75
+ "types": [
76
+ "./type.d.ts"
77
+ ],
71
78
  "runtime-base": [
72
79
  "./dist/types/runtime-testing/base.d.ts"
73
80
  ]
@@ -77,21 +84,19 @@
77
84
  "@babel/preset-env": "^7.15.6",
78
85
  "@babel/runtime": "^7",
79
86
  "@modern-js/babel-compiler": "^1.2.1",
80
- "@modern-js/testing": "^1.3.2",
81
- "@modern-js/utils": "^1.3.2",
82
- "@modern-js/webpack": "^1.4.0",
87
+ "@modern-js/testing": "^1.4.2",
88
+ "@modern-js/utils": "^1.4.0",
89
+ "@modern-js/webpack": "^1.5.4",
83
90
  "@testing-library/jest-dom": "^5.14.1",
84
91
  "@testing-library/react": "^12.0.0",
85
- "enhanced-resolve": "^5.8.3",
86
- "@modern-js/testing-plugin-bff": "^1.2.2"
92
+ "@modern-js/testing-plugin-bff": "^1.3.1"
87
93
  },
88
94
  "peerDependencies": {
89
95
  "@modern-js-reduck/plugin-auto-actions": "^1.0.0",
90
96
  "@modern-js-reduck/plugin-effects": "^1.0.0",
91
97
  "@modern-js-reduck/plugin-immutable": "^1.0.0",
92
98
  "@modern-js-reduck/store": "^1.0.0",
93
- "@modern-js/core": "^1.4.3",
94
- "@modern-js/runtime-core": "^1.2.1"
99
+ "@modern-js/runtime-core": "^1.4.1"
95
100
  },
96
101
  "devDependencies": {
97
102
  "@modern-js-reduck/plugin-auto-actions": "^1.0.0",
@@ -99,8 +104,8 @@
99
104
  "@modern-js-reduck/plugin-immutable": "^1.0.0",
100
105
  "@modern-js-reduck/store": "^1.0.0",
101
106
  "@scripts/build": "0.0.0",
102
- "@modern-js/core": "^1.4.3",
103
- "@modern-js/runtime-core": "^1.2.1",
107
+ "@modern-js/core": "1.7.0",
108
+ "@modern-js/runtime-core": "1.4.1",
104
109
  "@types/jest": "^26",
105
110
  "@types/node": "^14",
106
111
  "@types/react": "^17",
@@ -119,6 +124,7 @@
119
124
  },
120
125
  "scripts": {
121
126
  "new": "modern new",
127
+ "dev": "modern build --watch",
122
128
  "build": "modern build",
123
129
  "test": "jest --passWithNoTests"
124
130
  },
@@ -1,57 +1,54 @@
1
- import { mergeUserJestConfig } from "./modern";
2
- describe('modern plugin', () => {
1
+ import { mergeUserJestConfig } from '../src/cli';
2
+
3
+ describe('mergeUserJestConfig', () => {
3
4
  test('mergeUserJestConfig support object', () => {
4
- const testUtils = {
5
+ const testUtils: any = {
5
6
  _jestConfig: {
6
- a: 1
7
+ a: 1,
7
8
  },
8
-
9
9
  get jestConfig() {
10
10
  return this._jestConfig;
11
11
  },
12
-
13
12
  testConfig: {
14
13
  jest: {
15
- b: 1
16
- }
14
+ b: 1,
15
+ },
17
16
  },
18
-
19
- mergeJestConfig(config) {
17
+ mergeJestConfig(config: Record<string, string>) {
20
18
  Object.assign(this._jestConfig, config);
21
- }
22
-
19
+ },
23
20
  };
21
+
24
22
  mergeUserJestConfig(testUtils);
23
+
25
24
  expect(testUtils.jestConfig).toEqual({
26
25
  a: 1,
27
- b: 1
26
+ b: 1,
28
27
  });
29
28
  });
29
+
30
30
  test('mergeUserJestConfig support function', () => {
31
- const testUtils = {
31
+ const testUtils: any = {
32
32
  _jestConfig: {
33
- a: 1
33
+ a: 1,
34
34
  },
35
-
36
35
  get jestConfig() {
37
36
  return this._jestConfig;
38
37
  },
39
-
40
38
  testConfig: {
41
- jest: jestConfig => {
39
+ jest: (jestConfig: Record<string, number>) => {
42
40
  jestConfig.b = 1;
43
- }
41
+ },
44
42
  },
45
-
46
- mergeJestConfig(config) {
43
+ mergeJestConfig(config: Record<string, string>) {
47
44
  Object.assign(this._jestConfig, config);
48
- }
49
-
45
+ },
50
46
  };
47
+
51
48
  mergeUserJestConfig(testUtils);
52
49
  expect(testUtils.jestConfig).toEqual({
53
50
  a: 1,
54
- b: 1
51
+ b: 1,
55
52
  });
56
53
  });
57
- });
54
+ });
package/type.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import '@modern-js/core';
2
1
  import "@testing-library/react"
3
2
  import "@testing-library/jest-dom"
4
3
  import "./dist/types/runtime-testing"
@@ -7,13 +6,3 @@ declare module '@modern-js/runtime/testing' {
7
6
  export * from '@testing-library/react';
8
7
  export { renderApp, createStore, testBff } from './dist/types/runtime-testing';
9
8
  }
10
-
11
- declare module '@modern-js/core' {
12
- interface UserConfig {
13
- testing?: import('@modern-js/testing').TestConfig;
14
- }
15
-
16
- interface ToolsConfig {
17
- jest?: import('@modern-js/testing').TestConfig['jest'];
18
- }
19
- }
@@ -1,43 +0,0 @@
1
- import { createPlugin, getModuleNameMapper } from '@modern-js/testing';
2
- import { modernjs_config_key } from "../../constant";
3
- export const mergeUserJestConfig = async testUtils => {
4
- const resolveJestConfig = testUtils.testConfig.jest;
5
-
6
- if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
7
- testUtils.mergeJestConfig(resolveJestConfig);
8
- }
9
-
10
- if (typeof resolveJestConfig === 'function') {
11
- await resolveJestConfig(testUtils.jestConfig);
12
- }
13
- };
14
- export default ((webpackConfig, userConfig, pwd) => createPlugin(() => {
15
- const {
16
- resolve: {
17
- alias = {}
18
- }
19
- } = webpackConfig;
20
- return {
21
- jestConfig: (utils, next) => {
22
- utils.mergeJestConfig({
23
- globals: {
24
- [modernjs_config_key]: userConfig
25
- },
26
- moduleNameMapper: getModuleNameMapper(alias),
27
- testEnvironment: 'jsdom',
28
- resolver: require.resolve("../resolver")
29
- });
30
- utils.setJestConfig({
31
- rootDir: pwd || process.cwd(),
32
- // todo: diffrent test root for diffrent solutions
33
- // testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
34
- // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
35
- testMatch: [`<rootDir>/src/**/*.test.[jt]s?(x)`, `<rootDir>/tests/**/*.test.[jt]s?(x)`, `<rootDir>/electron/**/*.test.[jt]s?(x)`]
36
- });
37
- mergeUserJestConfig(utils);
38
- return next(utils);
39
- }
40
- };
41
- }, {
42
- name: '@modern-js/testing-plugin-modern'
43
- }));
@@ -1,15 +0,0 @@
1
- import enhanceResolve from 'enhanced-resolve';
2
- const resolver = enhanceResolve.create.sync({
3
- conditionNames: ['require', 'node', 'default'],
4
- extensions: ['.js', '.json', '.node', '.ts', '.tsx']
5
- });
6
-
7
- const shouldResolveByEnhance = url => /^@[^/]+\/[^/]+\/.*/.test(url);
8
-
9
- module.exports = function (request, options) {
10
- if (shouldResolveByEnhance(request)) {
11
- return resolver(options.basedir, request);
12
- }
13
-
14
- return options.defaultResolver(request, options);
15
- };
@@ -1,57 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.mergeUserJestConfig = exports.default = void 0;
7
-
8
- var _testing = require("@modern-js/testing");
9
-
10
- var _constant = require("../../constant");
11
-
12
- const mergeUserJestConfig = async testUtils => {
13
- const resolveJestConfig = testUtils.testConfig.jest;
14
-
15
- if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
16
- testUtils.mergeJestConfig(resolveJestConfig);
17
- }
18
-
19
- if (typeof resolveJestConfig === 'function') {
20
- await resolveJestConfig(testUtils.jestConfig);
21
- }
22
- };
23
-
24
- exports.mergeUserJestConfig = mergeUserJestConfig;
25
-
26
- var _default = (webpackConfig, userConfig, pwd) => (0, _testing.createPlugin)(() => {
27
- const {
28
- resolve: {
29
- alias = {}
30
- }
31
- } = webpackConfig;
32
- return {
33
- jestConfig: (utils, next) => {
34
- utils.mergeJestConfig({
35
- globals: {
36
- [_constant.modernjs_config_key]: userConfig
37
- },
38
- moduleNameMapper: (0, _testing.getModuleNameMapper)(alias),
39
- testEnvironment: 'jsdom',
40
- resolver: require.resolve("../resolver")
41
- });
42
- utils.setJestConfig({
43
- rootDir: pwd || process.cwd(),
44
- // todo: diffrent test root for diffrent solutions
45
- // testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
46
- // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
47
- testMatch: [`<rootDir>/src/**/*.test.[jt]s?(x)`, `<rootDir>/tests/**/*.test.[jt]s?(x)`, `<rootDir>/electron/**/*.test.[jt]s?(x)`]
48
- });
49
- mergeUserJestConfig(utils);
50
- return next(utils);
51
- }
52
- };
53
- }, {
54
- name: '@modern-js/testing-plugin-modern'
55
- });
56
-
57
- exports.default = _default;