@modern-js/plugin-testing 1.2.2 → 1.3.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.
- package/CHANGELOG.md +84 -0
- package/dist/js/modern/cli/plugins/modern.js +12 -2
- package/dist/js/modern/cli/plugins/modern.test.js +69 -0
- package/dist/js/modern/cli/test.js +6 -0
- package/dist/js/modern/runtime-testing/app.js +1 -1
- package/dist/js/node/cli/plugins/modern.js +18 -1
- package/dist/js/node/cli/plugins/modern.test.js +72 -0
- package/dist/js/node/cli/test.js +6 -0
- package/dist/js/node/runtime-testing/app.js +2 -2
- package/dist/js/treeshaking/cli/plugins/modern.js +40 -2
- package/dist/js/treeshaking/cli/plugins/modern.test.js +65 -0
- package/dist/js/treeshaking/cli/test.js +11 -5
- package/dist/js/treeshaking/runtime-testing/app.js +1 -1
- package/dist/types/cli/plugins/modern.d.ts +5 -1
- package/dist/types/cli/plugins/modern.test.d.ts +1 -0
- package/jest.config.js +8 -0
- package/package.json +32 -20
- package/tests/.eslintrc.js +6 -0
- package/tests/index.test.ts +7 -0
- package/tests/resolver.test.ts +30 -0
- package/tests/tsconfig.json +13 -0
- package/tsconfig.json +1 -3
- package/type.d.ts +5 -1
- package/src/.eslintrc.json +0 -3
- package/src/cli/index.ts +0 -48
- package/src/cli/plugins/modern.ts +0 -64
- package/src/cli/resolver.ts +0 -16
- package/src/cli/test.ts +0 -70
- package/src/constant.ts +0 -1
- package/src/index.ts +0 -4
- package/src/runtime-testing/app.ts +0 -48
- package/src/runtime-testing/customRender.ts +0 -11
- package/src/runtime-testing/index.ts +0 -4
- package/src/runtime-testing/reduck.ts +0 -38
- package/src/runtime-testing/resolvePlugins.ts +0 -23
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,89 @@
|
|
1
1
|
# @modern-js/plugin-testing
|
2
2
|
|
3
|
+
## 1.3.2
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
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
|
55
|
+
|
56
|
+
## 1.2.1
|
57
|
+
|
58
|
+
### Patch Changes
|
59
|
+
|
60
|
+
- fix: type define
|
61
|
+
|
62
|
+
## 1.2.0
|
63
|
+
|
64
|
+
### Minor Changes
|
65
|
+
|
66
|
+
- 90eeb72c: add modern config schema and types of testing, tools.jest.
|
67
|
+
add typesVersions for re-exporting types of @modern-js/plugin-testing.
|
68
|
+
fix type lost when redeclareing modules.
|
69
|
+
- 5a4c557e: feat: support bff test
|
70
|
+
|
71
|
+
### Patch Changes
|
72
|
+
|
73
|
+
- Updated dependencies [90eeb72c]
|
74
|
+
- Updated dependencies [e04914ce]
|
75
|
+
- Updated dependencies [4406c2db]
|
76
|
+
- Updated dependencies [90eeb72c]
|
77
|
+
- Updated dependencies [5a4c557e]
|
78
|
+
- Updated dependencies [e04914ce]
|
79
|
+
- Updated dependencies [ca7dcb32]
|
80
|
+
- Updated dependencies [ecb344dc]
|
81
|
+
- @modern-js/core@1.2.0
|
82
|
+
- @modern-js/runtime-core@1.1.2
|
83
|
+
- @modern-js/testing@1.2.0
|
84
|
+
- @modern-js/babel-compiler@1.1.3
|
85
|
+
- @modern-js/utils@1.1.5
|
86
|
+
|
3
87
|
## 1.1.1
|
4
88
|
|
5
89
|
### Patch Changes
|
@@ -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) {
|
@@ -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
|
+
});
|
package/dist/js/node/cli/test.js
CHANGED
@@ -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; }
|
@@ -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 =
|
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
|
64
|
-
_context.next =
|
69
|
+
case 11:
|
70
|
+
_context.next = 13;
|
65
71
|
return runTest(userConfig.testing);
|
66
72
|
|
67
|
-
case
|
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) {
|
@@ -1,3 +1,7 @@
|
|
1
|
-
|
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 {};
|
package/jest.config.js
ADDED
package/package.json
CHANGED
@@ -11,16 +11,20 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.
|
14
|
+
"version": "1.3.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
|
-
"./type":
|
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,23 @@
|
|
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":
|
43
|
+
"./cli": {
|
44
|
+
"jsnext:source": "./src/cli/index.ts",
|
45
|
+
"default": "./dist/js/node/cli/index.js"
|
46
|
+
}
|
39
47
|
},
|
40
48
|
"typesVersions": {
|
41
49
|
"*": {
|
42
50
|
".": [
|
43
|
-
"./dist/types/runtime/index.d.ts"
|
51
|
+
"./dist/types/runtime-testing/index.d.ts"
|
44
52
|
],
|
45
53
|
"cli": [
|
46
54
|
"./dist/types/cli/index.d.ts"
|
@@ -56,48 +64,52 @@
|
|
56
64
|
"dependencies": {
|
57
65
|
"@babel/preset-env": "^7.15.6",
|
58
66
|
"@babel/runtime": "^7",
|
59
|
-
"@modern-js/babel-compiler": "^1.
|
60
|
-
"@modern-js/testing": "^1.
|
61
|
-
"@modern-js/utils": "^1.
|
62
|
-
"@modern-js/webpack": "^1.
|
67
|
+
"@modern-js/babel-compiler": "^1.2.1",
|
68
|
+
"@modern-js/testing": "^1.3.1",
|
69
|
+
"@modern-js/utils": "^1.2.2",
|
70
|
+
"@modern-js/webpack": "^1.2.2",
|
63
71
|
"@testing-library/jest-dom": "^5.14.1",
|
64
72
|
"@testing-library/react": "^12.0.0",
|
65
|
-
"enhanced-resolve": "^5.8.
|
66
|
-
"@modern-js/testing-plugin-bff": "^1.
|
73
|
+
"enhanced-resolve": "^5.8.3",
|
74
|
+
"@modern-js/testing-plugin-bff": "^1.2.1"
|
67
75
|
},
|
68
76
|
"peerDependencies": {
|
69
77
|
"@modern-js-reduck/plugin-auto-actions": "^1.0.0",
|
70
78
|
"@modern-js-reduck/plugin-effects": "^1.0.0",
|
71
79
|
"@modern-js-reduck/plugin-immutable": "^1.0.0",
|
72
80
|
"@modern-js-reduck/store": "^1.0.0",
|
73
|
-
"@modern-js/core": "^1.
|
74
|
-
"@modern-js/runtime-core": "^1.
|
81
|
+
"@modern-js/core": "^1.3.2",
|
82
|
+
"@modern-js/runtime-core": "^1.2.1"
|
75
83
|
},
|
76
84
|
"devDependencies": {
|
77
85
|
"@modern-js-reduck/plugin-auto-actions": "^1.0.0",
|
78
86
|
"@modern-js-reduck/plugin-effects": "^1.0.0",
|
79
87
|
"@modern-js-reduck/plugin-immutable": "^1.0.0",
|
80
88
|
"@modern-js-reduck/store": "^1.0.0",
|
81
|
-
"@
|
82
|
-
"@modern-js/
|
83
|
-
"@modern-js/core": "^1.
|
84
|
-
"@modern-js/runtime-core": "^1.0.0",
|
89
|
+
"@scripts/build": "0.0.0",
|
90
|
+
"@modern-js/core": "^1.3.2",
|
91
|
+
"@modern-js/runtime-core": "^1.2.1",
|
85
92
|
"@types/jest": "^26",
|
86
93
|
"@types/node": "^14",
|
87
94
|
"@types/react": "^17",
|
88
95
|
"@types/react-dom": "^17",
|
89
|
-
"
|
96
|
+
"react": "^17",
|
97
|
+
"react-dom": "^17",
|
98
|
+
"typescript": "^4",
|
99
|
+
"jest": "^27",
|
100
|
+
"@scripts/jest-config": "0.0.0"
|
90
101
|
},
|
91
102
|
"sideEffects": false,
|
92
103
|
"modernConfig": {},
|
93
104
|
"publishConfig": {
|
94
105
|
"registry": "https://registry.npmjs.org/",
|
95
|
-
"access": "public"
|
106
|
+
"access": "public",
|
107
|
+
"types": "./dist/types/index.d.ts"
|
96
108
|
},
|
97
109
|
"scripts": {
|
98
110
|
"new": "modern new",
|
99
111
|
"build": "modern build",
|
100
|
-
"test": "
|
112
|
+
"test": "jest --passWithNoTests"
|
101
113
|
},
|
102
114
|
"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
115
|
}
|
@@ -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
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 '
|
8
|
+
export { renderApp, createStore } from './dist/types/runtime-testing';
|
5
9
|
}
|
6
10
|
|
7
11
|
declare module '@modern-js/core' {
|
package/src/.eslintrc.json
DELETED
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;
|
package/src/cli/resolver.ts
DELETED
@@ -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,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
|
-
}
|