@modern-js/plugin-testing 1.3.2 → 1.3.4
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 +30 -0
- package/dist/js/modern/cli/plugins/modern.js +29 -48
- package/dist/js/modern/cli/plugins/modern.test.js +1 -13
- package/dist/js/modern/cli/test.js +25 -9
- package/dist/js/modern/runtime-testing/base.js +3 -0
- package/dist/js/modern/runtime-testing/index.js +2 -4
- package/dist/js/node/cli/plugins/modern.js +29 -56
- package/dist/js/node/cli/plugins/modern.test.js +0 -12
- package/dist/js/node/cli/test.js +25 -9
- package/dist/js/node/runtime-testing/base.js +41 -0
- package/dist/js/node/runtime-testing/index.js +5 -29
- package/dist/js/treeshaking/cli/plugins/modern.js +4 -27
- package/dist/js/treeshaking/cli/plugins/modern.test.js +1 -13
- package/dist/js/treeshaking/cli/test.js +35 -15
- package/dist/js/treeshaking/runtime-testing/base.js +3 -0
- package/dist/js/treeshaking/runtime-testing/index.js +2 -4
- package/dist/types/cli/plugins/modern.d.ts +0 -1
- package/dist/types/runtime-testing/base.d.ts +3 -0
- package/dist/types/runtime-testing/index.d.ts +2 -4
- package/package.json +20 -9
- package/type.d.ts +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,35 @@
|
|
1
1
|
# @modern-js/plugin-testing
|
2
2
|
|
3
|
+
## 1.3.4
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 9594df3f: fix: allow other bff plugin in unbundle mode
|
8
|
+
- Updated dependencies [deeaa602]
|
9
|
+
- Updated dependencies [54786e58]
|
10
|
+
- Updated dependencies [3da3bf48]
|
11
|
+
- @modern-js/utils@1.3.2
|
12
|
+
- @modern-js/webpack@1.4.0
|
13
|
+
- @modern-js/core@1.4.3
|
14
|
+
|
15
|
+
## 1.3.3
|
16
|
+
|
17
|
+
### Patch Changes
|
18
|
+
|
19
|
+
- 698ad9e8: feat: support test bff for api service
|
20
|
+
- 11fda442: fix: add testing runtime base
|
21
|
+
- Updated dependencies [75f4eeb8]
|
22
|
+
- Updated dependencies [698ad9e8]
|
23
|
+
- Updated dependencies [53aca274]
|
24
|
+
- Updated dependencies [78279953]
|
25
|
+
- Updated dependencies [e116ace5]
|
26
|
+
- Updated dependencies [4d72edea]
|
27
|
+
- @modern-js/webpack@1.3.1
|
28
|
+
- @modern-js/testing@1.3.2
|
29
|
+
- @modern-js/testing-plugin-bff@1.2.2
|
30
|
+
- @modern-js/core@1.4.1
|
31
|
+
- @modern-js/utils@1.3.1
|
32
|
+
|
3
33
|
## 1.3.2
|
4
34
|
|
5
35
|
### Patch Changes
|
@@ -1,31 +1,5 @@
|
|
1
|
-
import
|
2
|
-
import { createPlugin } from '@modern-js/testing';
|
1
|
+
import { createPlugin, getModuleNameMapper } from '@modern-js/testing';
|
3
2
|
import { modernjs_config_key } from "../../constant";
|
4
|
-
export const getModuleNameMapper = config => {
|
5
|
-
const {
|
6
|
-
resolve: {
|
7
|
-
alias = {}
|
8
|
-
}
|
9
|
-
} = config;
|
10
|
-
return Object.keys(alias).reduce((memo, cur) => {
|
11
|
-
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
|
12
|
-
const isFile = aliasValue.some(s => s.endsWith('.js')); // It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
|
13
|
-
|
14
|
-
if (cur === '@modern-js/runtime$') {
|
15
|
-
memo[`.+${cur}`] = aliasValue[0];
|
16
|
-
return memo;
|
17
|
-
}
|
18
|
-
|
19
|
-
if (isFile) {
|
20
|
-
memo[cur] = aliasValue[0];
|
21
|
-
}
|
22
|
-
|
23
|
-
const key = `^${cur}/(.*)$`;
|
24
|
-
const value = path.normalize(`${aliasValue}/$1`);
|
25
|
-
memo[key] = value;
|
26
|
-
return memo;
|
27
|
-
}, {});
|
28
|
-
};
|
29
3
|
export const mergeUserJestConfig = async testUtils => {
|
30
4
|
const resolveJestConfig = testUtils.testConfig.jest;
|
31
5
|
|
@@ -37,26 +11,33 @@ export const mergeUserJestConfig = async testUtils => {
|
|
37
11
|
await resolveJestConfig(testUtils.jestConfig);
|
38
12
|
}
|
39
13
|
};
|
40
|
-
export default ((webpackConfig, userConfig, pwd) => createPlugin(() =>
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
14
|
+
export default ((webpackConfig, userConfig, pwd) => createPlugin(() => {
|
15
|
+
const {
|
16
|
+
resolve: {
|
17
|
+
alias = {}
|
18
|
+
}
|
19
|
+
} = webpackConfig;
|
20
|
+
return {
|
21
|
+
jestConfig: (utils, next) => {
|
22
|
+
utils.mergeJestConfig({
|
23
|
+
globals: {
|
24
|
+
[modernjs_config_key]: userConfig
|
25
|
+
},
|
26
|
+
moduleNameMapper: getModuleNameMapper(alias),
|
27
|
+
testEnvironment: 'jsdom',
|
28
|
+
resolver: require.resolve("../resolver")
|
29
|
+
});
|
30
|
+
utils.setJestConfig({
|
31
|
+
rootDir: pwd || process.cwd(),
|
32
|
+
// todo: diffrent test root for diffrent solutions
|
33
|
+
// testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
|
34
|
+
// testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
|
35
|
+
testMatch: [`<rootDir>/src/**/*.test.[jt]s?(x)`, `<rootDir>/tests/**/*.test.[jt]s?(x)`, `<rootDir>/electron/**/*.test.[jt]s?(x)`]
|
36
|
+
});
|
37
|
+
mergeUserJestConfig(utils);
|
38
|
+
return next(utils);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
}, {
|
61
42
|
name: '@modern-js/testing-plugin-modern'
|
62
43
|
}));
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { mergeUserJestConfig
|
1
|
+
import { mergeUserJestConfig } from "./modern";
|
2
2
|
describe('modern plugin', () => {
|
3
3
|
test('mergeUserJestConfig support object', () => {
|
4
4
|
const testUtils = {
|
@@ -53,17 +53,5 @@ describe('modern plugin', () => {
|
|
53
53
|
a: 1,
|
54
54
|
b: 1
|
55
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
56
|
});
|
69
57
|
});
|
@@ -4,15 +4,18 @@ import { useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
4
4
|
import { runTest } from '@modern-js/testing';
|
5
5
|
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
|
6
6
|
import testingBffPlugin from '@modern-js/testing-plugin-bff';
|
7
|
+
import { fs } from '@modern-js/utils';
|
7
8
|
import modernTestPlugin from "./plugins/modern";
|
8
9
|
|
9
10
|
const test = async () => {
|
10
11
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
11
12
|
const userConfig = useResolvedConfigContext(); // eslint-disable-next-line react-hooks/rules-of-hooks
|
12
13
|
|
13
|
-
const config = useAppContext();
|
14
|
-
|
15
|
-
|
14
|
+
const config = useAppContext();
|
15
|
+
const {
|
16
|
+
srcDirectory
|
17
|
+
} = config;
|
18
|
+
const existSrc = await fs.pathExists(srcDirectory);
|
16
19
|
userConfig.testing = userConfig.testing || {};
|
17
20
|
const jest = userConfig.testing.jest || userConfig.tools.jest;
|
18
21
|
|
@@ -21,12 +24,25 @@ const test = async () => {
|
|
21
24
|
}
|
22
25
|
|
23
26
|
userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
|
28
|
+
if (existSrc) {
|
29
|
+
// todo: consider lib-tools ...
|
30
|
+
const webpackConfigs = getWebpackConfig(WebpackConfigTarget.CLIENT);
|
31
|
+
userConfig.testing.plugins = [...(userConfig.testing.plugins || []), modernTestPlugin(webpackConfigs, userConfig, config.appDirectory), testingBffPlugin({
|
32
|
+
pwd: config.appDirectory,
|
33
|
+
userConfig,
|
34
|
+
plugins: config.plugins.map(p => p.server).filter(Boolean),
|
35
|
+
routes: config.serverRoutes
|
36
|
+
})];
|
37
|
+
} else {
|
38
|
+
userConfig.testing.plugins = [...(userConfig.testing.plugins || []), testingBffPlugin({
|
39
|
+
pwd: config.appDirectory,
|
40
|
+
userConfig,
|
41
|
+
plugins: config.plugins.map(p => p.server).filter(Boolean),
|
42
|
+
routes: config.serverRoutes
|
43
|
+
})];
|
44
|
+
}
|
45
|
+
|
30
46
|
const runtimeExportsPath = path.join(config.internalDirectory, '.runtime-exports');
|
31
47
|
await compiler({
|
32
48
|
sourceDir: runtimeExportsPath,
|
@@ -3,46 +3,12 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.mergeUserJestConfig = exports.
|
7
|
-
|
8
|
-
var _path = _interopRequireDefault(require("path"));
|
6
|
+
exports.mergeUserJestConfig = exports.default = void 0;
|
9
7
|
|
10
8
|
var _testing = require("@modern-js/testing");
|
11
9
|
|
12
10
|
var _constant = require("../../constant");
|
13
11
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
-
|
16
|
-
const getModuleNameMapper = config => {
|
17
|
-
const {
|
18
|
-
resolve: {
|
19
|
-
alias = {}
|
20
|
-
}
|
21
|
-
} = config;
|
22
|
-
return Object.keys(alias).reduce((memo, cur) => {
|
23
|
-
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
|
24
|
-
const isFile = aliasValue.some(s => s.endsWith('.js')); // It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
|
25
|
-
|
26
|
-
if (cur === '@modern-js/runtime$') {
|
27
|
-
memo[`.+${cur}`] = aliasValue[0];
|
28
|
-
return memo;
|
29
|
-
}
|
30
|
-
|
31
|
-
if (isFile) {
|
32
|
-
memo[cur] = aliasValue[0];
|
33
|
-
}
|
34
|
-
|
35
|
-
const key = `^${cur}/(.*)$`;
|
36
|
-
|
37
|
-
const value = _path.default.normalize(`${aliasValue}/$1`);
|
38
|
-
|
39
|
-
memo[key] = value;
|
40
|
-
return memo;
|
41
|
-
}, {});
|
42
|
-
};
|
43
|
-
|
44
|
-
exports.getModuleNameMapper = getModuleNameMapper;
|
45
|
-
|
46
12
|
const mergeUserJestConfig = async testUtils => {
|
47
13
|
const resolveJestConfig = testUtils.testConfig.jest;
|
48
14
|
|
@@ -57,27 +23,34 @@ const mergeUserJestConfig = async testUtils => {
|
|
57
23
|
|
58
24
|
exports.mergeUserJestConfig = mergeUserJestConfig;
|
59
25
|
|
60
|
-
var _default = (webpackConfig, userConfig, pwd) => (0, _testing.createPlugin)(() =>
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
26
|
+
var _default = (webpackConfig, userConfig, pwd) => (0, _testing.createPlugin)(() => {
|
27
|
+
const {
|
28
|
+
resolve: {
|
29
|
+
alias = {}
|
30
|
+
}
|
31
|
+
} = webpackConfig;
|
32
|
+
return {
|
33
|
+
jestConfig: (utils, next) => {
|
34
|
+
utils.mergeJestConfig({
|
35
|
+
globals: {
|
36
|
+
[_constant.modernjs_config_key]: userConfig
|
37
|
+
},
|
38
|
+
moduleNameMapper: (0, _testing.getModuleNameMapper)(alias),
|
39
|
+
testEnvironment: 'jsdom',
|
40
|
+
resolver: require.resolve("../resolver")
|
41
|
+
});
|
42
|
+
utils.setJestConfig({
|
43
|
+
rootDir: pwd || process.cwd(),
|
44
|
+
// todo: diffrent test root for diffrent solutions
|
45
|
+
// testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
|
46
|
+
// testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
|
47
|
+
testMatch: [`<rootDir>/src/**/*.test.[jt]s?(x)`, `<rootDir>/tests/**/*.test.[jt]s?(x)`, `<rootDir>/electron/**/*.test.[jt]s?(x)`]
|
48
|
+
});
|
49
|
+
mergeUserJestConfig(utils);
|
50
|
+
return next(utils);
|
51
|
+
}
|
52
|
+
};
|
53
|
+
}, {
|
81
54
|
name: '@modern-js/testing-plugin-modern'
|
82
55
|
});
|
83
56
|
|
@@ -56,17 +56,5 @@ describe('modern plugin', () => {
|
|
56
56
|
a: 1,
|
57
57
|
b: 1
|
58
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
59
|
});
|
72
60
|
});
|
package/dist/js/node/cli/test.js
CHANGED
@@ -17,6 +17,8 @@ var _webpack = require("@modern-js/webpack");
|
|
17
17
|
|
18
18
|
var _testingPluginBff = _interopRequireDefault(require("@modern-js/testing-plugin-bff"));
|
19
19
|
|
20
|
+
var _utils = require("@modern-js/utils");
|
21
|
+
|
20
22
|
var _modern = _interopRequireDefault(require("./plugins/modern"));
|
21
23
|
|
22
24
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -25,9 +27,11 @@ const test = async () => {
|
|
25
27
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
26
28
|
const userConfig = (0, _core.useResolvedConfigContext)(); // eslint-disable-next-line react-hooks/rules-of-hooks
|
27
29
|
|
28
|
-
const config = (0, _core.useAppContext)();
|
29
|
-
|
30
|
-
|
30
|
+
const config = (0, _core.useAppContext)();
|
31
|
+
const {
|
32
|
+
srcDirectory
|
33
|
+
} = config;
|
34
|
+
const existSrc = await _utils.fs.pathExists(srcDirectory);
|
31
35
|
userConfig.testing = userConfig.testing || {};
|
32
36
|
const jest = userConfig.testing.jest || userConfig.tools.jest;
|
33
37
|
|
@@ -36,12 +40,24 @@ const test = async () => {
|
|
36
40
|
}
|
37
41
|
|
38
42
|
userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
|
44
|
+
if (existSrc) {
|
45
|
+
// todo: consider lib-tools ...
|
46
|
+
const webpackConfigs = (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT);
|
47
|
+
userConfig.testing.plugins = [...(userConfig.testing.plugins || []), (0, _modern.default)(webpackConfigs, userConfig, config.appDirectory), (0, _testingPluginBff.default)({
|
48
|
+
pwd: config.appDirectory,
|
49
|
+
userConfig,
|
50
|
+
plugins: config.plugins.map(p => p.server).filter(Boolean),
|
51
|
+
routes: config.serverRoutes
|
52
|
+
})];
|
53
|
+
} else {
|
54
|
+
userConfig.testing.plugins = [...(userConfig.testing.plugins || []), (0, _testingPluginBff.default)({
|
55
|
+
pwd: config.appDirectory,
|
56
|
+
userConfig,
|
57
|
+
plugins: config.plugins.map(p => p.server).filter(Boolean),
|
58
|
+
routes: config.serverRoutes
|
59
|
+
})];
|
60
|
+
}
|
45
61
|
|
46
62
|
const runtimeExportsPath = _path.default.join(config.internalDirectory, '.runtime-exports');
|
47
63
|
|
@@ -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
|
7
|
+
var _base = require("./base");
|
26
8
|
|
27
|
-
Object.keys(
|
9
|
+
Object.keys(_base).forEach(function (key) {
|
28
10
|
if (key === "default" || key === "__esModule") return;
|
29
|
-
if (
|
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
|
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
|
+
});
|
@@ -6,33 +6,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
|
|
6
6
|
|
7
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
8
|
|
9
|
-
import
|
10
|
-
import { createPlugin } from '@modern-js/testing';
|
9
|
+
import { createPlugin, getModuleNameMapper } from '@modern-js/testing';
|
11
10
|
import { modernjs_config_key } from "../../constant";
|
12
|
-
export var getModuleNameMapper = function getModuleNameMapper(config) {
|
13
|
-
var _config$resolve$alias = config.resolve.alias,
|
14
|
-
alias = _config$resolve$alias === void 0 ? {} : _config$resolve$alias;
|
15
|
-
return Object.keys(alias).reduce(function (memo, cur) {
|
16
|
-
var aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
|
17
|
-
var isFile = aliasValue.some(function (s) {
|
18
|
-
return s.endsWith('.js');
|
19
|
-
}); // It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
|
20
|
-
|
21
|
-
if (cur === '@modern-js/runtime$') {
|
22
|
-
memo[".+".concat(cur)] = aliasValue[0];
|
23
|
-
return memo;
|
24
|
-
}
|
25
|
-
|
26
|
-
if (isFile) {
|
27
|
-
memo[cur] = aliasValue[0];
|
28
|
-
}
|
29
|
-
|
30
|
-
var key = "^".concat(cur, "/(.*)$");
|
31
|
-
var value = path.normalize("".concat(aliasValue, "/$1"));
|
32
|
-
memo[key] = value;
|
33
|
-
return memo;
|
34
|
-
}, {});
|
35
|
-
};
|
36
11
|
export var mergeUserJestConfig = /*#__PURE__*/function () {
|
37
12
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(testUtils) {
|
38
13
|
var resolveJestConfig;
|
@@ -68,11 +43,13 @@ export var mergeUserJestConfig = /*#__PURE__*/function () {
|
|
68
43
|
}();
|
69
44
|
export default (function (webpackConfig, userConfig, pwd) {
|
70
45
|
return createPlugin(function () {
|
46
|
+
var _webpackConfig$resolv = webpackConfig.resolve.alias,
|
47
|
+
alias = _webpackConfig$resolv === void 0 ? {} : _webpackConfig$resolv;
|
71
48
|
return {
|
72
49
|
jestConfig: function jestConfig(utils, next) {
|
73
50
|
utils.mergeJestConfig({
|
74
51
|
globals: _defineProperty({}, modernjs_config_key, userConfig),
|
75
|
-
moduleNameMapper: getModuleNameMapper(
|
52
|
+
moduleNameMapper: getModuleNameMapper(alias),
|
76
53
|
testEnvironment: 'jsdom',
|
77
54
|
resolver: require.resolve("../resolver")
|
78
55
|
});
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { mergeUserJestConfig
|
1
|
+
import { mergeUserJestConfig } from "./modern";
|
2
2
|
describe('modern plugin', function () {
|
3
3
|
test('mergeUserJestConfig support object', function () {
|
4
4
|
var testUtils = {
|
@@ -49,17 +49,5 @@ describe('modern plugin', function () {
|
|
49
49
|
a: 1,
|
50
50
|
b: 1
|
51
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
52
|
});
|
65
53
|
});
|
@@ -22,11 +22,12 @@ import { useAppContext, useResolvedConfigContext } from '@modern-js/core';
|
|
22
22
|
import { runTest } from '@modern-js/testing';
|
23
23
|
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
|
24
24
|
import testingBffPlugin from '@modern-js/testing-plugin-bff';
|
25
|
+
import { fs } from '@modern-js/utils';
|
25
26
|
import modernTestPlugin from "./plugins/modern";
|
26
27
|
|
27
28
|
var test = /*#__PURE__*/function () {
|
28
29
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
29
|
-
var userConfig, config,
|
30
|
+
var userConfig, config, srcDirectory, existSrc, jest, webpackConfigs, runtimeExportsPath;
|
30
31
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
31
32
|
while (1) {
|
32
33
|
switch (_context.prev = _context.next) {
|
@@ -34,9 +35,13 @@ var test = /*#__PURE__*/function () {
|
|
34
35
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
35
36
|
userConfig = useResolvedConfigContext(); // eslint-disable-next-line react-hooks/rules-of-hooks
|
36
37
|
|
37
|
-
config = useAppContext();
|
38
|
+
config = useAppContext();
|
39
|
+
srcDirectory = config.srcDirectory;
|
40
|
+
_context.next = 5;
|
41
|
+
return fs.pathExists(srcDirectory);
|
38
42
|
|
39
|
-
|
43
|
+
case 5:
|
44
|
+
existSrc = _context.sent;
|
40
45
|
userConfig.testing = userConfig.testing || {};
|
41
46
|
jest = userConfig.testing.jest || userConfig.tools.jest;
|
42
47
|
|
@@ -45,16 +50,31 @@ var test = /*#__PURE__*/function () {
|
|
45
50
|
}
|
46
51
|
|
47
52
|
userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
|
54
|
+
if (existSrc) {
|
55
|
+
// todo: consider lib-tools ...
|
56
|
+
webpackConfigs = getWebpackConfig(WebpackConfigTarget.CLIENT);
|
57
|
+
userConfig.testing.plugins = [].concat(_toConsumableArray(userConfig.testing.plugins || []), [modernTestPlugin(webpackConfigs, userConfig, config.appDirectory), testingBffPlugin({
|
58
|
+
pwd: config.appDirectory,
|
59
|
+
userConfig: userConfig,
|
60
|
+
plugins: config.plugins.map(function (p) {
|
61
|
+
return p.server;
|
62
|
+
}).filter(Boolean),
|
63
|
+
routes: config.serverRoutes
|
64
|
+
})]);
|
65
|
+
} else {
|
66
|
+
userConfig.testing.plugins = [].concat(_toConsumableArray(userConfig.testing.plugins || []), [testingBffPlugin({
|
67
|
+
pwd: config.appDirectory,
|
68
|
+
userConfig: userConfig,
|
69
|
+
plugins: config.plugins.map(function (p) {
|
70
|
+
return p.server;
|
71
|
+
}).filter(Boolean),
|
72
|
+
routes: config.serverRoutes
|
73
|
+
})]);
|
74
|
+
}
|
75
|
+
|
56
76
|
runtimeExportsPath = path.join(config.internalDirectory, '.runtime-exports');
|
57
|
-
_context.next =
|
77
|
+
_context.next = 14;
|
58
78
|
return compiler({
|
59
79
|
sourceDir: runtimeExportsPath,
|
60
80
|
rootDir: runtimeExportsPath,
|
@@ -66,11 +86,11 @@ var test = /*#__PURE__*/function () {
|
|
66
86
|
}]]
|
67
87
|
});
|
68
88
|
|
69
|
-
case
|
70
|
-
_context.next =
|
89
|
+
case 14:
|
90
|
+
_context.next = 16;
|
71
91
|
return runTest(userConfig.testing);
|
72
92
|
|
73
|
-
case
|
93
|
+
case 16:
|
74
94
|
case "end":
|
75
95
|
return _context.stop();
|
76
96
|
}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import type { NormalizedConfig } from '@modern-js/core';
|
2
|
-
export declare const getModuleNameMapper: (config: any) => any;
|
3
2
|
export declare const mergeUserJestConfig: (testUtils: any) => Promise<void>;
|
4
3
|
|
5
4
|
declare const _default: (webpackConfig: any, userConfig: NormalizedConfig, pwd: string) => any;
|
package/package.json
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
"modern",
|
12
12
|
"modern.js"
|
13
13
|
],
|
14
|
-
"version": "1.3.
|
14
|
+
"version": "1.3.4",
|
15
15
|
"jsnext:source": "./src/index.ts",
|
16
16
|
"types": "./dist/types/index.d.ts",
|
17
17
|
"main": "./dist/js/node/index.js",
|
@@ -40,6 +40,15 @@
|
|
40
40
|
},
|
41
41
|
"default": "./dist/js/treeshaking/runtime-testing/index.js"
|
42
42
|
},
|
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
|
+
},
|
43
52
|
"./cli": {
|
44
53
|
"jsnext:source": "./src/cli/index.ts",
|
45
54
|
"default": "./dist/js/node/cli/index.js"
|
@@ -58,6 +67,9 @@
|
|
58
67
|
],
|
59
68
|
"type": [
|
60
69
|
"./type.d.ts"
|
70
|
+
],
|
71
|
+
"runtime-base": [
|
72
|
+
"./dist/types/runtime-testing/base.d.ts"
|
61
73
|
]
|
62
74
|
}
|
63
75
|
},
|
@@ -65,20 +77,20 @@
|
|
65
77
|
"@babel/preset-env": "^7.15.6",
|
66
78
|
"@babel/runtime": "^7",
|
67
79
|
"@modern-js/babel-compiler": "^1.2.1",
|
68
|
-
"@modern-js/testing": "^1.3.
|
69
|
-
"@modern-js/utils": "^1.
|
70
|
-
"@modern-js/webpack": "^1.
|
80
|
+
"@modern-js/testing": "^1.3.2",
|
81
|
+
"@modern-js/utils": "^1.3.2",
|
82
|
+
"@modern-js/webpack": "^1.4.0",
|
71
83
|
"@testing-library/jest-dom": "^5.14.1",
|
72
84
|
"@testing-library/react": "^12.0.0",
|
73
85
|
"enhanced-resolve": "^5.8.3",
|
74
|
-
"@modern-js/testing-plugin-bff": "^1.2.
|
86
|
+
"@modern-js/testing-plugin-bff": "^1.2.2"
|
75
87
|
},
|
76
88
|
"peerDependencies": {
|
77
89
|
"@modern-js-reduck/plugin-auto-actions": "^1.0.0",
|
78
90
|
"@modern-js-reduck/plugin-effects": "^1.0.0",
|
79
91
|
"@modern-js-reduck/plugin-immutable": "^1.0.0",
|
80
92
|
"@modern-js-reduck/store": "^1.0.0",
|
81
|
-
"@modern-js/core": "^1.3
|
93
|
+
"@modern-js/core": "^1.4.3",
|
82
94
|
"@modern-js/runtime-core": "^1.2.1"
|
83
95
|
},
|
84
96
|
"devDependencies": {
|
@@ -87,7 +99,7 @@
|
|
87
99
|
"@modern-js-reduck/plugin-immutable": "^1.0.0",
|
88
100
|
"@modern-js-reduck/store": "^1.0.0",
|
89
101
|
"@scripts/build": "0.0.0",
|
90
|
-
"@modern-js/core": "^1.3
|
102
|
+
"@modern-js/core": "^1.4.3",
|
91
103
|
"@modern-js/runtime-core": "^1.2.1",
|
92
104
|
"@types/jest": "^26",
|
93
105
|
"@types/node": "^14",
|
@@ -103,8 +115,7 @@
|
|
103
115
|
"modernConfig": {},
|
104
116
|
"publishConfig": {
|
105
117
|
"registry": "https://registry.npmjs.org/",
|
106
|
-
"access": "public"
|
107
|
-
"types": "./dist/types/index.d.ts"
|
118
|
+
"access": "public"
|
108
119
|
},
|
109
120
|
"scripts": {
|
110
121
|
"new": "modern new",
|
package/type.d.ts
CHANGED
@@ -5,7 +5,7 @@ import "./dist/types/runtime-testing"
|
|
5
5
|
|
6
6
|
declare module '@modern-js/runtime/testing' {
|
7
7
|
export * from '@testing-library/react';
|
8
|
-
export { renderApp, createStore } from './dist/types/runtime-testing';
|
8
|
+
export { renderApp, createStore, testBff } from './dist/types/runtime-testing';
|
9
9
|
}
|
10
10
|
|
11
11
|
declare module '@modern-js/core' {
|