@modern-js/plugin-testing 1.2.3-rc.0 → 1.3.3-beta.0

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 (42) hide show
  1. package/CHANGELOG.md +49 -14
  2. package/dist/js/modern/cli/plugins/modern.js +12 -2
  3. package/dist/js/modern/cli/plugins/modern.test.js +69 -0
  4. package/dist/js/modern/cli/test.js +6 -0
  5. package/dist/js/modern/runtime-testing/app.js +1 -1
  6. package/dist/js/modern/runtime-testing/base.js +3 -0
  7. package/dist/js/modern/runtime-testing/index.js +2 -4
  8. package/dist/js/node/cli/plugins/modern.js +18 -1
  9. package/dist/js/node/cli/plugins/modern.test.js +72 -0
  10. package/dist/js/node/cli/test.js +6 -0
  11. package/dist/js/node/runtime-testing/app.js +2 -2
  12. package/dist/js/node/runtime-testing/base.js +41 -0
  13. package/dist/js/node/runtime-testing/index.js +5 -29
  14. package/dist/js/treeshaking/cli/plugins/modern.js +40 -2
  15. package/dist/js/treeshaking/cli/plugins/modern.test.js +65 -0
  16. package/dist/js/treeshaking/cli/test.js +11 -5
  17. package/dist/js/treeshaking/runtime-testing/app.js +1 -1
  18. package/dist/js/treeshaking/runtime-testing/base.js +3 -0
  19. package/dist/js/treeshaking/runtime-testing/index.js +2 -4
  20. package/dist/types/cli/plugins/modern.d.ts +5 -1
  21. package/dist/types/cli/plugins/modern.test.d.ts +1 -0
  22. package/{src/runtime-testing/index.ts → dist/types/runtime-testing/base.d.ts} +1 -2
  23. package/dist/types/runtime-testing/index.d.ts +2 -4
  24. package/jest.config.js +8 -0
  25. package/package.json +41 -20
  26. package/tests/.eslintrc.js +6 -0
  27. package/tests/index.test.ts +7 -0
  28. package/tests/resolver.test.ts +30 -0
  29. package/tests/tsconfig.json +13 -0
  30. package/tsconfig.json +1 -3
  31. package/type.d.ts +5 -1
  32. package/src/.eslintrc.json +0 -3
  33. package/src/cli/index.ts +0 -48
  34. package/src/cli/plugins/modern.ts +0 -64
  35. package/src/cli/resolver.ts +0 -16
  36. package/src/cli/test.ts +0 -70
  37. package/src/constant.ts +0 -1
  38. package/src/index.ts +0 -4
  39. package/src/runtime-testing/app.ts +0 -48
  40. package/src/runtime-testing/customRender.ts +0 -11
  41. package/src/runtime-testing/reduck.ts +0 -38
  42. package/src/runtime-testing/resolvePlugins.ts +0 -23
package/CHANGELOG.md CHANGED
@@ -1,22 +1,57 @@
1
1
  # @modern-js/plugin-testing
2
2
 
3
- ## 1.2.3-rc.0
3
+ ## 1.3.2
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - Updated dependencies [4a281912]
8
- - Updated dependencies [b715c994]
9
- - Updated dependencies [2da27d3b]
10
- - Updated dependencies [4a281912]
11
- - Updated dependencies [b7fb82ec]
12
- - Updated dependencies [eb026119]
13
- - @modern-js/runtime-core@1.1.3-rc.0
14
- - @modern-js/testing-plugin-bff@1.1.3-rc.0
15
- - @modern-js/babel-compiler@1.1.4-rc.0
16
- - @modern-js/utils@1.1.6-rc.0
17
- - @modern-js/core@1.2.1-rc.0
18
- - @modern-js/webpack@1.1.4-rc.0
19
- - @modern-js/testing@1.2.1-rc.0
7
+ - b57ded28: fix testing resolver
8
+ - 1b22634e: fix: plugin testing types
9
+ - Updated dependencies [7dc5aa75]
10
+ - @modern-js/webpack@1.2.2
11
+
12
+ ## 1.3.1
13
+
14
+ ### Patch Changes
15
+
16
+ - 83166714: change .npmignore
17
+ - Updated dependencies [83166714]
18
+ - Updated dependencies [c3de9882]
19
+ - Updated dependencies [33ff48af]
20
+ - Updated dependencies [c74597bd]
21
+ - @modern-js/core@1.3.2
22
+ - @modern-js/webpack@1.2.1
23
+ - @modern-js/testing@1.3.1
24
+ - @modern-js/testing-plugin-bff@1.2.1
25
+ - @modern-js/runtime-core@1.2.1
26
+ - @modern-js/babel-compiler@1.2.1
27
+ - @modern-js/utils@1.2.2
28
+
29
+ ## 1.3.0
30
+
31
+ ### Minor Changes
32
+
33
+ - cfe11628: Make Modern.js self bootstraping
34
+
35
+ ### Patch Changes
36
+
37
+ - c3d46ee4: fix: test config invalid
38
+ - Updated dependencies [2da09c69]
39
+ - Updated dependencies [5597289b]
40
+ - Updated dependencies [fc71e36f]
41
+ - Updated dependencies [4a85378c]
42
+ - Updated dependencies [a2cb9abc]
43
+ - Updated dependencies [e453e421]
44
+ - Updated dependencies [c3d46ee4]
45
+ - Updated dependencies [cfe11628]
46
+ - Updated dependencies [146dcd85]
47
+ - Updated dependencies [1ebc7ee2]
48
+ - @modern-js/utils@1.2.0
49
+ - @modern-js/webpack@1.2.0
50
+ - @modern-js/core@1.3.0
51
+ - @modern-js/runtime-core@1.2.0
52
+ - @modern-js/testing@1.3.0
53
+ - @modern-js/testing-plugin-bff@1.2.0
54
+ - @modern-js/babel-compiler@1.2.0
20
55
 
21
56
  ## 1.2.1
22
57
 
@@ -1,8 +1,7 @@
1
1
  import path from 'path';
2
2
  import { createPlugin } from '@modern-js/testing';
3
3
  import { modernjs_config_key } from "../../constant";
4
-
5
- const getModuleNameMapper = config => {
4
+ export const getModuleNameMapper = config => {
6
5
  const {
7
6
  resolve: {
8
7
  alias = {}
@@ -27,7 +26,17 @@ const getModuleNameMapper = config => {
27
26
  return memo;
28
27
  }, {});
29
28
  };
29
+ export const mergeUserJestConfig = async testUtils => {
30
+ const resolveJestConfig = testUtils.testConfig.jest;
31
+
32
+ if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
33
+ testUtils.mergeJestConfig(resolveJestConfig);
34
+ }
30
35
 
36
+ if (typeof resolveJestConfig === 'function') {
37
+ await resolveJestConfig(testUtils.jestConfig);
38
+ }
39
+ };
31
40
  export default ((webpackConfig, userConfig, pwd) => createPlugin(() => ({
32
41
  jestConfig: (utils, next) => {
33
42
  utils.mergeJestConfig({
@@ -45,6 +54,7 @@ export default ((webpackConfig, userConfig, pwd) => createPlugin(() => ({
45
54
  // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
46
55
  testMatch: [`<rootDir>/src/**/*.test.[jt]s?(x)`, `<rootDir>/tests/**/*.test.[jt]s?(x)`, `<rootDir>/electron/**/*.test.[jt]s?(x)`]
47
56
  });
57
+ mergeUserJestConfig(utils);
48
58
  return next(utils);
49
59
  }
50
60
  }), {
@@ -0,0 +1,69 @@
1
+ import { mergeUserJestConfig, getModuleNameMapper } from "./modern";
2
+ describe('modern plugin', () => {
3
+ test('mergeUserJestConfig support object', () => {
4
+ const 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
+
19
+ mergeJestConfig(config) {
20
+ Object.assign(this._jestConfig, config);
21
+ }
22
+
23
+ };
24
+ mergeUserJestConfig(testUtils);
25
+ expect(testUtils.jestConfig).toEqual({
26
+ a: 1,
27
+ b: 1
28
+ });
29
+ });
30
+ test('mergeUserJestConfig support function', () => {
31
+ const testUtils = {
32
+ _jestConfig: {
33
+ a: 1
34
+ },
35
+
36
+ get jestConfig() {
37
+ return this._jestConfig;
38
+ },
39
+
40
+ testConfig: {
41
+ jest: jestConfig => {
42
+ jestConfig.b = 1;
43
+ }
44
+ },
45
+
46
+ mergeJestConfig(config) {
47
+ Object.assign(this._jestConfig, config);
48
+ }
49
+
50
+ };
51
+ mergeUserJestConfig(testUtils);
52
+ expect(testUtils.jestConfig).toEqual({
53
+ a: 1,
54
+ b: 1
55
+ });
56
+ }); // TODO: 临时测试代码,待补充
57
+
58
+ test('getModuleNameMapper', () => {
59
+ const mockConfig = {
60
+ resolve: {
61
+ alias: {
62
+ '@modern-js/runtime/core': '/xxx'
63
+ }
64
+ }
65
+ };
66
+ const alias = getModuleNameMapper(mockConfig);
67
+ expect(alias).toBeDefined();
68
+ });
69
+ });
@@ -14,6 +14,12 @@ const test = async () => {
14
14
 
15
15
  const webpackConfigs = getWebpackConfig(WebpackConfigTarget.CLIENT);
16
16
  userConfig.testing = userConfig.testing || {};
17
+ const jest = userConfig.testing.jest || userConfig.tools.jest;
18
+
19
+ if (Array.isArray(jest)) {
20
+ userConfig.testing.jest = jest[0];
21
+ }
22
+
17
23
  userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
18
24
  userConfig.testing.plugins = [...(userConfig.testing.plugins || []), modernTestPlugin(webpackConfigs, userConfig, config.appDirectory), testingBffPlugin({
19
25
  pwd: config.appDirectory,
@@ -5,8 +5,8 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
5
  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; }
6
6
 
7
7
  import { createApp } from '@modern-js/runtime-core';
8
- import resolvePlugins from "./resolvePlugins";
9
8
  import { modernjs_config_key } from "../constant";
9
+ import resolvePlugins from "./resolvePlugins";
10
10
 
11
11
  class ModernRuntime {
12
12
  constructor(options) {
@@ -0,0 +1,3 @@
1
+ export { default as renderApp } from "./customRender";
2
+ export * from '@testing-library/react';
3
+ export { testBff } from '@modern-js/testing-plugin-bff';
@@ -1,4 +1,2 @@
1
- export { default as renderApp } from "./customRender";
2
- export * from '@testing-library/react';
3
- export * from "./reduck";
4
- export { testBff } from '@modern-js/testing-plugin-bff';
1
+ export * from "./base";
2
+ export * from "./reduck";
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.mergeUserJestConfig = exports.getModuleNameMapper = exports.default = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
 
@@ -41,6 +41,22 @@ const getModuleNameMapper = config => {
41
41
  }, {});
42
42
  };
43
43
 
44
+ exports.getModuleNameMapper = getModuleNameMapper;
45
+
46
+ const mergeUserJestConfig = async testUtils => {
47
+ const resolveJestConfig = testUtils.testConfig.jest;
48
+
49
+ if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
50
+ testUtils.mergeJestConfig(resolveJestConfig);
51
+ }
52
+
53
+ if (typeof resolveJestConfig === 'function') {
54
+ await resolveJestConfig(testUtils.jestConfig);
55
+ }
56
+ };
57
+
58
+ exports.mergeUserJestConfig = mergeUserJestConfig;
59
+
44
60
  var _default = (webpackConfig, userConfig, pwd) => (0, _testing.createPlugin)(() => ({
45
61
  jestConfig: (utils, next) => {
46
62
  utils.mergeJestConfig({
@@ -58,6 +74,7 @@ var _default = (webpackConfig, userConfig, pwd) => (0, _testing.createPlugin)(()
58
74
  // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
59
75
  testMatch: [`<rootDir>/src/**/*.test.[jt]s?(x)`, `<rootDir>/tests/**/*.test.[jt]s?(x)`, `<rootDir>/electron/**/*.test.[jt]s?(x)`]
60
76
  });
77
+ mergeUserJestConfig(utils);
61
78
  return next(utils);
62
79
  }
63
80
  }), {
@@ -0,0 +1,72 @@
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
+ }); // TODO: 临时测试代码,待补充
60
+
61
+ test('getModuleNameMapper', () => {
62
+ const mockConfig = {
63
+ resolve: {
64
+ alias: {
65
+ '@modern-js/runtime/core': '/xxx'
66
+ }
67
+ }
68
+ };
69
+ const alias = (0, _modern.getModuleNameMapper)(mockConfig);
70
+ expect(alias).toBeDefined();
71
+ });
72
+ });
@@ -29,6 +29,12 @@ const test = async () => {
29
29
 
30
30
  const webpackConfigs = (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT);
31
31
  userConfig.testing = userConfig.testing || {};
32
+ const jest = userConfig.testing.jest || userConfig.tools.jest;
33
+
34
+ if (Array.isArray(jest)) {
35
+ userConfig.testing.jest = jest[0];
36
+ }
37
+
32
38
  userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
33
39
  userConfig.testing.plugins = [...(userConfig.testing.plugins || []), (0, _modern.default)(webpackConfigs, userConfig, config.appDirectory), (0, _testingPluginBff.default)({
34
40
  pwd: config.appDirectory,
@@ -7,10 +7,10 @@ exports.default = void 0;
7
7
 
8
8
  var _runtimeCore = require("@modern-js/runtime-core");
9
9
 
10
- var _resolvePlugins = _interopRequireDefault(require("./resolvePlugins"));
11
-
12
10
  var _constant = require("../constant");
13
11
 
12
+ var _resolvePlugins = _interopRequireDefault(require("./resolvePlugins"));
13
+
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
16
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ renderApp: true,
8
+ testBff: true
9
+ };
10
+ Object.defineProperty(exports, "renderApp", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _customRender.default;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "testBff", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _testingPluginBff.testBff;
20
+ }
21
+ });
22
+
23
+ var _customRender = _interopRequireDefault(require("./customRender"));
24
+
25
+ var _react = require("@testing-library/react");
26
+
27
+ Object.keys(_react).forEach(function (key) {
28
+ if (key === "default" || key === "__esModule") return;
29
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
30
+ if (key in exports && exports[key] === _react[key]) return;
31
+ Object.defineProperty(exports, key, {
32
+ enumerable: true,
33
+ get: function () {
34
+ return _react[key];
35
+ }
36
+ });
37
+ });
38
+
39
+ var _testingPluginBff = require("@modern-js/testing-plugin-bff");
40
+
41
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -3,35 +3,16 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- var _exportNames = {
7
- renderApp: true,
8
- testBff: true
9
- };
10
- Object.defineProperty(exports, "renderApp", {
11
- enumerable: true,
12
- get: function () {
13
- return _customRender.default;
14
- }
15
- });
16
- Object.defineProperty(exports, "testBff", {
17
- enumerable: true,
18
- get: function () {
19
- return _testingPluginBff.testBff;
20
- }
21
- });
22
-
23
- var _customRender = _interopRequireDefault(require("./customRender"));
24
6
 
25
- var _react = require("@testing-library/react");
7
+ var _base = require("./base");
26
8
 
27
- Object.keys(_react).forEach(function (key) {
9
+ Object.keys(_base).forEach(function (key) {
28
10
  if (key === "default" || key === "__esModule") return;
29
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
30
- if (key in exports && exports[key] === _react[key]) return;
11
+ if (key in exports && exports[key] === _base[key]) return;
31
12
  Object.defineProperty(exports, key, {
32
13
  enumerable: true,
33
14
  get: function () {
34
- return _react[key];
15
+ return _base[key];
35
16
  }
36
17
  });
37
18
  });
@@ -40,7 +21,6 @@ var _reduck = require("./reduck");
40
21
 
41
22
  Object.keys(_reduck).forEach(function (key) {
42
23
  if (key === "default" || key === "__esModule") return;
43
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
44
24
  if (key in exports && exports[key] === _reduck[key]) return;
45
25
  Object.defineProperty(exports, key, {
46
26
  enumerable: true,
@@ -48,8 +28,4 @@ Object.keys(_reduck).forEach(function (key) {
48
28
  return _reduck[key];
49
29
  }
50
30
  });
51
- });
52
-
53
- var _testingPluginBff = require("@modern-js/testing-plugin-bff");
54
-
55
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+ });
@@ -1,10 +1,15 @@
1
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
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
+
3
9
  import path from 'path';
4
10
  import { createPlugin } from '@modern-js/testing';
5
11
  import { modernjs_config_key } from "../../constant";
6
-
7
- var getModuleNameMapper = function getModuleNameMapper(config) {
12
+ export var getModuleNameMapper = function getModuleNameMapper(config) {
8
13
  var _config$resolve$alias = config.resolve.alias,
9
14
  alias = _config$resolve$alias === void 0 ? {} : _config$resolve$alias;
10
15
  return Object.keys(alias).reduce(function (memo, cur) {
@@ -28,7 +33,39 @@ var getModuleNameMapper = function getModuleNameMapper(config) {
28
33
  return memo;
29
34
  }, {});
30
35
  };
36
+ export var mergeUserJestConfig = /*#__PURE__*/function () {
37
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(testUtils) {
38
+ var resolveJestConfig;
39
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
40
+ while (1) {
41
+ switch (_context.prev = _context.next) {
42
+ case 0:
43
+ resolveJestConfig = testUtils.testConfig.jest;
44
+
45
+ if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
46
+ testUtils.mergeJestConfig(resolveJestConfig);
47
+ }
48
+
49
+ if (!(typeof resolveJestConfig === 'function')) {
50
+ _context.next = 5;
51
+ break;
52
+ }
53
+
54
+ _context.next = 5;
55
+ return resolveJestConfig(testUtils.jestConfig);
56
+
57
+ case 5:
58
+ case "end":
59
+ return _context.stop();
60
+ }
61
+ }
62
+ }, _callee);
63
+ }));
31
64
 
65
+ return function mergeUserJestConfig(_x) {
66
+ return _ref.apply(this, arguments);
67
+ };
68
+ }();
32
69
  export default (function (webpackConfig, userConfig, pwd) {
33
70
  return createPlugin(function () {
34
71
  return {
@@ -46,6 +83,7 @@ export default (function (webpackConfig, userConfig, pwd) {
46
83
  // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
47
84
  testMatch: ["<rootDir>/src/**/*.test.[jt]s?(x)", "<rootDir>/tests/**/*.test.[jt]s?(x)", "<rootDir>/electron/**/*.test.[jt]s?(x)"]
48
85
  });
86
+ mergeUserJestConfig(utils);
49
87
  return next(utils);
50
88
  }
51
89
  };
@@ -0,0 +1,65 @@
1
+ import { mergeUserJestConfig, getModuleNameMapper } 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
+ }); // TODO: 临时测试代码,待补充
53
+
54
+ test('getModuleNameMapper', function () {
55
+ var mockConfig = {
56
+ resolve: {
57
+ alias: {
58
+ '@modern-js/runtime/core': '/xxx'
59
+ }
60
+ }
61
+ };
62
+ var alias = getModuleNameMapper(mockConfig);
63
+ expect(alias).toBeDefined();
64
+ });
65
+ });
@@ -26,7 +26,7 @@ import modernTestPlugin from "./plugins/modern";
26
26
 
27
27
  var test = /*#__PURE__*/function () {
28
28
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
29
- var userConfig, config, webpackConfigs, runtimeExportsPath;
29
+ var userConfig, config, webpackConfigs, jest, runtimeExportsPath;
30
30
  return _regeneratorRuntime.wrap(function _callee$(_context) {
31
31
  while (1) {
32
32
  switch (_context.prev = _context.next) {
@@ -38,6 +38,12 @@ var test = /*#__PURE__*/function () {
38
38
 
39
39
  webpackConfigs = getWebpackConfig(WebpackConfigTarget.CLIENT);
40
40
  userConfig.testing = userConfig.testing || {};
41
+ jest = userConfig.testing.jest || userConfig.tools.jest;
42
+
43
+ if (Array.isArray(jest)) {
44
+ userConfig.testing.jest = jest[0];
45
+ }
46
+
41
47
  userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
42
48
  userConfig.testing.plugins = [].concat(_toConsumableArray(userConfig.testing.plugins || []), [modernTestPlugin(webpackConfigs, userConfig, config.appDirectory), testingBffPlugin({
43
49
  pwd: config.appDirectory,
@@ -48,7 +54,7 @@ var test = /*#__PURE__*/function () {
48
54
  routes: config.serverRoutes
49
55
  })]);
50
56
  runtimeExportsPath = path.join(config.internalDirectory, '.runtime-exports');
51
- _context.next = 9;
57
+ _context.next = 11;
52
58
  return compiler({
53
59
  sourceDir: runtimeExportsPath,
54
60
  rootDir: runtimeExportsPath,
@@ -60,11 +66,11 @@ var test = /*#__PURE__*/function () {
60
66
  }]]
61
67
  });
62
68
 
63
- case 9:
64
- _context.next = 11;
69
+ case 11:
70
+ _context.next = 13;
65
71
  return runTest(userConfig.testing);
66
72
 
67
- case 11:
73
+ case 13:
68
74
  case "end":
69
75
  return _context.stop();
70
76
  }
@@ -11,8 +11,8 @@ 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 resolvePlugins from "./resolvePlugins";
15
14
  import { modernjs_config_key } from "../constant";
15
+ import resolvePlugins from "./resolvePlugins";
16
16
 
17
17
  var ModernRuntime = /*#__PURE__*/function () {
18
18
  function ModernRuntime(options) {
@@ -0,0 +1,3 @@
1
+ export { default as renderApp } from "./customRender";
2
+ export * from '@testing-library/react';
3
+ export { testBff } from '@modern-js/testing-plugin-bff';
@@ -1,4 +1,2 @@
1
- export { default as renderApp } from "./customRender";
2
- export * from '@testing-library/react';
3
- export * from "./reduck";
4
- export { testBff } from '@modern-js/testing-plugin-bff';
1
+ export * from "./base";
2
+ export * from "./reduck";
@@ -1,3 +1,7 @@
1
- declare const _default: (webpackConfig: any, userConfig: any, pwd: string) => any;
1
+ import type { NormalizedConfig } from '@modern-js/core';
2
+ export declare const getModuleNameMapper: (config: any) => any;
3
+ export declare const mergeUserJestConfig: (testUtils: any) => Promise<void>;
4
+
5
+ declare const _default: (webpackConfig: any, userConfig: NormalizedConfig, pwd: string) => any;
2
6
 
3
7
  export default _default;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,3 @@
1
1
  export { default as renderApp } from './customRender';
2
2
  export * from '@testing-library/react';
3
- export * from './reduck';
4
- export { testBff } from '@modern-js/testing-plugin-bff';
3
+ export { testBff } from '@modern-js/testing-plugin-bff';
@@ -1,4 +1,2 @@
1
- export { default as renderApp } from './customRender';
2
- export * from '@testing-library/react';
3
- export * from './reduck';
4
- export { testBff } from '@modern-js/testing-plugin-bff';
1
+ export * from './base';
2
+ export * from './reduck';
package/jest.config.js ADDED
@@ -0,0 +1,8 @@
1
+ const sharedConfig = require('@scripts/jest-config');
2
+
3
+ /** @type {import('@jest/types').Config.InitialOptions} */
4
+ module.exports = {
5
+ // eslint-disable-next-line node/no-unsupported-features/es-syntax
6
+ ...sharedConfig,
7
+ rootDir: __dirname,
8
+ };
package/package.json CHANGED
@@ -11,16 +11,20 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.2.3-rc.0",
14
+ "version": "1.3.3-beta.0",
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
- "./type": "./type.d.ts",
21
+ "./type": {
22
+ "jsnext:source": "./type.d.ts",
23
+ "default": "./type.d.ts"
24
+ },
22
25
  ".": {
23
26
  "node": {
27
+ "jsnext:source": "./src/runtime-testing/index.ts",
24
28
  "import": "./dist/js/modern/runtime-testing/index.js",
25
29
  "require": "./dist/js/node/runtime-testing/index.js",
26
30
  "types": "./types/index.d.ts"
@@ -28,19 +32,32 @@
28
32
  "default": "./dist/js/treeshaking/runtime-testing/index.js"
29
33
  },
30
34
  "./runtime": {
35
+ "jsnext:source": "./src/runtime-testing/index.ts",
31
36
  "node": {
32
37
  "import": "./dist/js/modern/runtime-testing/index.js",
33
38
  "require": "./dist/js/node/runtime-testing/index.js",
34
39
  "types": "./types/index.d.ts"
35
40
  },
36
- "default": "./dist/js/treeshaking/runtime/index.js"
41
+ "default": "./dist/js/treeshaking/runtime-testing/index.js"
37
42
  },
38
- "./cli": "./dist/js/node/cli/index.js"
43
+ "./runtime-base": {
44
+ "jsnext:source": "./src/runtime-testing/base.ts",
45
+ "node": {
46
+ "import": "./dist/js/modern/runtime-testing/base.js",
47
+ "require": "./dist/js/node/runtime-testing/base.js",
48
+ "types": "./types/base.d.ts"
49
+ },
50
+ "default": "./dist/js/treeshaking/runtime-testing/base.js"
51
+ },
52
+ "./cli": {
53
+ "jsnext:source": "./src/cli/index.ts",
54
+ "default": "./dist/js/node/cli/index.js"
55
+ }
39
56
  },
40
57
  "typesVersions": {
41
58
  "*": {
42
59
  ".": [
43
- "./dist/types/runtime/index.d.ts"
60
+ "./dist/types/runtime-testing/index.d.ts"
44
61
  ],
45
62
  "cli": [
46
63
  "./dist/types/cli/index.d.ts"
@@ -56,48 +73,52 @@
56
73
  "dependencies": {
57
74
  "@babel/preset-env": "^7.15.6",
58
75
  "@babel/runtime": "^7",
59
- "@modern-js/babel-compiler": "^1.1.4-rc.0",
60
- "@modern-js/testing": "^1.2.1-rc.0",
61
- "@modern-js/utils": "^1.1.6-rc.0",
62
- "@modern-js/webpack": "^1.1.4-rc.0",
76
+ "@modern-js/babel-compiler": "^1.2.1",
77
+ "@modern-js/testing": "^1.3.1",
78
+ "@modern-js/utils": "^1.2.2",
79
+ "@modern-js/webpack": "^1.2.2",
63
80
  "@testing-library/jest-dom": "^5.14.1",
64
81
  "@testing-library/react": "^12.0.0",
65
- "enhanced-resolve": "^5.8.2",
66
- "@modern-js/testing-plugin-bff": "^1.1.3-rc.0"
82
+ "enhanced-resolve": "^5.8.3",
83
+ "@modern-js/testing-plugin-bff": "^1.2.1"
67
84
  },
68
85
  "peerDependencies": {
69
86
  "@modern-js-reduck/plugin-auto-actions": "^1.0.0",
70
87
  "@modern-js-reduck/plugin-effects": "^1.0.0",
71
88
  "@modern-js-reduck/plugin-immutable": "^1.0.0",
72
89
  "@modern-js-reduck/store": "^1.0.0",
73
- "@modern-js/core": "^1.2.1-rc.0",
74
- "@modern-js/runtime-core": "^1.1.3-rc.0"
90
+ "@modern-js/core": "^1.3.2",
91
+ "@modern-js/runtime-core": "^1.2.1"
75
92
  },
76
93
  "devDependencies": {
77
94
  "@modern-js-reduck/plugin-auto-actions": "^1.0.0",
78
95
  "@modern-js-reduck/plugin-effects": "^1.0.0",
79
96
  "@modern-js-reduck/plugin-immutable": "^1.0.0",
80
97
  "@modern-js-reduck/store": "^1.0.0",
81
- "@modern-js/plugin-testing": "^1.2.2",
82
- "@modern-js/module-tools": "^1.1.4",
83
- "@modern-js/core": "^1.2.1-rc.0",
84
- "@modern-js/runtime-core": "^1.1.3-rc.0",
98
+ "@scripts/build": "0.0.0",
99
+ "@modern-js/core": "^1.3.2",
100
+ "@modern-js/runtime-core": "^1.2.1",
85
101
  "@types/jest": "^26",
86
102
  "@types/node": "^14",
87
103
  "@types/react": "^17",
88
104
  "@types/react-dom": "^17",
89
- "typescript": "^4"
105
+ "react": "^17",
106
+ "react-dom": "^17",
107
+ "typescript": "^4",
108
+ "jest": "^27",
109
+ "@scripts/jest-config": "0.0.0"
90
110
  },
91
111
  "sideEffects": false,
92
112
  "modernConfig": {},
93
113
  "publishConfig": {
94
114
  "registry": "https://registry.npmjs.org/",
95
- "access": "public"
115
+ "access": "public",
116
+ "types": "./dist/types/index.d.ts"
96
117
  },
97
118
  "scripts": {
98
119
  "new": "modern new",
99
120
  "build": "modern build",
100
- "test": "modern test --passWithNoTests"
121
+ "test": "jest --passWithNoTests"
101
122
  },
102
123
  "readme": "\n<p align=\"center\">\n <a href=\"https://modernjs.dev\" target=\"blank\"><img src=\"https://lf3-static.bytednsdoc.com/obj/eden-cn/ylaelkeh7nuhfnuhf/modernjs-cover.png\" width=\"300\" alt=\"Modern.js Logo\" /></a>\n</p>\n<p align=\"center\">\n现代 Web 工程体系\n <br/>\n <a href=\"https://modernjs.dev\" target=\"blank\">\n modernjs.dev\n </a>\n</p>\n<p align=\"center\">\n The meta-framework suite designed from scratch for frontend-focused modern web development\n</p>\n\n# Introduction\n\n> The doc site ([modernjs.dev](https://modernjs.dev)) and articles are only available in Chinese for now, we are planning to add English versions soon.\n\n- [Modern.js: Hello, World!](https://zhuanlan.zhihu.com/p/426707646)\n\n## Getting Started\n\n- [Quick Start](https://modernjs.dev/docs/start)\n- [Guides](https://modernjs.dev/docs/guides)\n- [API References](https://modernjs.dev/docs/apis)\n\n## Contributing\n\n- [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md)\n"
103
124
  }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ extends: ['@modern-js'],
3
+ parserOptions: {
4
+ project: require.resolve('./tsconfig.json'),
5
+ },
6
+ };
@@ -0,0 +1,7 @@
1
+ import { createStore } from '../src';
2
+
3
+ describe('plugin-testing', () => {
4
+ it('default', () => {
5
+ expect(createStore).toBeDefined();
6
+ });
7
+ });
@@ -0,0 +1,30 @@
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
+ });
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "@modern-js/tsconfig/base",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "jsx": "preserve",
6
+ "baseUrl": "./",
7
+ "outDir": "./out",
8
+ "emitDeclarationOnly": true,
9
+ "isolatedModules": true,
10
+ "paths": {},
11
+ "types": ["node", "jest"]
12
+ }
13
+ }
package/tsconfig.json CHANGED
@@ -4,9 +4,7 @@
4
4
  "declaration": false,
5
5
  "jsx": "preserve",
6
6
  "baseUrl": "./",
7
- "paths": {
8
- "@/*": ["./src/*"]
9
- }
7
+ "paths": {}
10
8
  },
11
9
  "include": ["src"]
12
10
  }
package/type.d.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  import '@modern-js/core';
2
+ import "@testing-library/react"
3
+ import "@testing-library/jest-dom"
4
+ import "./dist/types/runtime-testing"
5
+
2
6
  declare module '@modern-js/runtime/testing' {
3
7
  export * from '@testing-library/react';
4
- export { renderApp, createStore } from '@modern-js/plugin-testing';
8
+ export { renderApp, createStore } from './dist/types/runtime-testing';
5
9
  }
6
10
 
7
11
  declare module '@modern-js/core' {
@@ -1,3 +0,0 @@
1
- {
2
- "extends": ["@modern-js"]
3
- }
package/src/cli/index.ts DELETED
@@ -1,48 +0,0 @@
1
- import path from 'path';
2
- import { createRuntimeExportsUtils, PLUGIN_SCHEMAS } from '@modern-js/utils';
3
- import { createPlugin, useAppContext } from '@modern-js/core';
4
- import test from './test';
5
-
6
- export default createPlugin(
7
- () => {
8
- let testingExportsUtils: ReturnType<typeof createRuntimeExportsUtils>;
9
-
10
- return {
11
- commands: ({ program }: any) => {
12
- program
13
- .command('test')
14
- .allowUnknownOption()
15
- .usage('[options]')
16
- .action(async () => {
17
- await test();
18
- });
19
- },
20
- validateSchema() {
21
- return PLUGIN_SCHEMAS['@modern-js/plugin-testing'];
22
- },
23
- config() {
24
- // eslint-disable-next-line react-hooks/rules-of-hooks
25
- const appContext = useAppContext();
26
-
27
- testingExportsUtils = createRuntimeExportsUtils(
28
- appContext.internalDirectory,
29
- 'testing',
30
- );
31
-
32
- return {
33
- source: {
34
- alias: {
35
- '@modern-js/runtime/testing': testingExportsUtils.getPath(),
36
- },
37
- },
38
- };
39
- },
40
- addRuntimeExports() {
41
- const testingPath = path.resolve(__dirname, '../');
42
-
43
- testingExportsUtils.addExport(`export * from '${testingPath}'`);
44
- },
45
- };
46
- },
47
- { name: '@modern-js/plugin-testing' },
48
- ) as any;
@@ -1,64 +0,0 @@
1
- import path from 'path';
2
- import { createPlugin } from '@modern-js/testing';
3
- import { modernjs_config_key } from '@/constant';
4
-
5
- const getModuleNameMapper = (config: any) => {
6
- const {
7
- resolve: { alias = {} },
8
- } = config;
9
-
10
- return Object.keys(alias).reduce((memo, cur) => {
11
- const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
12
-
13
- const isFile = aliasValue.some((s: string) => s.endsWith('.js'));
14
-
15
- // It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
16
- if (cur === '@modern-js/runtime$') {
17
- memo[`.+${cur}`] = aliasValue[0];
18
-
19
- return memo;
20
- }
21
-
22
- if (isFile) {
23
- memo[cur] = aliasValue[0];
24
- }
25
-
26
- const key = `^${cur}/(.*)$`;
27
- const value = path.normalize(`${aliasValue}/$1`);
28
- memo[key] = value;
29
- return memo;
30
- }, {} as any);
31
- };
32
-
33
- export default (webpackConfig: any, userConfig: any, pwd: string) =>
34
- createPlugin(
35
- () => ({
36
- jestConfig: (utils: any, next: any) => {
37
- utils.mergeJestConfig({
38
- globals: {
39
- [modernjs_config_key]: userConfig,
40
- },
41
- moduleNameMapper: getModuleNameMapper(webpackConfig),
42
- testEnvironment: 'jsdom',
43
- resolver: require.resolve('../resolver'),
44
- });
45
-
46
- utils.setJestConfig({
47
- rootDir: pwd || process.cwd(),
48
- // todo: diffrent test root for diffrent solutions
49
- // testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
50
- // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
51
- testMatch: [
52
- `<rootDir>/src/**/*.test.[jt]s?(x)`,
53
- `<rootDir>/tests/**/*.test.[jt]s?(x)`,
54
- `<rootDir>/electron/**/*.test.[jt]s?(x)`,
55
- ],
56
- });
57
-
58
- return next(utils);
59
- },
60
- }),
61
- {
62
- name: '@modern-js/testing-plugin-modern',
63
- },
64
- ) as any;
@@ -1,16 +0,0 @@
1
- import enhanceResolve from 'enhanced-resolve';
2
-
3
- const resolver = enhanceResolve.create.sync({
4
- conditionNames: ['require', 'node', 'default'],
5
- extensions: ['.js', '.json', '.node', '.ts', '.tsx'],
6
- });
7
-
8
- const shouldResolveByEnhance = (url: string) => /^@[^/]+\/[^/]+\/.*/.test(url);
9
-
10
- module.exports = function (request: string, options: any) {
11
- if (shouldResolveByEnhance(request)) {
12
- return resolver(options.basedir, request);
13
- }
14
-
15
- return options.defaultResolver(request, options);
16
- };
package/src/cli/test.ts DELETED
@@ -1,70 +0,0 @@
1
- import path from 'path';
2
- import { compiler } from '@modern-js/babel-compiler';
3
- import { useAppContext, useResolvedConfigContext } from '@modern-js/core';
4
- import { runTest } from '@modern-js/testing';
5
- import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
6
- import testingBffPlugin from '@modern-js/testing-plugin-bff';
7
- import modernTestPlugin from './plugins/modern';
8
-
9
- const test = async () => {
10
- // eslint-disable-next-line react-hooks/rules-of-hooks
11
- const userConfig = useResolvedConfigContext();
12
- // eslint-disable-next-line react-hooks/rules-of-hooks
13
- const config = useAppContext();
14
-
15
- // todo: consider lib-tools ...
16
- const webpackConfigs = getWebpackConfig(WebpackConfigTarget.CLIENT);
17
-
18
- userConfig.testing = userConfig.testing || {};
19
- userConfig.testing.jest =
20
- userConfig.testing.jest || (userConfig.tools as any).jest;
21
-
22
- userConfig.testing.plugins = [
23
- ...(userConfig.testing.plugins || []),
24
- modernTestPlugin(webpackConfigs, userConfig, config.appDirectory),
25
- testingBffPlugin({
26
- pwd: config.appDirectory,
27
- userConfig,
28
- plugins: config.plugins.map(p => p.server).filter(Boolean),
29
- routes: (config as any).serverRoutes,
30
- }),
31
- ];
32
-
33
- const runtimeExportsPath = path.join(
34
- config.internalDirectory,
35
- '.runtime-exports',
36
- );
37
-
38
- await compiler(
39
- {
40
- sourceDir: runtimeExportsPath,
41
- rootDir: runtimeExportsPath,
42
- distDir: runtimeExportsPath,
43
- quiet: true,
44
- },
45
- {
46
- presets: [
47
- [
48
- require.resolve('@babel/preset-env'),
49
- {
50
- modules: 'cjs',
51
- },
52
- ],
53
- ],
54
- },
55
- );
56
-
57
- await runTest(userConfig.testing);
58
- };
59
-
60
- export default test;
61
-
62
- declare module '@modern-js/core' {
63
- interface UserConfig {
64
- testing?: import('@modern-js/testing').TestConfig;
65
- }
66
-
67
- interface ToolsConfig {
68
- jest?: import('@modern-js/testing').TestConfig['jest'];
69
- }
70
- }
package/src/constant.ts DELETED
@@ -1 +0,0 @@
1
- export const modernjs_config_key = '__modernjs_config__';
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- import '@testing-library/jest-dom/extend-expect';
2
- import '@testing-library/jest-dom';
3
-
4
- export * from './runtime-testing';
@@ -1,48 +0,0 @@
1
- import React from 'react';
2
- import { createApp } from '@modern-js/runtime-core';
3
- import { UserConfig } from '@modern-js/core';
4
- import resolvePlugins from './resolvePlugins';
5
- import { modernjs_config_key } from '@/constant';
6
-
7
- interface CreateAppProps {
8
- entry?: string;
9
- children?: React.ReactElement;
10
- }
11
-
12
- class ModernRuntime {
13
- private options: UserConfig;
14
-
15
- constructor(options: UserConfig) {
16
- this.options = options;
17
- }
18
-
19
- public init(options: UserConfig) {
20
- this.options = options;
21
- }
22
-
23
- public createApp(props?: CreateAppProps) {
24
- const { entry, children } = props || {};
25
- let runtimeFeatures = this.options?.runtime;
26
-
27
- if (entry) {
28
- runtimeFeatures = {
29
- ...(runtimeFeatures || {}),
30
- ...this.options.runtimeByEntries?.[entry],
31
- };
32
- }
33
-
34
- const Component = (): React.ReactElement | null => {
35
- if (!children) {
36
- return null;
37
- }
38
-
39
- return children;
40
- };
41
-
42
- return createApp({
43
- plugins: resolvePlugins(runtimeFeatures || {}),
44
- })(Component);
45
- }
46
- }
47
-
48
- export default new ModernRuntime((global as any)[modernjs_config_key] || {});
@@ -1,11 +0,0 @@
1
- import React from 'react';
2
- import { render } from '@testing-library/react';
3
- import app from './app';
4
-
5
- const WrapModernProviders = (props: any) =>
6
- React.createElement(app.createApp(props));
7
-
8
- const customRender = (ui: React.ReactElement, options: any) =>
9
- render(ui, { wrapper: WrapModernProviders, ...options });
10
-
11
- export default customRender as typeof render;
@@ -1,38 +0,0 @@
1
- import { createStore as originCreateStore } from '@modern-js-reduck/store';
2
- import effectsPlugin from '@modern-js-reduck/plugin-effects';
3
- import autoActionsPlugin from '@modern-js-reduck/plugin-auto-actions';
4
- import immerPlugin from '@modern-js-reduck/plugin-immutable';
5
- import { modernjs_config_key } from '@/constant';
6
-
7
- export const effects = () => effectsPlugin;
8
- export const immer = () => immerPlugin;
9
- export const autoActions = () => autoActionsPlugin;
10
-
11
- export const createStore: typeof originCreateStore = props => {
12
- const createStatePlugins = () => {
13
- const modernConfig = (global as any)[modernjs_config_key];
14
- const stateConfig = modernConfig?.runtime?.state;
15
- const plugins = [];
16
-
17
- if (stateConfig?.effects !== false) {
18
- plugins.push(effects());
19
- }
20
-
21
- if (stateConfig?.autoActions !== false) {
22
- plugins.push(autoActions());
23
- }
24
-
25
- if (stateConfig?.immer !== false) {
26
- plugins.push(immer());
27
- }
28
-
29
- return (props?.plugins || []).concat(plugins);
30
- };
31
-
32
- const config = {
33
- ...(props || {}),
34
- plugins: createStatePlugins(),
35
- };
36
-
37
- return originCreateStore(config);
38
- };
@@ -1,23 +0,0 @@
1
- import { NormalizedConfig } from '@modern-js/core';
2
-
3
- const allowedFeatures = ['router', 'state'];
4
-
5
- export default function resolvePlugins(features: NormalizedConfig['runtime']) {
6
- const plugins: any[] = [];
7
-
8
- if (!features) {
9
- return plugins;
10
- }
11
-
12
- Object.keys(features).forEach(feature => {
13
- if (allowedFeatures.includes(feature)) {
14
- const curPluginRes = require(`@modern-js/runtime/plugins`)[feature]({
15
- ...features[feature],
16
- });
17
-
18
- plugins.push(curPluginRes);
19
- }
20
- });
21
-
22
- return plugins;
23
- }