@modern-js/plugin-testing 1.2.3-rc.0 → 1.3.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.
- package/CHANGELOG.md +23 -14
- 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/resolver.js +1 -1
- 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/resolver.js +1 -1
- 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/resolver.js +1 -1
- 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/src/cli/plugins/modern.test.ts +68 -0
- package/src/cli/plugins/modern.ts +22 -3
- package/src/cli/resolver.ts +1 -1
- package/src/cli/test.ts +7 -0
- package/src/runtime-testing/app.ts +1 -1
- package/src/runtime-testing/reduck.ts +1 -1
- package/tests/index.test.ts +7 -0
- package/tsconfig.json +1 -3
package/CHANGELOG.md
CHANGED
@@ -1,22 +1,31 @@
|
|
1
1
|
# @modern-js/plugin-testing
|
2
2
|
|
3
|
-
## 1.
|
3
|
+
## 1.3.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- cfe11628: Make Modern.js self bootstraping
|
4
8
|
|
5
9
|
### Patch Changes
|
6
10
|
|
7
|
-
-
|
8
|
-
- Updated dependencies [
|
9
|
-
- Updated dependencies [
|
10
|
-
- Updated dependencies [
|
11
|
-
- Updated dependencies [
|
12
|
-
- Updated dependencies [
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
- @modern-js/
|
19
|
-
- @modern-js/
|
11
|
+
- c3d46ee4: fix: test config invalid
|
12
|
+
- Updated dependencies [2da09c69]
|
13
|
+
- Updated dependencies [5597289b]
|
14
|
+
- Updated dependencies [fc71e36f]
|
15
|
+
- Updated dependencies [4a85378c]
|
16
|
+
- Updated dependencies [a2cb9abc]
|
17
|
+
- Updated dependencies [e453e421]
|
18
|
+
- Updated dependencies [c3d46ee4]
|
19
|
+
- Updated dependencies [cfe11628]
|
20
|
+
- Updated dependencies [146dcd85]
|
21
|
+
- Updated dependencies [1ebc7ee2]
|
22
|
+
- @modern-js/utils@1.2.0
|
23
|
+
- @modern-js/webpack@1.2.0
|
24
|
+
- @modern-js/core@1.3.0
|
25
|
+
- @modern-js/runtime-core@1.2.0
|
26
|
+
- @modern-js/testing@1.3.0
|
27
|
+
- @modern-js/testing-plugin-bff@1.2.0
|
28
|
+
- @modern-js/babel-compiler@1.2.0
|
20
29
|
|
21
30
|
## 1.2.1
|
22
31
|
|
@@ -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
|
+
});
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import enhanceResolve from 'enhanced-resolve';
|
2
2
|
const resolver = enhanceResolve.create.sync({
|
3
|
-
conditionNames: ['require', 'node', 'default'],
|
3
|
+
conditionNames: ['jsnext:source', 'require', 'node', 'default'],
|
4
4
|
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
5
5
|
});
|
6
6
|
|
@@ -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
|
+
});
|
@@ -5,7 +5,7 @@ var _enhancedResolve = _interopRequireDefault(require("enhanced-resolve"));
|
|
5
5
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
6
6
|
|
7
7
|
const resolver = _enhancedResolve.default.create.sync({
|
8
|
-
conditionNames: ['require', 'node', 'default'],
|
8
|
+
conditionNames: ['jsnext:source', 'require', 'node', 'default'],
|
9
9
|
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
10
10
|
});
|
11
11
|
|
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
|
+
});
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import enhanceResolve from 'enhanced-resolve';
|
2
2
|
var resolver = enhanceResolve.create.sync({
|
3
|
-
conditionNames: ['require', 'node', 'default'],
|
3
|
+
conditionNames: ['jsnext:source', 'require', 'node', 'default'],
|
4
4
|
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
5
5
|
});
|
6
6
|
|
@@ -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.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":
|
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.0",
|
68
|
+
"@modern-js/testing": "^1.3.0",
|
69
|
+
"@modern-js/utils": "^1.2.0",
|
70
|
+
"@modern-js/webpack": "^1.2.0",
|
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.0"
|
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.0",
|
82
|
+
"@modern-js/runtime-core": "^1.2.0"
|
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.2.
|
84
|
-
"@modern-js/runtime-core": "^1.1.3-rc.0",
|
89
|
+
"@scripts/build": "0.0.0",
|
90
|
+
"@modern-js/core": "^1.3.0",
|
91
|
+
"@modern-js/runtime-core": "^1.2.0",
|
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,68 @@
|
|
1
|
+
import { mergeUserJestConfig, getModuleNameMapper } from './modern';
|
2
|
+
|
3
|
+
describe('modern plugin', () => {
|
4
|
+
test('mergeUserJestConfig support object', () => {
|
5
|
+
const testUtils = {
|
6
|
+
_jestConfig: {
|
7
|
+
a: 1,
|
8
|
+
},
|
9
|
+
get jestConfig() {
|
10
|
+
return this._jestConfig;
|
11
|
+
},
|
12
|
+
testConfig: {
|
13
|
+
jest: {
|
14
|
+
b: 1,
|
15
|
+
},
|
16
|
+
},
|
17
|
+
mergeJestConfig(config: Record<string, string>) {
|
18
|
+
Object.assign(this._jestConfig, config);
|
19
|
+
},
|
20
|
+
};
|
21
|
+
|
22
|
+
mergeUserJestConfig(testUtils);
|
23
|
+
|
24
|
+
expect(testUtils.jestConfig).toEqual({
|
25
|
+
a: 1,
|
26
|
+
b: 1,
|
27
|
+
});
|
28
|
+
});
|
29
|
+
|
30
|
+
test('mergeUserJestConfig support function', () => {
|
31
|
+
const testUtils = {
|
32
|
+
_jestConfig: {
|
33
|
+
a: 1,
|
34
|
+
},
|
35
|
+
get jestConfig() {
|
36
|
+
return this._jestConfig;
|
37
|
+
},
|
38
|
+
testConfig: {
|
39
|
+
jest: (jestConfig: Record<string, number>) => {
|
40
|
+
jestConfig.b = 1;
|
41
|
+
},
|
42
|
+
},
|
43
|
+
mergeJestConfig(config: Record<string, string>) {
|
44
|
+
Object.assign(this._jestConfig, config);
|
45
|
+
},
|
46
|
+
};
|
47
|
+
|
48
|
+
mergeUserJestConfig(testUtils);
|
49
|
+
expect(testUtils.jestConfig).toEqual({
|
50
|
+
a: 1,
|
51
|
+
b: 1,
|
52
|
+
});
|
53
|
+
});
|
54
|
+
|
55
|
+
// TODO: 临时测试代码,待补充
|
56
|
+
test('getModuleNameMapper', () => {
|
57
|
+
const mockConfig = {
|
58
|
+
resolve: {
|
59
|
+
alias: {
|
60
|
+
'@modern-js/runtime/core': '/xxx',
|
61
|
+
},
|
62
|
+
},
|
63
|
+
};
|
64
|
+
|
65
|
+
const alias = getModuleNameMapper(mockConfig);
|
66
|
+
expect(alias).toBeDefined();
|
67
|
+
});
|
68
|
+
});
|
@@ -1,8 +1,9 @@
|
|
1
1
|
import path from 'path';
|
2
2
|
import { createPlugin } from '@modern-js/testing';
|
3
|
-
import {
|
3
|
+
import type { NormalizedConfig } from '@modern-js/core';
|
4
|
+
import { modernjs_config_key } from '../../constant';
|
4
5
|
|
5
|
-
const getModuleNameMapper = (config: any) => {
|
6
|
+
export const getModuleNameMapper = (config: any) => {
|
6
7
|
const {
|
7
8
|
resolve: { alias = {} },
|
8
9
|
} = config;
|
@@ -30,7 +31,23 @@ const getModuleNameMapper = (config: any) => {
|
|
30
31
|
}, {} as any);
|
31
32
|
};
|
32
33
|
|
33
|
-
export
|
34
|
+
export const mergeUserJestConfig = async (testUtils: any) => {
|
35
|
+
const resolveJestConfig = testUtils.testConfig.jest;
|
36
|
+
|
37
|
+
if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
|
38
|
+
testUtils.mergeJestConfig(resolveJestConfig);
|
39
|
+
}
|
40
|
+
|
41
|
+
if (typeof resolveJestConfig === 'function') {
|
42
|
+
await resolveJestConfig(testUtils.jestConfig);
|
43
|
+
}
|
44
|
+
};
|
45
|
+
|
46
|
+
export default (
|
47
|
+
webpackConfig: any,
|
48
|
+
userConfig: NormalizedConfig,
|
49
|
+
pwd: string,
|
50
|
+
) =>
|
34
51
|
createPlugin(
|
35
52
|
() => ({
|
36
53
|
jestConfig: (utils: any, next: any) => {
|
@@ -55,6 +72,8 @@ export default (webpackConfig: any, userConfig: any, pwd: string) =>
|
|
55
72
|
],
|
56
73
|
});
|
57
74
|
|
75
|
+
mergeUserJestConfig(utils);
|
76
|
+
|
58
77
|
return next(utils);
|
59
78
|
},
|
60
79
|
}),
|
package/src/cli/resolver.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import enhanceResolve from 'enhanced-resolve';
|
2
2
|
|
3
3
|
const resolver = enhanceResolve.create.sync({
|
4
|
-
conditionNames: ['require', 'node', 'default'],
|
4
|
+
conditionNames: ['jsnext:source', 'require', 'node', 'default'],
|
5
5
|
extensions: ['.js', '.json', '.node', '.ts', '.tsx'],
|
6
6
|
});
|
7
7
|
|
package/src/cli/test.ts
CHANGED
@@ -16,6 +16,13 @@ const test = async () => {
|
|
16
16
|
const webpackConfigs = getWebpackConfig(WebpackConfigTarget.CLIENT);
|
17
17
|
|
18
18
|
userConfig.testing = userConfig.testing || {};
|
19
|
+
|
20
|
+
const jest = userConfig.testing.jest || (userConfig.tools as any).jest;
|
21
|
+
|
22
|
+
if (Array.isArray(jest)) {
|
23
|
+
userConfig.testing.jest = jest[0];
|
24
|
+
}
|
25
|
+
|
19
26
|
userConfig.testing.jest =
|
20
27
|
userConfig.testing.jest || (userConfig.tools as any).jest;
|
21
28
|
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { createApp } from '@modern-js/runtime-core';
|
3
3
|
import { UserConfig } from '@modern-js/core';
|
4
|
+
import { modernjs_config_key } from '../constant';
|
4
5
|
import resolvePlugins from './resolvePlugins';
|
5
|
-
import { modernjs_config_key } from '@/constant';
|
6
6
|
|
7
7
|
interface CreateAppProps {
|
8
8
|
entry?: string;
|
@@ -2,7 +2,7 @@ import { createStore as originCreateStore } from '@modern-js-reduck/store';
|
|
2
2
|
import effectsPlugin from '@modern-js-reduck/plugin-effects';
|
3
3
|
import autoActionsPlugin from '@modern-js-reduck/plugin-auto-actions';
|
4
4
|
import immerPlugin from '@modern-js-reduck/plugin-immutable';
|
5
|
-
import { modernjs_config_key } from '
|
5
|
+
import { modernjs_config_key } from '../constant';
|
6
6
|
|
7
7
|
export const effects = () => effectsPlugin;
|
8
8
|
export const immer = () => immerPlugin;
|