@modern-js/plugin-testing 1.21.5 → 2.0.0-beta.1
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 +88 -29
- package/dist/js/modern/base/config/index.js +1 -3
- package/dist/js/modern/base/config/patches/index.js +0 -2
- package/dist/js/modern/base/config/patches/transformer.js +1 -7
- package/dist/js/modern/base/config/resolver.js +0 -3
- package/dist/js/modern/base/config/testConfigOperator.js +0 -23
- package/dist/js/modern/base/config/transformer/babelTransformer.js +0 -1
- package/dist/js/modern/base/runJest.js +11 -14
- package/dist/js/modern/base/utils.js +2 -12
- package/dist/js/modern/cli/bff/app.js +1 -8
- package/dist/js/modern/cli/bff/index.js +5 -17
- package/dist/js/modern/cli/bff/mockAPI.js +4 -20
- package/dist/js/modern/cli/bff/setup.js +0 -5
- package/dist/js/modern/cli/bff/utils/index.js +0 -4
- package/dist/js/modern/cli/index.js +7 -15
- package/dist/js/modern/cli/test.js +0 -4
- package/dist/js/modern/runtime-testing/app.js +0 -15
- package/dist/js/modern/runtime-testing/customRender.js +0 -6
- package/dist/js/modern/runtime-testing/reduck.js +0 -10
- package/dist/js/modern/runtime-testing/request.js +1 -4
- package/dist/js/modern/runtime-testing/resolvePlugins.js +0 -6
- package/dist/js/node/base/config/index.js +0 -8
- package/dist/js/node/base/config/patches/assetsModule.js +0 -2
- package/dist/js/node/base/config/patches/index.js +0 -6
- package/dist/js/node/base/config/patches/transformer.js +1 -9
- package/dist/js/node/base/config/resolver.js +0 -5
- package/dist/js/node/base/config/testConfigOperator.js +0 -24
- package/dist/js/node/base/config/transformer/babelTransformer.js +0 -4
- package/dist/js/node/base/hook.js +0 -2
- package/dist/js/node/base/index.js +0 -7
- package/dist/js/node/base/runJest.js +11 -21
- package/dist/js/node/base/utils.js +2 -22
- package/dist/js/node/cli/bff/app.js +1 -15
- package/dist/js/node/cli/bff/index.js +5 -27
- package/dist/js/node/cli/bff/mockAPI.js +2 -25
- package/dist/js/node/cli/bff/setup.js +0 -11
- package/dist/js/node/cli/bff/utils/index.js +0 -9
- package/dist/js/node/cli/index.js +6 -27
- package/dist/js/node/cli/test.js +0 -10
- package/dist/js/node/index.js +0 -4
- package/dist/js/node/runtime-testing/app.js +0 -20
- package/dist/js/node/runtime-testing/base.js +0 -5
- package/dist/js/node/runtime-testing/customRender.js +0 -10
- package/dist/js/node/runtime-testing/index.js +0 -4
- package/dist/js/node/runtime-testing/reduck.js +0 -24
- package/dist/js/node/runtime-testing/request.js +1 -6
- package/dist/js/node/runtime-testing/resolvePlugins.js +0 -8
- package/dist/js/treeshaking/base/config/index.js +1 -6
- package/dist/js/treeshaking/base/config/patches/index.js +0 -17
- package/dist/js/treeshaking/base/config/patches/transformer.js +1 -7
- package/dist/js/treeshaking/base/config/resolver.js +0 -3
- package/dist/js/treeshaking/base/config/testConfigOperator.js +0 -15
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +0 -1
- package/dist/js/treeshaking/base/runJest.js +19 -38
- package/dist/js/treeshaking/base/utils.js +2 -10
- package/dist/js/treeshaking/cli/bff/app.js +1 -14
- package/dist/js/treeshaking/cli/bff/index.js +5 -24
- package/dist/js/treeshaking/cli/bff/mockAPI.js +8 -24
- package/dist/js/treeshaking/cli/bff/setup.js +0 -9
- package/dist/js/treeshaking/cli/bff/utils/index.js +1 -2
- package/dist/js/treeshaking/cli/index.js +8 -15
- package/dist/js/treeshaking/cli/test.js +0 -7
- package/dist/js/treeshaking/runtime-testing/app.js +2 -15
- package/dist/js/treeshaking/runtime-testing/customRender.js +0 -3
- package/dist/js/treeshaking/runtime-testing/reduck.js +0 -7
- package/dist/js/treeshaking/runtime-testing/request.js +2 -7
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +0 -3
- package/dist/types/base/config/index.d.ts +0 -1
- package/dist/types/base/config/patches/assetsModule.d.ts +0 -1
- package/dist/types/base/config/patches/filemock.d.ts +0 -1
- package/dist/types/base/config/patches/transformer.d.ts +0 -1
- package/dist/types/base/config/testConfigOperator.d.ts +0 -2
- package/dist/types/base/runJest.d.ts +0 -2
- package/dist/types/base/utils.d.ts +0 -1
- package/dist/types/cli/bff/app.d.ts +2 -1
- package/dist/types/cli/bff/index.d.ts +2 -3
- package/dist/types/cli/bff/mockAPI.d.ts +0 -1
- package/dist/types/cli/index.d.ts +0 -2
- package/dist/types/runtime-testing/app.d.ts +0 -3
- package/dist/types/runtime-testing/customRender.d.ts +0 -2
- package/package.json +18 -41
package/CHANGELOG.md
CHANGED
|
@@ -1,42 +1,101 @@
|
|
|
1
1
|
# @modern-js/plugin-testing
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 2.0.0-beta.1
|
|
4
4
|
|
|
5
|
-
###
|
|
6
|
-
|
|
7
|
-
- Updated dependencies [a150632]
|
|
8
|
-
- Updated dependencies [29576fc]
|
|
9
|
-
- @modern-js/runtime@1.21.5
|
|
10
|
-
- @modern-js/babel-preset-app@1.21.5
|
|
11
|
-
- @modern-js/webpack@1.21.5
|
|
12
|
-
- @modern-js/prod-server@1.21.5
|
|
13
|
-
- @modern-js/babel-compiler@1.21.5
|
|
14
|
-
- @modern-js/plugin@1.21.5
|
|
15
|
-
- @modern-js/utils@1.21.5
|
|
5
|
+
### Major Changes
|
|
16
6
|
|
|
17
|
-
|
|
7
|
+
- dda38c9: chore: v2
|
|
18
8
|
|
|
19
9
|
### Patch Changes
|
|
20
10
|
|
|
21
|
-
-
|
|
22
|
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
|
|
11
|
+
- cc971eabfc: refactor: move server plugin load logic in `@modern-js/core`
|
|
12
|
+
refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
|
|
13
|
+
- 14b712d: fix: use consistent alias type and default value across packages
|
|
14
|
+
|
|
15
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [2344eb2]
|
|
18
|
+
- Updated dependencies [a11fcf8]
|
|
19
|
+
- Updated dependencies [b18fa8f]
|
|
20
|
+
- Updated dependencies [c9e800d39a]
|
|
21
|
+
- Updated dependencies [d032d49]
|
|
22
|
+
- Updated dependencies [15bf09d9c8]
|
|
23
|
+
- Updated dependencies [3e57f2b]
|
|
24
|
+
- Updated dependencies [fbf5eed]
|
|
25
|
+
- Updated dependencies [a2509bfbdb]
|
|
26
|
+
- Updated dependencies [decfcd989d]
|
|
27
|
+
- Updated dependencies [4369648ae2]
|
|
28
|
+
- Updated dependencies [92f0ead]
|
|
29
|
+
- Updated dependencies [92c0994]
|
|
30
|
+
- Updated dependencies [edd1cfb1af]
|
|
31
|
+
- Updated dependencies [cc971eabfc]
|
|
32
|
+
- Updated dependencies [5b9049f]
|
|
33
|
+
- Updated dependencies [6bda14ed71]
|
|
34
|
+
- Updated dependencies [92004d1]
|
|
35
|
+
- Updated dependencies [b8bbe036c7]
|
|
36
|
+
- Updated dependencies [40ed587]
|
|
37
|
+
- Updated dependencies [60d5378632]
|
|
38
|
+
- Updated dependencies [d5a31df781]
|
|
39
|
+
- Updated dependencies [dda38c9]
|
|
40
|
+
- Updated dependencies [102d32e4ba]
|
|
41
|
+
- Updated dependencies [8b8e1bb571]
|
|
42
|
+
- Updated dependencies [3bbea92b2a]
|
|
43
|
+
- Updated dependencies [73cd29dd9f]
|
|
44
|
+
- Updated dependencies [18aaf42]
|
|
45
|
+
- Updated dependencies [f179749]
|
|
46
|
+
- Updated dependencies [fcace5b5b9]
|
|
47
|
+
- Updated dependencies [abf3421]
|
|
48
|
+
- Updated dependencies [543be9558e]
|
|
49
|
+
- Updated dependencies [14b712d]
|
|
50
|
+
- @modern-js/runtime@2.0.0-beta.1
|
|
51
|
+
- @modern-js/prod-server@2.0.0-beta.1
|
|
52
|
+
- @modern-js/babel-preset-app@2.0.0-beta.1
|
|
53
|
+
- @modern-js/utils@2.0.0-beta.1
|
|
54
|
+
- @modern-js/plugin@2.0.0-beta.1
|
|
55
|
+
- @modern-js/babel-compiler@2.0.0-beta.1
|
|
56
|
+
|
|
57
|
+
## 2.0.0-beta.0
|
|
58
|
+
|
|
59
|
+
### Major Changes
|
|
60
|
+
|
|
61
|
+
- dda38c9: chore: v2
|
|
30
62
|
|
|
31
63
|
### Patch Changes
|
|
32
64
|
|
|
33
|
-
-
|
|
34
|
-
|
|
35
|
-
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
-
|
|
65
|
+
- cc971eabf: refactor: move server plugin load logic in `@modern-js/core`
|
|
66
|
+
refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
|
|
67
|
+
- 14b712d: fix: use consistent alias type and default value across packages
|
|
68
|
+
|
|
69
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
70
|
+
|
|
71
|
+
- Updated dependencies [b18fa8f]
|
|
72
|
+
- Updated dependencies [c9e800d39]
|
|
73
|
+
- Updated dependencies [15bf09d9c]
|
|
74
|
+
- Updated dependencies [a2509bf]
|
|
75
|
+
- Updated dependencies [decfcd989]
|
|
76
|
+
- Updated dependencies [4369648ae]
|
|
77
|
+
- Updated dependencies [edd1cfb1a]
|
|
78
|
+
- Updated dependencies [cc971eabf]
|
|
79
|
+
- Updated dependencies [5b9049f]
|
|
80
|
+
- Updated dependencies [6bda14ed7]
|
|
81
|
+
- Updated dependencies [b8bbe036c]
|
|
82
|
+
- Updated dependencies [60d5378]
|
|
83
|
+
- Updated dependencies [d5a31df78]
|
|
84
|
+
- Updated dependencies [dda38c9]
|
|
85
|
+
- Updated dependencies [102d32e4b]
|
|
86
|
+
- Updated dependencies [8b8e1bb57]
|
|
87
|
+
- Updated dependencies [3bbea92b2]
|
|
88
|
+
- Updated dependencies [73cd29dd9]
|
|
89
|
+
- Updated dependencies [fcace5b5b]
|
|
90
|
+
- Updated dependencies [abf3421]
|
|
91
|
+
- Updated dependencies [543be95]
|
|
92
|
+
- Updated dependencies [14b712d]
|
|
93
|
+
- @modern-js/runtime@2.0.0-beta.0
|
|
94
|
+
- @modern-js/prod-server@2.0.0-beta.0
|
|
95
|
+
- @modern-js/babel-preset-app@2.0.0-beta.0
|
|
96
|
+
- @modern-js/utils@2.0.0-beta.0
|
|
97
|
+
- @modern-js/plugin@2.0.0-beta.0
|
|
98
|
+
- @modern-js/babel-compiler@2.0.0-beta.0
|
|
40
99
|
|
|
41
100
|
## 1.21.2
|
|
42
101
|
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { applyPatches } from "./patches";
|
|
2
2
|
import { TestConfigOperator } from "./testConfigOperator";
|
|
3
|
+
|
|
3
4
|
/**
|
|
4
5
|
* Parse jest config
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
const getJestUtils = testConfig => {
|
|
8
8
|
const testOperator = new TestConfigOperator(testConfig);
|
|
9
9
|
return testOperator;
|
|
10
10
|
};
|
|
11
|
-
|
|
12
11
|
const patchConfig = async testOperator => {
|
|
13
12
|
await applyPatches(testOperator);
|
|
14
13
|
return testOperator.jestConfig;
|
|
15
14
|
};
|
|
16
|
-
|
|
17
15
|
export const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
|
18
16
|
export { getJestUtils, patchConfig };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { patchTransformer } from "./transformer";
|
|
2
2
|
import { patchAssetsModule } from "./assetsModule";
|
|
3
|
-
|
|
4
3
|
const _applyPatches = async (patches, testOperator) => {
|
|
5
4
|
for (const patch of patches) {
|
|
6
5
|
await patch(testOperator);
|
|
7
6
|
}
|
|
8
7
|
};
|
|
9
|
-
|
|
10
8
|
const patches = [patchTransformer, patchAssetsModule];
|
|
11
9
|
export const applyPatches = async testConfig => {
|
|
12
10
|
await _applyPatches(patches, testConfig);
|
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import { readCompilerOptions } from "../../utils";
|
|
2
|
-
|
|
3
2
|
const resolveTsCompilerOptions = () => {
|
|
4
3
|
const tsCompilerOptions = readCompilerOptions() || {};
|
|
5
4
|
const {
|
|
6
5
|
jsx
|
|
7
6
|
} = tsCompilerOptions;
|
|
8
|
-
|
|
9
7
|
if (!jsx) {
|
|
10
8
|
return null;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
tsCompilerOptions.jsx = 'react-jsx';
|
|
14
11
|
return tsCompilerOptions;
|
|
15
12
|
};
|
|
13
|
+
|
|
16
14
|
/**
|
|
17
15
|
* Map `TestConfig.transformer` to jest config
|
|
18
16
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
17
|
export const patchTransformer = testOperator => {
|
|
22
18
|
const {
|
|
23
19
|
transformer
|
|
24
20
|
} = testOperator.testConfig;
|
|
25
|
-
|
|
26
21
|
if (transformer === 'babel-jest') {
|
|
27
22
|
testOperator.mergeJestConfig({
|
|
28
23
|
transform: {
|
|
@@ -30,7 +25,6 @@ export const patchTransformer = testOperator => {
|
|
|
30
25
|
}
|
|
31
26
|
});
|
|
32
27
|
}
|
|
33
|
-
|
|
34
28
|
if (transformer === 'ts-jest') {
|
|
35
29
|
testOperator.mergeJestConfig({
|
|
36
30
|
transform: {
|
|
@@ -3,13 +3,10 @@ const resolver = enhanceResolve.create.sync({
|
|
|
3
3
|
conditionNames: ['require', 'node', 'default'],
|
|
4
4
|
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
const shouldResolveByEnhance = url => /^@[^/]+\/[^/]+\/.*/.test(url);
|
|
8
|
-
|
|
9
7
|
module.exports = function (request, options) {
|
|
10
8
|
if (shouldResolveByEnhance(request)) {
|
|
11
9
|
return resolver(options.basedir, request);
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
return options.defaultResolver(request, options);
|
|
15
12
|
};
|
|
@@ -1,86 +1,63 @@
|
|
|
1
1
|
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; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
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
|
-
|
|
7
4
|
import { merge } from '@modern-js/utils/lodash';
|
|
8
|
-
|
|
9
5
|
class TestConfigOperator {
|
|
10
6
|
constructor(testConfig) {
|
|
11
7
|
_defineProperty(this, "_testConfig", void 0);
|
|
12
|
-
|
|
13
8
|
_defineProperty(this, "_jestConfig", void 0);
|
|
14
|
-
|
|
15
9
|
_defineProperty(this, "userJestConfig", void 0);
|
|
16
|
-
|
|
17
10
|
_defineProperty(this, "defaultTestConfig", {
|
|
18
11
|
transformer: 'babel-jest'
|
|
19
12
|
});
|
|
20
|
-
|
|
21
13
|
this._testConfig = testConfig;
|
|
22
14
|
this._jestConfig = {};
|
|
23
15
|
this.userJestConfig = testConfig.jest;
|
|
24
16
|
this.initial();
|
|
25
17
|
}
|
|
26
|
-
|
|
27
18
|
initial() {
|
|
28
19
|
this._testConfig = merge({}, this.defaultTestConfig, this.testConfig);
|
|
29
20
|
}
|
|
30
|
-
|
|
31
21
|
get jestConfig() {
|
|
32
22
|
return this._jestConfig;
|
|
33
23
|
}
|
|
34
|
-
|
|
35
24
|
get testConfig() {
|
|
36
25
|
return this._testConfig;
|
|
37
26
|
}
|
|
38
|
-
|
|
39
27
|
mergeJestConfig(sourceConfig) {
|
|
40
28
|
this._jestConfig = merge({}, this._jestConfig, sourceConfig);
|
|
41
29
|
}
|
|
42
|
-
|
|
43
30
|
setJestUserConfig() {
|
|
44
31
|
const {
|
|
45
32
|
userJestConfig
|
|
46
33
|
} = this;
|
|
47
|
-
|
|
48
34
|
if (typeof userJestConfig === 'object') {
|
|
49
35
|
this.setJestConfig(userJestConfig);
|
|
50
36
|
}
|
|
51
37
|
}
|
|
52
|
-
|
|
53
38
|
setJestConfig(sourceConfig, options) {
|
|
54
39
|
if (options) {
|
|
55
40
|
const {
|
|
56
41
|
force
|
|
57
42
|
} = options;
|
|
58
|
-
|
|
59
43
|
if (force) {
|
|
60
44
|
this._jestConfig = sourceConfig;
|
|
61
45
|
return;
|
|
62
46
|
}
|
|
63
47
|
}
|
|
64
|
-
|
|
65
48
|
this._jestConfig = _objectSpread(_objectSpread({}, this._jestConfig), sourceConfig);
|
|
66
49
|
}
|
|
67
|
-
|
|
68
50
|
getFinalConfig() {
|
|
69
51
|
const {
|
|
70
52
|
userJestConfig
|
|
71
53
|
} = this;
|
|
72
|
-
|
|
73
54
|
if (!userJestConfig) {
|
|
74
55
|
return this._jestConfig;
|
|
75
56
|
}
|
|
76
|
-
|
|
77
57
|
if (typeof userJestConfig === 'function') {
|
|
78
58
|
return userJestConfig(this._jestConfig);
|
|
79
59
|
}
|
|
80
|
-
|
|
81
60
|
return this.jestConfig;
|
|
82
61
|
}
|
|
83
|
-
|
|
84
62
|
}
|
|
85
|
-
|
|
86
63
|
export { TestConfigOperator };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
var _babelJest$createTran;
|
|
2
|
-
|
|
3
2
|
import babelJest from 'babel-jest';
|
|
4
3
|
const babelTransformer = (_babelJest$createTran = babelJest.createTransformer) === null || _babelJest$createTran === void 0 ? void 0 : _babelJest$createTran.call(babelJest, {
|
|
5
4
|
presets: [[require.resolve('@modern-js/babel-preset-app'), {
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
* The followed code is inspired by
|
|
6
6
|
* https://github.com/facebook/jest/blob/fdc74af37235354e077edeeee8aa2d1a4a863032/packages/jest-cli/src/cli/index.ts#L21
|
|
7
7
|
*/
|
|
8
|
+
|
|
8
9
|
import yargs from 'yargs/yargs';
|
|
9
10
|
import { runCLI } from 'jest';
|
|
10
11
|
import { chalk } from '@modern-js/utils';
|
|
11
12
|
import { getJestUtils, patchConfig } from "./config";
|
|
12
13
|
import { debug } from "./utils";
|
|
13
|
-
|
|
14
14
|
const buildArgv = async (rawArgv, config) => {
|
|
15
15
|
const argv = await yargs(rawArgv).argv;
|
|
16
16
|
const result = {
|
|
@@ -21,32 +21,28 @@ const buildArgv = async (rawArgv, config) => {
|
|
|
21
21
|
if (key.includes('-') || key === '_') {
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
|
|
25
24
|
result[key] = argv[key];
|
|
26
25
|
});
|
|
27
|
-
|
|
28
26
|
if (config) {
|
|
29
27
|
result.config = JSON.stringify(config);
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
return result;
|
|
33
30
|
};
|
|
34
|
-
|
|
35
31
|
const readResultsAndExit = (result, globalConfig) => {
|
|
36
|
-
const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
|
|
32
|
+
const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
|
|
37
33
|
|
|
34
|
+
// Only exit if needed
|
|
38
35
|
process.on('exit', () => {
|
|
39
36
|
if (typeof code === 'number' && code !== 0) {
|
|
40
37
|
process.exitCode = code;
|
|
41
38
|
}
|
|
42
39
|
});
|
|
43
|
-
|
|
44
40
|
if (globalConfig.forceExit) {
|
|
45
41
|
if (!globalConfig.detectOpenHandles) {
|
|
46
42
|
console.warn(`${chalk.bold('Force exiting Jest: ')}Have you considered using \`--detectOpenHandles\` to detect ` + `async operations that kept running after all tests finished?`);
|
|
47
|
-
}
|
|
48
|
-
|
|
43
|
+
}
|
|
49
44
|
|
|
45
|
+
// eslint-disable-next-line no-process-exit
|
|
50
46
|
process.exit(code);
|
|
51
47
|
} else if (!globalConfig.detectOpenHandles) {
|
|
52
48
|
setTimeout(() => {
|
|
@@ -54,11 +50,10 @@ const readResultsAndExit = (result, globalConfig) => {
|
|
|
54
50
|
}, 1000).unref();
|
|
55
51
|
}
|
|
56
52
|
};
|
|
53
|
+
|
|
57
54
|
/**
|
|
58
55
|
* Node API: execute jest
|
|
59
56
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
57
|
export async function runJest(config, pwd = process.cwd()) {
|
|
63
58
|
try {
|
|
64
59
|
const argvConfig = await buildArgv(process.argv.slice(2), config);
|
|
@@ -68,20 +63,22 @@ export async function runJest(config, pwd = process.cwd()) {
|
|
|
68
63
|
} = await runCLI(argvConfig, [pwd]);
|
|
69
64
|
readResultsAndExit(results, globalConfig);
|
|
70
65
|
} catch (e) {
|
|
71
|
-
console.error(chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
|
|
66
|
+
console.error(chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
|
|
72
67
|
|
|
68
|
+
// eslint-disable-next-line no-process-exit
|
|
73
69
|
process.exit(1);
|
|
74
70
|
}
|
|
75
71
|
}
|
|
72
|
+
|
|
76
73
|
/**
|
|
77
74
|
* Node API: run test
|
|
78
75
|
*/
|
|
79
|
-
|
|
80
76
|
export async function runTest(api, config, pwd = process.cwd()) {
|
|
81
77
|
process.env.NODE_ENV = 'test';
|
|
82
78
|
const jestUtils = getJestUtils(config);
|
|
83
|
-
await patchConfig(jestUtils);
|
|
79
|
+
await patchConfig(jestUtils);
|
|
84
80
|
|
|
81
|
+
// 确保用户设置的配置可以被插件处理,比如设置在 projects 中
|
|
85
82
|
jestUtils.setJestUserConfig();
|
|
86
83
|
const hookRunners = api.useHookRunners();
|
|
87
84
|
const testConfigOperator = await hookRunners.jestConfig(jestUtils, {
|
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
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; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
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
|
-
|
|
7
4
|
import fs from 'fs';
|
|
8
5
|
import path from 'path';
|
|
9
6
|
import { createDebugger } from '@modern-js/utils';
|
|
10
7
|
export const debug = createDebugger('test');
|
|
11
|
-
|
|
12
8
|
/**
|
|
13
9
|
* Read `compilerOptions` in the current pwd's tsconfig.json file
|
|
14
10
|
*/
|
|
@@ -16,42 +12,36 @@ export const readCompilerOptions = (pwd = process.cwd(), filename = 'tsconfig.js
|
|
|
16
12
|
let tsConfig = {};
|
|
17
13
|
let extendedCompilerOptions = {};
|
|
18
14
|
let tsconfigFile = '';
|
|
19
|
-
|
|
20
15
|
try {
|
|
21
16
|
const maybeTsconfigFile = path.join(pwd, filename);
|
|
22
|
-
|
|
23
17
|
if (fs.existsSync(maybeTsconfigFile)) {
|
|
24
18
|
tsconfigFile = maybeTsconfigFile;
|
|
25
19
|
} else {
|
|
26
20
|
tsconfigFile = require.resolve(filename);
|
|
27
21
|
}
|
|
28
|
-
|
|
29
22
|
({
|
|
30
23
|
config: tsConfig
|
|
31
24
|
} = require('typescript').parseConfigFileTextToJson(tsconfigFile, fs.readFileSync(tsconfigFile, 'utf8')));
|
|
32
25
|
} catch (e) {
|
|
33
26
|
return {};
|
|
34
27
|
}
|
|
35
|
-
|
|
36
28
|
if (tsConfig.extends) {
|
|
37
29
|
extendedCompilerOptions = readCompilerOptions(path.dirname(tsconfigFile), tsConfig.extends);
|
|
38
30
|
}
|
|
39
|
-
|
|
40
31
|
return _objectSpread(_objectSpread({}, extendedCompilerOptions), tsConfig.compilerOptions);
|
|
41
32
|
};
|
|
42
33
|
export const getModuleNameMapper = alias => Object.keys(alias).reduce((memo, cur) => {
|
|
43
34
|
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
|
|
44
|
-
const isFile = aliasValue.some(s => s.endsWith('.js'));
|
|
35
|
+
const isFile = aliasValue.some(s => s.endsWith('.js'));
|
|
45
36
|
|
|
37
|
+
// It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
|
|
46
38
|
if (cur === '@modern-js/runtime$') {
|
|
47
39
|
memo[`.+${cur}`] = aliasValue[0];
|
|
48
40
|
return memo;
|
|
49
41
|
}
|
|
50
|
-
|
|
51
42
|
if (isFile) {
|
|
52
43
|
memo[cur] = aliasValue[0];
|
|
53
44
|
}
|
|
54
|
-
|
|
55
45
|
const key = `^${cur}/(.*)$`;
|
|
56
46
|
const value = path.normalize(`${aliasValue}/$1`);
|
|
57
47
|
memo[key] = value;
|
|
@@ -3,7 +3,6 @@ import { Server } from '@modern-js/prod-server';
|
|
|
3
3
|
const store = new AsyncLocalStorage();
|
|
4
4
|
export const isInHandler = () => Boolean(store.getStore());
|
|
5
5
|
let server = null;
|
|
6
|
-
|
|
7
6
|
const createApp = async (pwd, config, plugins, routes) => {
|
|
8
7
|
if (!server) {
|
|
9
8
|
config.output.path = './';
|
|
@@ -11,30 +10,24 @@ const createApp = async (pwd, config, plugins, routes) => {
|
|
|
11
10
|
apiOnly: true,
|
|
12
11
|
pwd,
|
|
13
12
|
config,
|
|
14
|
-
plugins,
|
|
13
|
+
internalPlugins: plugins,
|
|
15
14
|
routes
|
|
16
15
|
});
|
|
17
16
|
await server.init();
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
const app = server.getRequestHandler();
|
|
21
19
|
return app;
|
|
22
20
|
};
|
|
23
|
-
|
|
24
21
|
const getApp = () => {
|
|
25
22
|
if (!server) {
|
|
26
23
|
throw new Error('please createApp first');
|
|
27
24
|
}
|
|
28
|
-
|
|
29
25
|
return server.getRequestHandler();
|
|
30
26
|
};
|
|
31
|
-
|
|
32
27
|
const closeServer = async () => {
|
|
33
28
|
if (!server) {
|
|
34
29
|
throw new Error('please createApp first');
|
|
35
30
|
}
|
|
36
|
-
|
|
37
31
|
await server.close();
|
|
38
32
|
};
|
|
39
|
-
|
|
40
33
|
export { createApp, getApp, closeServer };
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
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; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
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
|
-
|
|
7
4
|
import path from 'path';
|
|
8
5
|
import { isApiOnly } from '@modern-js/utils';
|
|
9
6
|
import { getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../../base";
|
|
@@ -17,7 +14,6 @@ export const setJestConfigForBFF = async ({
|
|
|
17
14
|
utils
|
|
18
15
|
}) => {
|
|
19
16
|
var _userConfig$source;
|
|
20
|
-
|
|
21
17
|
const bffConfig = {
|
|
22
18
|
rootDir: path.join(pwd, './api'),
|
|
23
19
|
setupFilesAfterEnv: [require.resolve("./setup")],
|
|
@@ -44,26 +40,24 @@ export const setJestConfigForBFF = async ({
|
|
|
44
40
|
const aliasMapper = getModuleNameMapper(alias);
|
|
45
41
|
const {
|
|
46
42
|
moduleNameMapper
|
|
47
|
-
} = jestConfig;
|
|
43
|
+
} = jestConfig;
|
|
48
44
|
|
|
45
|
+
// 服务端统一使用 ts-jest
|
|
49
46
|
const transform = {
|
|
50
47
|
'\\.[jt]sx?$': require.resolve('ts-jest')
|
|
51
48
|
};
|
|
52
49
|
const apiOnly = await isApiOnly(pwd);
|
|
53
|
-
|
|
54
50
|
const mergedModuleNameMapper = _objectSpread(_objectSpread({}, moduleNameMapper), aliasMapper);
|
|
51
|
+
const resolver = jestConfig.resolver || DEFAULT_RESOLVER_PATH;
|
|
55
52
|
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
// 这三个配置不能设置在 projects 中,需要设置在外层(https://github.com/facebook/jest/issues/9696)
|
|
58
54
|
const configFields = ['coverage', 'collectCoverage', 'testTimeout'];
|
|
59
55
|
const commonConfig = configFields.reduce((obj, field) => {
|
|
60
56
|
if (jestConfig.hasOwnProperty(field)) {
|
|
61
57
|
obj[field] = jestConfig[field];
|
|
62
58
|
}
|
|
63
|
-
|
|
64
59
|
return obj;
|
|
65
60
|
}, {});
|
|
66
|
-
|
|
67
61
|
if (!apiOnly) {
|
|
68
62
|
utils.setJestConfig({
|
|
69
63
|
projects: [_objectSpread({}, jestConfig), _objectSpread({
|
|
@@ -85,34 +79,28 @@ export const setJestConfigForBFF = async ({
|
|
|
85
79
|
force: true
|
|
86
80
|
});
|
|
87
81
|
}
|
|
88
|
-
|
|
89
82
|
utils.setJestConfig(commonConfig);
|
|
90
83
|
};
|
|
91
84
|
export default (() => ({
|
|
92
85
|
name: '@modern-js/testing-plugin-bff',
|
|
93
|
-
|
|
94
86
|
setup(api) {
|
|
95
87
|
return {
|
|
96
88
|
jestConfig: async (utils, next) => {
|
|
97
89
|
const appContext = api.useAppContext();
|
|
98
90
|
const pwd = appContext.appDirectory;
|
|
99
|
-
|
|
100
91
|
if (!isBFFProject(pwd)) {
|
|
101
92
|
return next(utils);
|
|
102
93
|
}
|
|
103
|
-
|
|
104
94
|
const userConfig = api.useResolvedConfigContext();
|
|
105
|
-
const plugins = appContext.plugins.map(p => p.server).filter(Boolean);
|
|
106
95
|
await setJestConfigForBFF({
|
|
107
96
|
pwd,
|
|
108
97
|
userConfig,
|
|
109
|
-
plugins,
|
|
110
98
|
routes: appContext.serverRoutes,
|
|
99
|
+
plugins: appContext.serverInternalPlugins,
|
|
111
100
|
utils
|
|
112
101
|
});
|
|
113
102
|
return next(utils);
|
|
114
103
|
}
|
|
115
104
|
};
|
|
116
105
|
}
|
|
117
|
-
|
|
118
106
|
}));
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
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; }
|
|
2
|
-
|
|
3
2
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
-
|
|
5
3
|
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
|
-
|
|
7
4
|
import * as ptr from 'path-to-regexp';
|
|
8
|
-
import * as mockAppModule from "./app";
|
|
5
|
+
import * as mockAppModule from "./app";
|
|
9
6
|
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10
8
|
const mock_replaceUrlWithParams = (url, paramValues, payload) => {
|
|
11
9
|
const keys = [];
|
|
12
10
|
ptr.pathToRegexp(url, keys);
|
|
@@ -14,28 +12,24 @@ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
|
|
|
14
12
|
if (paramValues[index]) {
|
|
15
13
|
cur[key.name] = paramValues[index];
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
return cur;
|
|
19
16
|
}, {});
|
|
20
17
|
const getFinalPath = ptr.compile(url, {
|
|
21
18
|
encode: encodeURIComponent
|
|
22
19
|
});
|
|
23
20
|
return getFinalPath(_objectSpread(_objectSpread({}, params), payload));
|
|
24
|
-
};
|
|
25
|
-
|
|
21
|
+
};
|
|
26
22
|
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
27
24
|
const mock_getParamsAndPayload = args => {
|
|
28
25
|
if (args.length === 0) {
|
|
29
26
|
return [[], {}];
|
|
30
27
|
}
|
|
31
|
-
|
|
32
28
|
const head = args[0];
|
|
33
|
-
|
|
34
29
|
if (typeof head === 'object') {
|
|
35
30
|
return [[], head];
|
|
36
31
|
} else {
|
|
37
32
|
const latest = args[args.length - 1];
|
|
38
|
-
|
|
39
33
|
if (typeof latest === 'object') {
|
|
40
34
|
return [args.slice(0, args.length - 1), latest];
|
|
41
35
|
} else {
|
|
@@ -43,20 +37,17 @@ const mock_getParamsAndPayload = args => {
|
|
|
43
37
|
}
|
|
44
38
|
}
|
|
45
39
|
};
|
|
46
|
-
|
|
47
40
|
export default (mockApiInfosByFile => {
|
|
48
41
|
const files = Object.keys(mockApiInfosByFile);
|
|
49
42
|
files.forEach(mockedFile => {
|
|
50
43
|
jest.mock(mockedFile, () => {
|
|
51
44
|
const supertest = require('supertest');
|
|
52
|
-
|
|
53
45
|
return mockApiInfosByFile[mockedFile].reduce((res, info) => {
|
|
54
46
|
const module = {
|
|
55
47
|
[info.name]: (...args) => {
|
|
56
48
|
if (mockAppModule.isInHandler()) {
|
|
57
49
|
return info.handler(...args);
|
|
58
50
|
}
|
|
59
|
-
|
|
60
51
|
const [params, payload] = mock_getParamsAndPayload(args);
|
|
61
52
|
const {
|
|
62
53
|
returnHttp
|
|
@@ -64,33 +55,26 @@ export default (mockApiInfosByFile => {
|
|
|
64
55
|
const url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
|
|
65
56
|
const app = mockAppModule.getApp();
|
|
66
57
|
let test = supertest(app)[info.httpMethod.toLowerCase()](url);
|
|
67
|
-
|
|
68
58
|
if (payload.query) {
|
|
69
59
|
test = test.query(payload.query);
|
|
70
60
|
}
|
|
71
|
-
|
|
72
61
|
if (payload.body) {
|
|
73
62
|
test = test.send(payload.body);
|
|
74
63
|
}
|
|
75
|
-
|
|
76
64
|
if (payload.data) {
|
|
77
65
|
test = test.send(payload.data);
|
|
78
66
|
}
|
|
79
|
-
|
|
80
67
|
if (payload.headers) {
|
|
81
68
|
for (const name in payload.headers) {
|
|
82
69
|
test = test.set(name, payload.headers[name]);
|
|
83
70
|
}
|
|
84
71
|
}
|
|
85
|
-
|
|
86
72
|
if (payload.cookies) {
|
|
87
73
|
test = test.set('Cookie', [payload.cookies]);
|
|
88
74
|
}
|
|
89
|
-
|
|
90
75
|
if (returnHttp) {
|
|
91
76
|
return test;
|
|
92
77
|
}
|
|
93
|
-
|
|
94
78
|
return test.then(value => {
|
|
95
79
|
try {
|
|
96
80
|
return JSON.parse(value.text);
|