@modern-js/plugin-testing 1.3.0 → 1.3.3
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 +44 -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/resolver.js +1 -1
- 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/resolver.js +1 -1
- 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/resolver.js +1 -1
- 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/{src/runtime-testing/index.ts → dist/types/runtime-testing/base.d.ts} +1 -2
- package/dist/types/runtime-testing/index.d.ts +2 -4
- package/package.json +20 -12
- package/tests/.eslintrc.js +6 -0
- package/tests/resolver.test.ts +30 -0
- package/tests/tsconfig.json +13 -0
- package/type.d.ts +5 -1
- package/src/.eslintrc.json +0 -3
- package/src/cli/index.ts +0 -48
- package/src/cli/plugins/modern.test.ts +0 -68
- package/src/cli/plugins/modern.ts +0 -83
- package/src/cli/resolver.ts +0 -16
- package/src/cli/test.ts +0 -77
- 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/reduck.ts +0 -38
- package/src/runtime-testing/resolvePlugins.ts +0 -23
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,49 @@
|
|
1
1
|
# @modern-js/plugin-testing
|
2
2
|
|
3
|
+
## 1.3.3
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 698ad9e8: feat: support test bff for api service
|
8
|
+
- 11fda442: fix: add testing runtime base
|
9
|
+
- Updated dependencies [75f4eeb8]
|
10
|
+
- Updated dependencies [698ad9e8]
|
11
|
+
- Updated dependencies [53aca274]
|
12
|
+
- Updated dependencies [78279953]
|
13
|
+
- Updated dependencies [e116ace5]
|
14
|
+
- Updated dependencies [4d72edea]
|
15
|
+
- @modern-js/webpack@1.3.1
|
16
|
+
- @modern-js/testing@1.3.2
|
17
|
+
- @modern-js/testing-plugin-bff@1.2.2
|
18
|
+
- @modern-js/core@1.4.1
|
19
|
+
- @modern-js/utils@1.3.1
|
20
|
+
|
21
|
+
## 1.3.2
|
22
|
+
|
23
|
+
### Patch Changes
|
24
|
+
|
25
|
+
- b57ded28: fix testing resolver
|
26
|
+
- 1b22634e: fix: plugin testing types
|
27
|
+
- Updated dependencies [7dc5aa75]
|
28
|
+
- @modern-js/webpack@1.2.2
|
29
|
+
|
30
|
+
## 1.3.1
|
31
|
+
|
32
|
+
### Patch Changes
|
33
|
+
|
34
|
+
- 83166714: change .npmignore
|
35
|
+
- Updated dependencies [83166714]
|
36
|
+
- Updated dependencies [c3de9882]
|
37
|
+
- Updated dependencies [33ff48af]
|
38
|
+
- Updated dependencies [c74597bd]
|
39
|
+
- @modern-js/core@1.3.2
|
40
|
+
- @modern-js/webpack@1.2.1
|
41
|
+
- @modern-js/testing@1.3.1
|
42
|
+
- @modern-js/testing-plugin-bff@1.2.1
|
43
|
+
- @modern-js/runtime-core@1.2.1
|
44
|
+
- @modern-js/babel-compiler@1.2.1
|
45
|
+
- @modern-js/utils@1.2.2
|
46
|
+
|
3
47
|
## 1.3.0
|
4
48
|
|
5
49
|
### Minor 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
|
});
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import enhanceResolve from 'enhanced-resolve';
|
2
2
|
const resolver = enhanceResolve.create.sync({
|
3
|
-
conditionNames: ['
|
3
|
+
conditionNames: ['require', 'node', 'default'],
|
4
4
|
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
5
5
|
});
|
6
6
|
|
@@ -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
|
});
|
@@ -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: ['
|
8
|
+
conditionNames: ['require', 'node', 'default'],
|
9
9
|
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
10
10
|
});
|
11
11
|
|
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
|
});
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import enhanceResolve from 'enhanced-resolve';
|
2
2
|
var resolver = enhanceResolve.create.sync({
|
3
|
-
conditionNames: ['
|
3
|
+
conditionNames: ['require', 'node', 'default'],
|
4
4
|
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
5
5
|
});
|
6
6
|
|