@modern-js/plugin-testing 0.0.0-next-20221209071922 → 0.0.0-next-20221209140613
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 +80 -7
- package/dist/js/modern/base/config/index.js +9 -29
- package/dist/js/modern/base/config/patches/assetsModule.js +7 -7
- package/dist/js/modern/base/config/patches/filemock.js +1 -4
- package/dist/js/modern/base/config/patches/index.js +7 -30
- package/dist/js/modern/base/config/patches/transformer.js +18 -13
- package/dist/js/modern/base/config/resolver.js +6 -11
- package/dist/js/modern/base/config/testConfigOperator.js +25 -29
- package/dist/js/modern/base/config/transformer/babelTransformer.js +8 -16
- package/dist/js/modern/base/hook.js +5 -10
- package/dist/js/modern/base/index.js +6 -14
- package/dist/js/modern/base/runJest.js +62 -73
- package/dist/js/modern/base/utils.js +25 -40
- package/dist/js/modern/cli/bff/app.js +12 -37
- package/dist/js/modern/cli/bff/constant.js +1 -4
- package/dist/js/modern/cli/bff/index.js +54 -95
- package/dist/js/modern/cli/bff/mockAPI.js +66 -79
- package/dist/js/modern/cli/bff/setup.js +34 -71
- package/dist/js/modern/cli/bff/utils/index.js +17 -31
- package/dist/js/modern/cli/index.js +30 -65
- package/dist/js/modern/cli/test.js +18 -53
- package/dist/js/modern/constant.js +1 -4
- package/dist/js/modern/index.js +3 -3
- package/dist/js/modern/runtime-testing/app.js +16 -25
- package/dist/js/modern/runtime-testing/base.js +3 -7
- package/dist/js/modern/runtime-testing/customRender.js +12 -24
- package/dist/js/modern/runtime-testing/index.js +1 -1
- package/dist/js/modern/runtime-testing/reduck.js +21 -41
- package/dist/js/modern/runtime-testing/request.js +4 -4
- package/dist/js/modern/runtime-testing/resolvePlugins.js +10 -24
- package/dist/js/node/base/config/index.js +18 -56
- package/dist/js/node/base/config/patches/assetsModule.js +12 -30
- package/dist/js/node/base/config/patches/filemock.js +7 -22
- package/dist/js/node/base/config/patches/index.js +15 -50
- package/dist/js/node/base/config/patches/transformer.js +25 -38
- package/dist/js/node/base/config/resolver.js +10 -37
- package/dist/js/node/base/config/testConfigOperator.js +32 -49
- package/dist/js/node/base/config/transformer/babelTransformer.js +15 -40
- package/dist/js/node/base/hook.js +13 -28
- package/dist/js/node/base/index.js +63 -31
- package/dist/js/node/base/runJest.js +71 -99
- package/dist/js/node/base/utils.js +36 -66
- package/dist/js/node/cli/bff/app.js +22 -57
- package/dist/js/node/cli/bff/constant.js +7 -22
- package/dist/js/node/cli/bff/index.js +67 -121
- package/dist/js/node/cli/bff/mockAPI.js +73 -103
- package/dist/js/node/cli/bff/setup.js +38 -100
- package/dist/js/node/cli/bff/utils/index.js +24 -55
- package/dist/js/node/cli/index.js +46 -88
- package/dist/js/node/cli/test.js +27 -79
- package/dist/js/node/constant.js +7 -22
- package/dist/js/node/index.js +18 -19
- package/dist/js/node/runtime-testing/app.js +27 -53
- package/dist/js/node/runtime-testing/base.js +33 -30
- package/dist/js/node/runtime-testing/customRender.js +20 -49
- package/dist/js/node/runtime-testing/index.js +27 -18
- package/dist/js/node/runtime-testing/reduck.js +33 -67
- package/dist/js/node/runtime-testing/request.js +13 -32
- package/dist/js/node/runtime-testing/resolvePlugins.js +14 -41
- package/dist/js/treeshaking/base/config/index.js +31 -150
- package/dist/js/treeshaking/base/config/patches/assetsModule.js +11 -9
- package/dist/js/treeshaking/base/config/patches/filemock.js +1 -2
- package/dist/js/treeshaking/base/config/patches/index.js +64 -221
- package/dist/js/treeshaking/base/config/patches/transformer.js +37 -34
- package/dist/js/treeshaking/base/config/resolver.js +11 -24
- package/dist/js/treeshaking/base/config/testConfigOperator.js +69 -120
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +10 -16
- package/dist/js/treeshaking/base/hook.js +7 -8
- package/dist/js/treeshaking/base/index.js +6 -7
- package/dist/js/treeshaking/base/runJest.js +164 -281
- package/dist/js/treeshaking/base/utils.js +48 -72
- package/dist/js/treeshaking/cli/bff/app.js +68 -192
- package/dist/js/treeshaking/cli/bff/constant.js +1 -2
- package/dist/js/treeshaking/cli/bff/index.js +130 -291
- package/dist/js/treeshaking/cli/bff/mockAPI.js +91 -181
- package/dist/js/treeshaking/cli/bff/setup.js +59 -185
- package/dist/js/treeshaking/cli/bff/utils/index.js +21 -47
- package/dist/js/treeshaking/cli/index.js +108 -249
- package/dist/js/treeshaking/cli/test.js +44 -177
- package/dist/js/treeshaking/constant.js +1 -2
- package/dist/js/treeshaking/index.js +3 -3
- package/dist/js/treeshaking/runtime-testing/app.js +39 -85
- package/dist/js/treeshaking/runtime-testing/base.js +3 -4
- package/dist/js/treeshaking/runtime-testing/customRender.js +10 -38
- package/dist/js/treeshaking/runtime-testing/index.js +1 -1
- package/dist/js/treeshaking/runtime-testing/reduck.js +33 -85
- package/dist/js/treeshaking/runtime-testing/request.js +19 -49
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +14 -45
- 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/resolver.d.ts +1 -2
- 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/index.d.ts +0 -2
- 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 +13 -13
- package/dist/js/modern/modern-app.env.d.js +0 -0
- package/dist/js/node/modern-app.env.d.js +0 -0
- package/dist/js/treeshaking/modern-app.env.d.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @modern-js/plugin-testing
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20221209140613
|
|
4
4
|
|
|
5
5
|
### Major Changes
|
|
6
6
|
|
|
@@ -18,7 +18,10 @@
|
|
|
18
18
|
- Updated dependencies [a11fcf8b5]
|
|
19
19
|
- Updated dependencies [e7ce0636d]
|
|
20
20
|
- Updated dependencies [b18fa8f3e]
|
|
21
|
+
- Updated dependencies [7879e8f71]
|
|
22
|
+
- Updated dependencies [50d4675e5]
|
|
21
23
|
- Updated dependencies [c9e800d39]
|
|
24
|
+
- Updated dependencies [6604f1b8b]
|
|
22
25
|
- Updated dependencies [d032d49e0]
|
|
23
26
|
- Updated dependencies [6aca87501]
|
|
24
27
|
- Updated dependencies [fda836fe8]
|
|
@@ -53,17 +56,87 @@
|
|
|
53
56
|
- Updated dependencies [34702d5d4]
|
|
54
57
|
- Updated dependencies [f17974937]
|
|
55
58
|
- Updated dependencies [fcace5b5b]
|
|
59
|
+
- Updated dependencies [ea7cf0625]
|
|
56
60
|
- Updated dependencies [bbe4c4ab6]
|
|
57
61
|
- Updated dependencies [e4558a0bc]
|
|
58
62
|
- Updated dependencies [abf3421a7]
|
|
59
63
|
- Updated dependencies [543be9558]
|
|
64
|
+
- Updated dependencies [fd1d9fd3d]
|
|
60
65
|
- Updated dependencies [14b712da8]
|
|
61
|
-
- @modern-js/runtime@0.0.0-next-
|
|
62
|
-
- @modern-js/prod-server@0.0.0-next-
|
|
63
|
-
- @modern-js/utils@0.0.0-next-
|
|
64
|
-
- @modern-js/babel-preset-app@0.0.0-next-
|
|
65
|
-
- @modern-js/plugin@0.0.0-next-
|
|
66
|
-
- @modern-js/babel-compiler@0.0.0-next-
|
|
66
|
+
- @modern-js/runtime@0.0.0-next-20221209140613
|
|
67
|
+
- @modern-js/prod-server@0.0.0-next-20221209140613
|
|
68
|
+
- @modern-js/utils@0.0.0-next-20221209140613
|
|
69
|
+
- @modern-js/babel-preset-app@0.0.0-next-20221209140613
|
|
70
|
+
- @modern-js/plugin@0.0.0-next-20221209140613
|
|
71
|
+
- @modern-js/babel-compiler@0.0.0-next-20221209140613
|
|
72
|
+
|
|
73
|
+
## 2.0.0-beta.3
|
|
74
|
+
|
|
75
|
+
### Major Changes
|
|
76
|
+
|
|
77
|
+
- dda38c9c3e: chore: v2
|
|
78
|
+
|
|
79
|
+
### Patch Changes
|
|
80
|
+
|
|
81
|
+
- cc971eabfc: refactor: move server plugin load logic in `@modern-js/core`
|
|
82
|
+
refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
|
|
83
|
+
- 14b712da84: fix: use consistent alias type and default value across packages
|
|
84
|
+
|
|
85
|
+
fix: 在各个包中使用一致的 alias 类型定义和默认值
|
|
86
|
+
|
|
87
|
+
- Updated dependencies [2344eb26ed]
|
|
88
|
+
- Updated dependencies [a11fcf8b50]
|
|
89
|
+
- Updated dependencies [e7ce063]
|
|
90
|
+
- Updated dependencies [b18fa8f3ed]
|
|
91
|
+
- Updated dependencies [c9e800d39a]
|
|
92
|
+
- Updated dependencies [6604f1b]
|
|
93
|
+
- Updated dependencies [d032d49e09]
|
|
94
|
+
- Updated dependencies [6aca875]
|
|
95
|
+
- Updated dependencies [fda836f]
|
|
96
|
+
- Updated dependencies [15bf09d9c8]
|
|
97
|
+
- Updated dependencies [3e57f2bd58]
|
|
98
|
+
- Updated dependencies [2e60319]
|
|
99
|
+
- Updated dependencies [fbf5eed5aa]
|
|
100
|
+
- Updated dependencies [a2509bfbdb]
|
|
101
|
+
- Updated dependencies [425e570]
|
|
102
|
+
- Updated dependencies [decfcd989d]
|
|
103
|
+
- Updated dependencies [e4357f1]
|
|
104
|
+
- Updated dependencies [4369648ae2]
|
|
105
|
+
- Updated dependencies [92f0eade39]
|
|
106
|
+
- Updated dependencies [92c0994468]
|
|
107
|
+
- Updated dependencies [edd1cfb1af]
|
|
108
|
+
- Updated dependencies [cc971eabfc]
|
|
109
|
+
- Updated dependencies [5b9049f2e9]
|
|
110
|
+
- Updated dependencies [6bda14ed71]
|
|
111
|
+
- Updated dependencies [92004d1906]
|
|
112
|
+
- Updated dependencies [b8bbe036c7]
|
|
113
|
+
- Updated dependencies [40ed5874c6]
|
|
114
|
+
- Updated dependencies [60d5378632]
|
|
115
|
+
- Updated dependencies [d5a31df781]
|
|
116
|
+
- Updated dependencies [dda38c9c3e]
|
|
117
|
+
- Updated dependencies [102d32e4ba]
|
|
118
|
+
- Updated dependencies [8b8e1bb571]
|
|
119
|
+
- Updated dependencies [3bbea92b2a]
|
|
120
|
+
- Updated dependencies [73cd29dd9f]
|
|
121
|
+
- Updated dependencies [b710adb]
|
|
122
|
+
- Updated dependencies [cce8ece]
|
|
123
|
+
- Updated dependencies [18aaf42249]
|
|
124
|
+
- Updated dependencies [34702d5]
|
|
125
|
+
- Updated dependencies [f179749375]
|
|
126
|
+
- Updated dependencies [fcace5b5b9]
|
|
127
|
+
- Updated dependencies [ea7cf06]
|
|
128
|
+
- Updated dependencies [bbe4c4a]
|
|
129
|
+
- Updated dependencies [e4558a0]
|
|
130
|
+
- Updated dependencies [abf3421a75]
|
|
131
|
+
- Updated dependencies [543be9558e]
|
|
132
|
+
- Updated dependencies [fd1d9fd]
|
|
133
|
+
- Updated dependencies [14b712da84]
|
|
134
|
+
- @modern-js/runtime@2.0.0-beta.3
|
|
135
|
+
- @modern-js/prod-server@2.0.0-beta.3
|
|
136
|
+
- @modern-js/utils@2.0.0-beta.3
|
|
137
|
+
- @modern-js/babel-preset-app@2.0.0-beta.3
|
|
138
|
+
- @modern-js/plugin@2.0.0-beta.3
|
|
139
|
+
- @modern-js/babel-compiler@2.0.0-beta.3
|
|
67
140
|
|
|
68
141
|
## 2.0.0-beta.2
|
|
69
142
|
|
|
@@ -1,36 +1,16 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
1
|
import { applyPatches } from "./patches";
|
|
22
2
|
import { TestConfigOperator } from "./testConfigOperator";
|
|
23
|
-
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parse jest config
|
|
6
|
+
*/
|
|
7
|
+
const getJestUtils = testConfig => {
|
|
24
8
|
const testOperator = new TestConfigOperator(testConfig);
|
|
25
9
|
return testOperator;
|
|
26
10
|
};
|
|
27
|
-
const patchConfig =
|
|
28
|
-
|
|
11
|
+
const patchConfig = async testOperator => {
|
|
12
|
+
await applyPatches(testOperator);
|
|
29
13
|
return testOperator.jestConfig;
|
|
30
|
-
});
|
|
31
|
-
const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
|
32
|
-
export {
|
|
33
|
-
DEFAULT_RESOLVER_PATH,
|
|
34
|
-
getJestUtils,
|
|
35
|
-
patchConfig
|
|
36
14
|
};
|
|
15
|
+
export const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
|
16
|
+
export { getJestUtils, patchConfig };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Merge config from testConfig.jest
|
|
3
|
+
*/
|
|
4
|
+
export const patchAssetsModule = testOperator => {
|
|
2
5
|
testOperator.mergeJestConfig({
|
|
3
6
|
moduleNameMapper: {
|
|
4
|
-
|
|
5
|
-
|
|
7
|
+
'\\.(css|less|scss|sass)$': require.resolve('identity-obj-proxy'),
|
|
8
|
+
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': require.resolve("./filemock.js")
|
|
6
9
|
}
|
|
7
10
|
});
|
|
8
|
-
};
|
|
9
|
-
export {
|
|
10
|
-
patchAssetsModule
|
|
11
|
-
};
|
|
11
|
+
};
|
|
@@ -1,34 +1,11 @@
|
|
|
1
|
-
var __async = (__this, __arguments, generator) => {
|
|
2
|
-
return new Promise((resolve, reject) => {
|
|
3
|
-
var fulfilled = (value) => {
|
|
4
|
-
try {
|
|
5
|
-
step(generator.next(value));
|
|
6
|
-
} catch (e) {
|
|
7
|
-
reject(e);
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
var rejected = (value) => {
|
|
11
|
-
try {
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
1
|
import { patchTransformer } from "./transformer";
|
|
22
2
|
import { patchAssetsModule } from "./assetsModule";
|
|
23
|
-
const _applyPatches = (
|
|
24
|
-
for (const patch of
|
|
25
|
-
|
|
3
|
+
const _applyPatches = async (patches, testOperator) => {
|
|
4
|
+
for (const patch of patches) {
|
|
5
|
+
await patch(testOperator);
|
|
26
6
|
}
|
|
27
|
-
});
|
|
28
|
-
const patches = [patchTransformer, patchAssetsModule];
|
|
29
|
-
const applyPatches = (testConfig) => __async(void 0, null, function* () {
|
|
30
|
-
yield _applyPatches(patches, testConfig);
|
|
31
|
-
});
|
|
32
|
-
export {
|
|
33
|
-
applyPatches
|
|
34
7
|
};
|
|
8
|
+
const patches = [patchTransformer, patchAssetsModule];
|
|
9
|
+
export const applyPatches = async testConfig => {
|
|
10
|
+
await _applyPatches(patches, testConfig);
|
|
11
|
+
};
|
|
@@ -1,38 +1,43 @@
|
|
|
1
1
|
import { readCompilerOptions } from "../../utils";
|
|
2
2
|
const resolveTsCompilerOptions = () => {
|
|
3
3
|
const tsCompilerOptions = readCompilerOptions() || {};
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
jsx
|
|
6
|
+
} = tsCompilerOptions;
|
|
5
7
|
if (!jsx) {
|
|
6
8
|
return null;
|
|
7
9
|
}
|
|
8
|
-
tsCompilerOptions.jsx =
|
|
10
|
+
tsCompilerOptions.jsx = 'react-jsx';
|
|
9
11
|
return tsCompilerOptions;
|
|
10
12
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Map `TestConfig.transformer` to jest config
|
|
16
|
+
*/
|
|
17
|
+
export const patchTransformer = testOperator => {
|
|
18
|
+
const {
|
|
19
|
+
transformer
|
|
20
|
+
} = testOperator.testConfig;
|
|
21
|
+
if (transformer === 'babel-jest') {
|
|
14
22
|
testOperator.mergeJestConfig({
|
|
15
23
|
transform: {
|
|
16
|
-
|
|
24
|
+
'\\.[jt]sx?$': require.resolve("../transformer/babelTransformer")
|
|
17
25
|
}
|
|
18
26
|
});
|
|
19
27
|
}
|
|
20
|
-
if (transformer ===
|
|
28
|
+
if (transformer === 'ts-jest') {
|
|
21
29
|
testOperator.mergeJestConfig({
|
|
22
30
|
transform: {
|
|
23
|
-
|
|
31
|
+
'\\.[jt]sx?$': require.resolve('ts-jest')
|
|
24
32
|
}
|
|
25
33
|
});
|
|
26
34
|
const compilerOptions = resolveTsCompilerOptions();
|
|
27
35
|
compilerOptions && testOperator.mergeJestConfig({
|
|
28
36
|
globals: {
|
|
29
|
-
|
|
37
|
+
'ts-jest': {
|
|
30
38
|
tsconfig: compilerOptions
|
|
31
39
|
}
|
|
32
40
|
}
|
|
33
41
|
});
|
|
34
42
|
}
|
|
35
|
-
};
|
|
36
|
-
export {
|
|
37
|
-
patchTransformer
|
|
38
|
-
};
|
|
43
|
+
};
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import enhanceResolve from
|
|
1
|
+
import enhanceResolve from 'enhanced-resolve';
|
|
2
2
|
const resolver = enhanceResolve.create.sync({
|
|
3
|
-
conditionNames: [
|
|
4
|
-
extensions: [
|
|
3
|
+
conditionNames: ['require', 'node', 'default'],
|
|
4
|
+
extensions: ['.js', '.json', '.node', '.ts', '.tsx']
|
|
5
5
|
});
|
|
6
|
-
const shouldResolveByEnhance =
|
|
7
|
-
|
|
6
|
+
const shouldResolveByEnhance = url => /^@[^/]+\/[^/]+\/.*/.test(url);
|
|
7
|
+
module.exports = function (request, options) {
|
|
8
8
|
if (shouldResolveByEnhance(request)) {
|
|
9
9
|
return resolver(options.basedir, request);
|
|
10
10
|
}
|
|
11
11
|
return options.defaultResolver(request, options);
|
|
12
|
-
};
|
|
13
|
-
module.exports = internalResolve;
|
|
14
|
-
var resolver_default = internalResolve;
|
|
15
|
-
export {
|
|
16
|
-
resolver_default as default
|
|
17
|
-
};
|
|
12
|
+
};
|
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
for (var prop in b || (b = {}))
|
|
8
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
-
__defNormalProp(a, prop, b[prop]);
|
|
10
|
-
if (__getOwnPropSymbols)
|
|
11
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
12
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
|
14
|
-
}
|
|
15
|
-
return a;
|
|
16
|
-
};
|
|
17
|
-
import { merge } from "@modern-js/utils/lodash";
|
|
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
|
+
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; }
|
|
3
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
4
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
|
|
5
|
+
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
6
|
+
import { merge } from '@modern-js/utils/lodash';
|
|
18
7
|
class TestConfigOperator {
|
|
19
8
|
constructor(testConfig) {
|
|
20
|
-
this
|
|
21
|
-
|
|
22
|
-
|
|
9
|
+
_defineProperty(this, "_testConfig", void 0);
|
|
10
|
+
_defineProperty(this, "_jestConfig", void 0);
|
|
11
|
+
_defineProperty(this, "userJestConfig", void 0);
|
|
12
|
+
_defineProperty(this, "defaultTestConfig", {
|
|
13
|
+
transformer: 'babel-jest'
|
|
14
|
+
});
|
|
23
15
|
this._testConfig = testConfig;
|
|
24
16
|
this._jestConfig = {};
|
|
25
17
|
this.userJestConfig = testConfig.jest;
|
|
@@ -38,32 +30,36 @@ class TestConfigOperator {
|
|
|
38
30
|
this._jestConfig = merge({}, this._jestConfig, sourceConfig);
|
|
39
31
|
}
|
|
40
32
|
setJestUserConfig() {
|
|
41
|
-
const {
|
|
42
|
-
|
|
33
|
+
const {
|
|
34
|
+
userJestConfig
|
|
35
|
+
} = this;
|
|
36
|
+
if (typeof userJestConfig === 'object') {
|
|
43
37
|
this.setJestConfig(userJestConfig);
|
|
44
38
|
}
|
|
45
39
|
}
|
|
46
40
|
setJestConfig(sourceConfig, options) {
|
|
47
41
|
if (options) {
|
|
48
|
-
const {
|
|
42
|
+
const {
|
|
43
|
+
force
|
|
44
|
+
} = options;
|
|
49
45
|
if (force) {
|
|
50
46
|
this._jestConfig = sourceConfig;
|
|
51
47
|
return;
|
|
52
48
|
}
|
|
53
49
|
}
|
|
54
|
-
this._jestConfig =
|
|
50
|
+
this._jestConfig = _objectSpread(_objectSpread({}, this._jestConfig), sourceConfig);
|
|
55
51
|
}
|
|
56
52
|
getFinalConfig() {
|
|
57
|
-
const {
|
|
53
|
+
const {
|
|
54
|
+
userJestConfig
|
|
55
|
+
} = this;
|
|
58
56
|
if (!userJestConfig) {
|
|
59
57
|
return this._jestConfig;
|
|
60
58
|
}
|
|
61
|
-
if (typeof userJestConfig ===
|
|
59
|
+
if (typeof userJestConfig === 'function') {
|
|
62
60
|
return userJestConfig(this._jestConfig);
|
|
63
61
|
}
|
|
64
62
|
return this.jestConfig;
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
|
-
export {
|
|
68
|
-
TestConfigOperator
|
|
69
|
-
};
|
|
65
|
+
export { TestConfigOperator };
|
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
import babelJest from
|
|
3
|
-
const babelTransformer = (
|
|
4
|
-
presets: [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
appDirectory: process.cwd(),
|
|
9
|
-
modules: "cjs"
|
|
10
|
-
}
|
|
11
|
-
]
|
|
12
|
-
],
|
|
1
|
+
var _babelJest$createTran;
|
|
2
|
+
import babelJest from 'babel-jest';
|
|
3
|
+
const babelTransformer = (_babelJest$createTran = babelJest.createTransformer) === null || _babelJest$createTran === void 0 ? void 0 : _babelJest$createTran.call(babelJest, {
|
|
4
|
+
presets: [[require.resolve('@modern-js/babel-preset-app'), {
|
|
5
|
+
appDirectory: process.cwd(),
|
|
6
|
+
modules: 'cjs'
|
|
7
|
+
}]],
|
|
13
8
|
configFile: false,
|
|
14
9
|
babelrc: false
|
|
15
10
|
});
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
babelTransformer_default as default
|
|
19
|
-
};
|
|
11
|
+
export default babelTransformer;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import { createAsyncPipeline, createParallelWorkflow } from
|
|
2
|
-
const jestConfigHook = createAsyncPipeline();
|
|
3
|
-
const afterTestHook = createParallelWorkflow();
|
|
4
|
-
const testingHooks = {
|
|
1
|
+
import { createAsyncPipeline, createParallelWorkflow } from '@modern-js/plugin';
|
|
2
|
+
export const jestConfigHook = createAsyncPipeline();
|
|
3
|
+
export const afterTestHook = createParallelWorkflow();
|
|
4
|
+
export const testingHooks = {
|
|
5
5
|
jestConfig: createAsyncPipeline(),
|
|
6
6
|
afterTest: createParallelWorkflow()
|
|
7
|
-
};
|
|
8
|
-
export {
|
|
9
|
-
afterTestHook,
|
|
10
|
-
jestConfigHook,
|
|
11
|
-
testingHooks
|
|
12
|
-
};
|
|
7
|
+
};
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export * from "./types";
|
|
7
|
-
export {
|
|
8
|
-
DEFAULT_RESOLVER_PATH,
|
|
9
|
-
TestConfigOperator,
|
|
10
|
-
getModuleNameMapper,
|
|
11
|
-
runJest,
|
|
12
|
-
runTest,
|
|
13
|
-
testingHooks
|
|
14
|
-
};
|
|
1
|
+
export { runTest, runJest } from "./runJest";
|
|
2
|
+
export { getModuleNameMapper } from "./utils";
|
|
3
|
+
export { DEFAULT_RESOLVER_PATH } from "./config";
|
|
4
|
+
export { TestConfigOperator } from "./config/testConfigOperator";
|
|
5
|
+
export { testingHooks } from "./hook";
|
|
6
|
+
export * from "./types";
|
|
@@ -1,36 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
step(generator.throw(value));
|
|
13
|
-
} catch (e) {
|
|
14
|
-
reject(e);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
import yargs from "yargs/yargs";
|
|
22
|
-
import { runCLI } from "jest";
|
|
23
|
-
import { chalk } from "@modern-js/utils";
|
|
1
|
+
/**
|
|
2
|
+
* @file run jest by nodejs API
|
|
3
|
+
* @description
|
|
4
|
+
* Jest does not provide node API to run jest.
|
|
5
|
+
* The followed code is inspired by
|
|
6
|
+
* https://github.com/facebook/jest/blob/fdc74af37235354e077edeeee8aa2d1a4a863032/packages/jest-cli/src/cli/index.ts#L21
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import yargs from 'yargs/yargs';
|
|
10
|
+
import { runCLI } from 'jest';
|
|
11
|
+
import { chalk } from '@modern-js/utils';
|
|
24
12
|
import { getJestUtils, patchConfig } from "./config";
|
|
25
13
|
import { debug } from "./utils";
|
|
26
|
-
const buildArgv = (rawArgv, config) =>
|
|
27
|
-
const argv =
|
|
14
|
+
const buildArgv = async (rawArgv, config) => {
|
|
15
|
+
const argv = await yargs(rawArgv).argv;
|
|
28
16
|
const result = {
|
|
29
17
|
$0: argv.$0,
|
|
30
18
|
_: argv._.slice(1)
|
|
31
19
|
};
|
|
32
|
-
Object.keys(argv).forEach(
|
|
33
|
-
if (key.includes(
|
|
20
|
+
Object.keys(argv).forEach(key => {
|
|
21
|
+
if (key.includes('-') || key === '_') {
|
|
34
22
|
return;
|
|
35
23
|
}
|
|
36
24
|
result[key] = argv[key];
|
|
@@ -39,64 +27,65 @@ const buildArgv = (rawArgv, config) => __async(void 0, null, function* () {
|
|
|
39
27
|
result.config = JSON.stringify(config);
|
|
40
28
|
}
|
|
41
29
|
return result;
|
|
42
|
-
}
|
|
30
|
+
};
|
|
43
31
|
const readResultsAndExit = (result, globalConfig) => {
|
|
44
32
|
const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
|
|
45
|
-
|
|
46
|
-
|
|
33
|
+
|
|
34
|
+
// Only exit if needed
|
|
35
|
+
process.on('exit', () => {
|
|
36
|
+
if (typeof code === 'number' && code !== 0) {
|
|
47
37
|
process.exitCode = code;
|
|
48
38
|
}
|
|
49
39
|
});
|
|
50
40
|
if (globalConfig.forceExit) {
|
|
51
41
|
if (!globalConfig.detectOpenHandles) {
|
|
52
|
-
console.warn(
|
|
53
|
-
`${chalk.bold(
|
|
54
|
-
"Force exiting Jest: "
|
|
55
|
-
)}Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?`
|
|
56
|
-
);
|
|
42
|
+
console.warn(`${chalk.bold('Force exiting Jest: ')}Have you considered using \`--detectOpenHandles\` to detect ` + `async operations that kept running after all tests finished?`);
|
|
57
43
|
}
|
|
44
|
+
|
|
45
|
+
// eslint-disable-next-line no-process-exit
|
|
58
46
|
process.exit(code);
|
|
59
47
|
} else if (!globalConfig.detectOpenHandles) {
|
|
60
48
|
setTimeout(() => {
|
|
61
|
-
console.warn(
|
|
62
|
-
|
|
63
|
-
"Jest did not exit one second after the test run has completed.\n\n"
|
|
64
|
-
) + chalk.yellow(
|
|
65
|
-
"This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue."
|
|
66
|
-
)
|
|
67
|
-
);
|
|
68
|
-
}, 1e3).unref();
|
|
49
|
+
console.warn(chalk.yellow.bold('Jest did not exit one second after the test run has completed.\n\n') + chalk.yellow('This usually means that there are asynchronous operations that ' + "weren't stopped in your tests. Consider running Jest with " + '`--detectOpenHandles` to troubleshoot this issue.'));
|
|
50
|
+
}, 1000).unref();
|
|
69
51
|
}
|
|
70
52
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Node API: execute jest
|
|
56
|
+
*/
|
|
57
|
+
export async function runJest(config, pwd = process.cwd()) {
|
|
58
|
+
try {
|
|
59
|
+
const argvConfig = await buildArgv(process.argv.slice(2), config);
|
|
60
|
+
const {
|
|
61
|
+
results,
|
|
62
|
+
globalConfig
|
|
63
|
+
} = await runCLI(argvConfig, [pwd]);
|
|
64
|
+
readResultsAndExit(results, globalConfig);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.error(chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
|
|
67
|
+
|
|
68
|
+
// eslint-disable-next-line no-process-exit
|
|
69
|
+
process.exit(1);
|
|
70
|
+
}
|
|
82
71
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Node API: run test
|
|
75
|
+
*/
|
|
76
|
+
export async function runTest(api, config, pwd = process.cwd()) {
|
|
77
|
+
process.env.NODE_ENV = 'test';
|
|
78
|
+
const jestUtils = getJestUtils(config);
|
|
79
|
+
await patchConfig(jestUtils);
|
|
80
|
+
|
|
81
|
+
// 确保用户设置的配置可以被插件处理,比如设置在 projects 中
|
|
82
|
+
jestUtils.setJestUserConfig();
|
|
83
|
+
const hookRunners = api.useHookRunners();
|
|
84
|
+
const testConfigOperator = await hookRunners.jestConfig(jestUtils, {
|
|
85
|
+
onLast: input => input
|
|
97
86
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
runJest,
|
|
101
|
-
|
|
102
|
-
}
|
|
87
|
+
const finalConfig = testConfigOperator.getFinalConfig();
|
|
88
|
+
debug('Jest config:', finalConfig);
|
|
89
|
+
await runJest(finalConfig, pwd);
|
|
90
|
+
await hookRunners.afterTest();
|
|
91
|
+
}
|