@modern-js/plugin-testing 2.21.2-alpha.0 → 2.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/package.json +16 -13
- package/dist/js/modern/base/config/index.js +0 -36
- package/dist/js/modern/base/config/patches/assetsModule.js +0 -11
- package/dist/js/modern/base/config/patches/filemock.js +0 -4
- package/dist/js/modern/base/config/patches/index.js +0 -34
- package/dist/js/modern/base/config/patches/transformer.js +0 -38
- package/dist/js/modern/base/config/resolver.js +0 -21
- package/dist/js/modern/base/config/testConfigOperator.js +0 -69
- package/dist/js/modern/base/config/transformer/babelTransformer.js +0 -19
- package/dist/js/modern/base/hook.js +0 -12
- package/dist/js/modern/base/index.js +0 -14
- package/dist/js/modern/base/runJest.js +0 -102
- package/dist/js/modern/base/types/index.js +0 -0
- package/dist/js/modern/base/utils.js +0 -66
- package/dist/js/modern/cli/bff/app.js +0 -58
- package/dist/js/modern/cli/bff/constant.js +0 -4
- package/dist/js/modern/cli/bff/index.js +0 -149
- package/dist/js/modern/cli/bff/mockAPI.js +0 -109
- package/dist/js/modern/cli/bff/setup.js +0 -75
- package/dist/js/modern/cli/bff/utils/index.js +0 -37
- package/dist/js/modern/cli/index.js +0 -115
- package/dist/js/modern/cli/test.js +0 -61
- package/dist/js/modern/constant.js +0 -4
- package/dist/js/modern/index.js +0 -3
- package/dist/js/modern/runtime-testing/app.js +0 -48
- package/dist/js/modern/runtime-testing/base.js +0 -7
- package/dist/js/modern/runtime-testing/customRender.js +0 -25
- package/dist/js/modern/runtime-testing/index.js +0 -2
- package/dist/js/modern/runtime-testing/reduck.js +0 -55
- package/dist/js/modern/runtime-testing/request.js +0 -16
- package/dist/js/modern/runtime-testing/resolvePlugins.js +0 -33
- package/dist/js/node/base/config/index.js +0 -67
- package/dist/js/node/base/config/patches/assetsModule.js +0 -40
- package/dist/js/node/base/config/patches/filemock.js +0 -25
- package/dist/js/node/base/config/patches/index.js +0 -57
- package/dist/js/node/base/config/patches/transformer.js +0 -67
- package/dist/js/node/base/config/resolver.js +0 -30
- package/dist/js/node/base/config/testConfigOperator.js +0 -90
- package/dist/js/node/base/config/transformer/babelTransformer.js +0 -46
- package/dist/js/node/base/hook.js +0 -37
- package/dist/js/node/base/index.js +0 -43
- package/dist/js/node/base/runJest.js +0 -132
- package/dist/js/node/base/types/index.js +0 -15
- package/dist/js/node/base/utils.js +0 -95
- package/dist/js/node/cli/bff/app.js +0 -84
- package/dist/js/node/cli/bff/constant.js +0 -27
- package/dist/js/node/cli/bff/index.js +0 -173
- package/dist/js/node/cli/bff/mockAPI.js +0 -134
- package/dist/js/node/cli/bff/setup.js +0 -84
- package/dist/js/node/cli/bff/utils/index.js +0 -64
- package/dist/js/node/cli/index.js +0 -135
- package/dist/js/node/cli/test.js +0 -88
- package/dist/js/node/constant.js +0 -27
- package/dist/js/node/index.js +0 -19
- package/dist/js/node/runtime-testing/app.js +0 -73
- package/dist/js/node/runtime-testing/base.js +0 -38
- package/dist/js/node/runtime-testing/customRender.js +0 -50
- package/dist/js/node/runtime-testing/index.js +0 -18
- package/dist/js/node/runtime-testing/reduck.js +0 -85
- package/dist/js/node/runtime-testing/request.js +0 -45
- package/dist/js/node/runtime-testing/resolvePlugins.js +0 -52
- package/dist/js/treeshaking/base/config/index.js +0 -154
- package/dist/js/treeshaking/base/config/patches/assetsModule.js +0 -9
- package/dist/js/treeshaking/base/config/patches/filemock.js +0 -2
- package/dist/js/treeshaking/base/config/patches/index.js +0 -225
- package/dist/js/treeshaking/base/config/patches/transformer.js +0 -36
- package/dist/js/treeshaking/base/config/resolver.js +0 -37
- package/dist/js/treeshaking/base/config/testConfigOperator.js +0 -127
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +0 -17
- package/dist/js/treeshaking/base/hook.js +0 -8
- package/dist/js/treeshaking/base/index.js +0 -7
- package/dist/js/treeshaking/base/runJest.js +0 -292
- package/dist/js/treeshaking/base/types/index.js +0 -1
- package/dist/js/treeshaking/base/utils.js +0 -76
- package/dist/js/treeshaking/cli/bff/app.js +0 -200
- package/dist/js/treeshaking/cli/bff/constant.js +0 -2
- package/dist/js/treeshaking/cli/bff/index.js +0 -297
- package/dist/js/treeshaking/cli/bff/mockAPI.js +0 -188
- package/dist/js/treeshaking/cli/bff/setup.js +0 -192
- package/dist/js/treeshaking/cli/bff/utils/index.js +0 -47
- package/dist/js/treeshaking/cli/index.js +0 -255
- package/dist/js/treeshaking/cli/test.js +0 -180
- package/dist/js/treeshaking/constant.js +0 -2
- package/dist/js/treeshaking/index.js +0 -3
- package/dist/js/treeshaking/runtime-testing/app.js +0 -90
- package/dist/js/treeshaking/runtime-testing/base.js +0 -4
- package/dist/js/treeshaking/runtime-testing/customRender.js +0 -41
- package/dist/js/treeshaking/runtime-testing/index.js +0 -2
- package/dist/js/treeshaking/runtime-testing/reduck.js +0 -89
- package/dist/js/treeshaking/runtime-testing/request.js +0 -51
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +0 -46
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# @modern-js/plugin-testing
|
|
2
2
|
|
|
3
|
+
## 2.22.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3d48836: chore(deps): fix all missing peer dependencies
|
|
8
|
+
|
|
9
|
+
chore(deps): 修复缺少的 peer dependencies
|
|
10
|
+
|
|
11
|
+
- 8f1141c: fix: refactor the mock logic of BFF testing plugin
|
|
12
|
+
fix: 修改 BFF 测试插件的 mock 逻辑
|
|
13
|
+
- Updated dependencies [3d48836]
|
|
14
|
+
- Updated dependencies [63cdea1]
|
|
15
|
+
- Updated dependencies [8f1141c]
|
|
16
|
+
- Updated dependencies [5050e8e]
|
|
17
|
+
- Updated dependencies [4991c8a]
|
|
18
|
+
- Updated dependencies [cb9e1ec]
|
|
19
|
+
- Updated dependencies [dc45896]
|
|
20
|
+
- Updated dependencies [79180c2]
|
|
21
|
+
- Updated dependencies [c271c5d]
|
|
22
|
+
- Updated dependencies [ea961e7]
|
|
23
|
+
- @modern-js/runtime@2.22.0
|
|
24
|
+
- @modern-js/utils@2.22.0
|
|
25
|
+
- @modern-js/prod-server@2.22.0
|
|
26
|
+
- @modern-js/babel-preset-app@2.22.0
|
|
27
|
+
- @modern-js/babel-compiler@2.22.0
|
|
28
|
+
- @modern-js/plugin@2.22.0
|
|
29
|
+
|
|
3
30
|
## 2.21.1
|
|
4
31
|
|
|
5
32
|
### Patch Changes
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.22.0",
|
|
19
19
|
"jsnext:source": "./src/cli/index.ts",
|
|
20
20
|
"types": "./dist/types/cli/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/cli/index.js",
|
|
@@ -102,6 +102,9 @@
|
|
|
102
102
|
],
|
|
103
103
|
"base": [
|
|
104
104
|
"./dist/types/base/index.d.ts"
|
|
105
|
+
],
|
|
106
|
+
"bff": [
|
|
107
|
+
"./dist/types/runtime-testing/bff.d.ts"
|
|
105
108
|
]
|
|
106
109
|
}
|
|
107
110
|
},
|
|
@@ -126,16 +129,16 @@
|
|
|
126
129
|
"ts-jest": "^29.1.0",
|
|
127
130
|
"yargs": "^17.0.1",
|
|
128
131
|
"@swc/helpers": "0.5.1",
|
|
129
|
-
"@modern-js/babel-compiler": "2.
|
|
130
|
-
"@modern-js/
|
|
131
|
-
"@modern-js/
|
|
132
|
-
"@modern-js/
|
|
133
|
-
"@modern-js/
|
|
132
|
+
"@modern-js/babel-compiler": "2.22.0",
|
|
133
|
+
"@modern-js/utils": "2.22.0",
|
|
134
|
+
"@modern-js/babel-preset-app": "2.22.0",
|
|
135
|
+
"@modern-js/plugin": "2.22.0",
|
|
136
|
+
"@modern-js/prod-server": "2.22.0"
|
|
134
137
|
},
|
|
135
138
|
"peerDependencies": {
|
|
136
139
|
"react": ">=17",
|
|
137
140
|
"react-dom": ">=17",
|
|
138
|
-
"@modern-js/runtime": "^2.
|
|
141
|
+
"@modern-js/runtime": "^2.22.0"
|
|
139
142
|
},
|
|
140
143
|
"peerDependenciesMeta": {
|
|
141
144
|
"@modern-js/runtime": {
|
|
@@ -150,12 +153,12 @@
|
|
|
150
153
|
"@types/node": "^14",
|
|
151
154
|
"@types/yargs": "^17.0.2",
|
|
152
155
|
"typescript": "^5",
|
|
153
|
-
"@modern-js/core": "2.
|
|
154
|
-
"@modern-js/
|
|
155
|
-
"@modern-js/
|
|
156
|
-
"@
|
|
157
|
-
"@
|
|
158
|
-
"@scripts/jest-config": "2.
|
|
156
|
+
"@modern-js/core": "2.22.0",
|
|
157
|
+
"@modern-js/types": "2.22.0",
|
|
158
|
+
"@modern-js/runtime": "2.22.0",
|
|
159
|
+
"@modern-js/bff-core": "2.22.0",
|
|
160
|
+
"@scripts/build": "2.22.0",
|
|
161
|
+
"@scripts/jest-config": "2.22.0"
|
|
159
162
|
},
|
|
160
163
|
"sideEffects": false,
|
|
161
164
|
"modernConfig": {},
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
import { applyPatches } from "./patches";
|
|
22
|
-
import { TestConfigOperator } from "./testConfigOperator";
|
|
23
|
-
const getJestUtils = (testConfig) => {
|
|
24
|
-
const testOperator = new TestConfigOperator(testConfig);
|
|
25
|
-
return testOperator;
|
|
26
|
-
};
|
|
27
|
-
const patchConfig = (testOperator) => __async(void 0, null, function* () {
|
|
28
|
-
yield applyPatches(testOperator);
|
|
29
|
-
return testOperator.jestConfig;
|
|
30
|
-
});
|
|
31
|
-
const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
|
32
|
-
export {
|
|
33
|
-
DEFAULT_RESOLVER_PATH,
|
|
34
|
-
getJestUtils,
|
|
35
|
-
patchConfig
|
|
36
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const patchAssetsModule = (testOperator) => {
|
|
2
|
-
testOperator.mergeJestConfig({
|
|
3
|
-
moduleNameMapper: {
|
|
4
|
-
"\\.(css|less|scss|sass)$": require.resolve("identity-obj-proxy"),
|
|
5
|
-
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": require.resolve("./filemock.js")
|
|
6
|
-
}
|
|
7
|
-
});
|
|
8
|
-
};
|
|
9
|
-
export {
|
|
10
|
-
patchAssetsModule
|
|
11
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
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
|
-
import { patchTransformer } from "./transformer";
|
|
22
|
-
import { patchAssetsModule } from "./assetsModule";
|
|
23
|
-
const _applyPatches = (patches2, testOperator) => __async(void 0, null, function* () {
|
|
24
|
-
for (const patch of patches2) {
|
|
25
|
-
yield patch(testOperator);
|
|
26
|
-
}
|
|
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
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { readCompilerOptions } from "../../utils";
|
|
2
|
-
const resolveTsCompilerOptions = () => {
|
|
3
|
-
const tsCompilerOptions = readCompilerOptions() || {};
|
|
4
|
-
const { jsx } = tsCompilerOptions;
|
|
5
|
-
if (!jsx) {
|
|
6
|
-
return null;
|
|
7
|
-
}
|
|
8
|
-
tsCompilerOptions.jsx = "react-jsx";
|
|
9
|
-
return tsCompilerOptions;
|
|
10
|
-
};
|
|
11
|
-
const patchTransformer = (testOperator) => {
|
|
12
|
-
const { transformer } = testOperator.testConfig;
|
|
13
|
-
if (transformer === "babel-jest") {
|
|
14
|
-
testOperator.mergeJestConfig({
|
|
15
|
-
transform: {
|
|
16
|
-
"\\.[jt]sx?$": require.resolve("../transformer/babelTransformer")
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
if (transformer === "ts-jest") {
|
|
21
|
-
testOperator.mergeJestConfig({
|
|
22
|
-
transform: {
|
|
23
|
-
"\\.[jt]sx?$": require.resolve("ts-jest")
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
const compilerOptions = resolveTsCompilerOptions();
|
|
27
|
-
compilerOptions && testOperator.mergeJestConfig({
|
|
28
|
-
globals: {
|
|
29
|
-
"ts-jest": {
|
|
30
|
-
tsconfig: compilerOptions
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
export {
|
|
37
|
-
patchTransformer
|
|
38
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
-
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
-
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
-
};
|
|
5
|
-
import enhanceResolve from "enhanced-resolve";
|
|
6
|
-
var require_resolver = __commonJS({
|
|
7
|
-
"src/base/config/resolver.ts"(exports, module) {
|
|
8
|
-
const resolver = enhanceResolve.create.sync({
|
|
9
|
-
conditionNames: ["require", "node", "default"],
|
|
10
|
-
extensions: [".js", ".json", ".node", ".ts", ".tsx"]
|
|
11
|
-
});
|
|
12
|
-
const shouldResolveByEnhance = (url) => /^@[^/]+\/[^/]+\/.*/.test(url);
|
|
13
|
-
module.exports = function(request, options) {
|
|
14
|
-
if (shouldResolveByEnhance(request)) {
|
|
15
|
-
return resolver(options.basedir, request);
|
|
16
|
-
}
|
|
17
|
-
return options.defaultResolver(request, options);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
export default require_resolver();
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
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";
|
|
18
|
-
class TestConfigOperator {
|
|
19
|
-
constructor(testConfig) {
|
|
20
|
-
this.defaultTestConfig = {
|
|
21
|
-
transformer: "babel-jest"
|
|
22
|
-
};
|
|
23
|
-
this._testConfig = testConfig;
|
|
24
|
-
this._jestConfig = {};
|
|
25
|
-
this.userJestConfig = testConfig.jest;
|
|
26
|
-
this.initial();
|
|
27
|
-
}
|
|
28
|
-
initial() {
|
|
29
|
-
this._testConfig = merge({}, this.defaultTestConfig, this.testConfig);
|
|
30
|
-
}
|
|
31
|
-
get jestConfig() {
|
|
32
|
-
return this._jestConfig;
|
|
33
|
-
}
|
|
34
|
-
get testConfig() {
|
|
35
|
-
return this._testConfig;
|
|
36
|
-
}
|
|
37
|
-
mergeJestConfig(sourceConfig) {
|
|
38
|
-
this._jestConfig = merge({}, this._jestConfig, sourceConfig);
|
|
39
|
-
}
|
|
40
|
-
setJestUserConfig() {
|
|
41
|
-
const { userJestConfig } = this;
|
|
42
|
-
if (typeof userJestConfig === "object") {
|
|
43
|
-
this.setJestConfig(userJestConfig);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
setJestConfig(sourceConfig, options) {
|
|
47
|
-
if (options) {
|
|
48
|
-
const { force } = options;
|
|
49
|
-
if (force) {
|
|
50
|
-
this._jestConfig = sourceConfig;
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
this._jestConfig = __spreadValues(__spreadValues({}, this._jestConfig), sourceConfig);
|
|
55
|
-
}
|
|
56
|
-
getFinalConfig() {
|
|
57
|
-
const { userJestConfig } = this;
|
|
58
|
-
if (!userJestConfig) {
|
|
59
|
-
return this._jestConfig;
|
|
60
|
-
}
|
|
61
|
-
if (typeof userJestConfig === "function") {
|
|
62
|
-
return userJestConfig(this._jestConfig);
|
|
63
|
-
}
|
|
64
|
-
return this.jestConfig;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
export {
|
|
68
|
-
TestConfigOperator
|
|
69
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
var _a, _b;
|
|
2
|
-
import babelJest from "babel-jest";
|
|
3
|
-
const babelTransformer = (_b = (_a = babelJest).createTransformer) == null ? void 0 : _b.call(_a, {
|
|
4
|
-
presets: [
|
|
5
|
-
[
|
|
6
|
-
require.resolve("@modern-js/babel-preset-app"),
|
|
7
|
-
{
|
|
8
|
-
appDirectory: process.cwd(),
|
|
9
|
-
modules: "cjs"
|
|
10
|
-
}
|
|
11
|
-
]
|
|
12
|
-
],
|
|
13
|
-
configFile: false,
|
|
14
|
-
babelrc: false
|
|
15
|
-
});
|
|
16
|
-
var babelTransformer_default = babelTransformer;
|
|
17
|
-
export {
|
|
18
|
-
babelTransformer_default as default
|
|
19
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { createAsyncPipeline, createParallelWorkflow } from "@modern-js/plugin";
|
|
2
|
-
const jestConfigHook = createAsyncPipeline();
|
|
3
|
-
const afterTestHook = createParallelWorkflow();
|
|
4
|
-
const testingHooks = {
|
|
5
|
-
jestConfig: createAsyncPipeline(),
|
|
6
|
-
afterTest: createParallelWorkflow()
|
|
7
|
-
};
|
|
8
|
-
export {
|
|
9
|
-
afterTestHook,
|
|
10
|
-
jestConfigHook,
|
|
11
|
-
testingHooks
|
|
12
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { runTest, runJest } from "./runJest";
|
|
2
|
-
import { getModuleNameMapper } from "./utils";
|
|
3
|
-
import { DEFAULT_RESOLVER_PATH } from "./config";
|
|
4
|
-
import { TestConfigOperator } from "./config/testConfigOperator";
|
|
5
|
-
import { testingHooks } from "./hook";
|
|
6
|
-
export * from "./types";
|
|
7
|
-
export {
|
|
8
|
-
DEFAULT_RESOLVER_PATH,
|
|
9
|
-
TestConfigOperator,
|
|
10
|
-
getModuleNameMapper,
|
|
11
|
-
runJest,
|
|
12
|
-
runTest,
|
|
13
|
-
testingHooks
|
|
14
|
-
};
|
|
@@ -1,102 +0,0 @@
|
|
|
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
|
-
import yargs from "yargs/yargs";
|
|
22
|
-
import { runCLI } from "jest";
|
|
23
|
-
import { chalk } from "@modern-js/utils";
|
|
24
|
-
import { getJestUtils, patchConfig } from "./config";
|
|
25
|
-
import { debug } from "./utils";
|
|
26
|
-
const buildArgv = (rawArgv, config) => __async(void 0, null, function* () {
|
|
27
|
-
const argv = yield yargs(rawArgv).argv;
|
|
28
|
-
const result = {
|
|
29
|
-
$0: argv.$0,
|
|
30
|
-
_: argv._.slice(1)
|
|
31
|
-
};
|
|
32
|
-
Object.keys(argv).forEach((key) => {
|
|
33
|
-
if (key.includes("-") || key === "_") {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
result[key] = argv[key];
|
|
37
|
-
});
|
|
38
|
-
if (config) {
|
|
39
|
-
result.config = JSON.stringify(config);
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
});
|
|
43
|
-
const readResultsAndExit = (result, globalConfig) => {
|
|
44
|
-
const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
|
|
45
|
-
process.on("exit", () => {
|
|
46
|
-
if (typeof code === "number" && code !== 0) {
|
|
47
|
-
process.exitCode = code;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
if (globalConfig.forceExit) {
|
|
51
|
-
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
|
-
);
|
|
57
|
-
}
|
|
58
|
-
process.exit(code);
|
|
59
|
-
} else if (!globalConfig.detectOpenHandles) {
|
|
60
|
-
setTimeout(() => {
|
|
61
|
-
console.warn(
|
|
62
|
-
chalk.yellow.bold(
|
|
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();
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
function runJest(_0) {
|
|
72
|
-
return __async(this, arguments, function* (config, pwd = process.cwd()) {
|
|
73
|
-
try {
|
|
74
|
-
const argvConfig = yield buildArgv(process.argv.slice(2), config);
|
|
75
|
-
const { results, globalConfig } = yield runCLI(argvConfig, [pwd]);
|
|
76
|
-
readResultsAndExit(results, globalConfig);
|
|
77
|
-
} catch (e) {
|
|
78
|
-
console.error(chalk.red((e == null ? void 0 : e.stack) || e));
|
|
79
|
-
process.exit(1);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
function runTest(_0, _1) {
|
|
84
|
-
return __async(this, arguments, function* (api, config, pwd = process.cwd()) {
|
|
85
|
-
process.env.NODE_ENV = "test";
|
|
86
|
-
const jestUtils = getJestUtils(config);
|
|
87
|
-
yield patchConfig(jestUtils);
|
|
88
|
-
jestUtils.setJestUserConfig();
|
|
89
|
-
const hookRunners = api.useHookRunners();
|
|
90
|
-
const testConfigOperator = yield hookRunners.jestConfig(jestUtils, {
|
|
91
|
-
onLast: (input) => input
|
|
92
|
-
});
|
|
93
|
-
const finalConfig = testConfigOperator.getFinalConfig();
|
|
94
|
-
debug("Jest config:", finalConfig);
|
|
95
|
-
yield runJest(finalConfig, pwd);
|
|
96
|
-
yield hookRunners.afterTest();
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
export {
|
|
100
|
-
runJest,
|
|
101
|
-
runTest
|
|
102
|
-
};
|
|
File without changes
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
5
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
-
var __spreadValues = (a, b) => {
|
|
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 fs from "fs";
|
|
18
|
-
import path from "path";
|
|
19
|
-
import { createDebugger } from "@modern-js/utils";
|
|
20
|
-
const debug = createDebugger("test");
|
|
21
|
-
const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
|
|
22
|
-
let tsConfig = {};
|
|
23
|
-
let extendedCompilerOptions = {};
|
|
24
|
-
let tsconfigFile = "";
|
|
25
|
-
try {
|
|
26
|
-
const maybeTsconfigFile = path.join(pwd, filename);
|
|
27
|
-
if (fs.existsSync(maybeTsconfigFile)) {
|
|
28
|
-
tsconfigFile = maybeTsconfigFile;
|
|
29
|
-
} else {
|
|
30
|
-
tsconfigFile = require.resolve(filename);
|
|
31
|
-
}
|
|
32
|
-
({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(
|
|
33
|
-
tsconfigFile,
|
|
34
|
-
fs.readFileSync(tsconfigFile, "utf8")
|
|
35
|
-
));
|
|
36
|
-
} catch (e) {
|
|
37
|
-
return {};
|
|
38
|
-
}
|
|
39
|
-
if (tsConfig.extends) {
|
|
40
|
-
extendedCompilerOptions = readCompilerOptions(
|
|
41
|
-
path.dirname(tsconfigFile),
|
|
42
|
-
tsConfig.extends
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
return __spreadValues(__spreadValues({}, extendedCompilerOptions), tsConfig.compilerOptions);
|
|
46
|
-
};
|
|
47
|
-
const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
|
|
48
|
-
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
|
|
49
|
-
const isFile = aliasValue.some((s) => s.endsWith(".js"));
|
|
50
|
-
if (cur === "@modern-js/runtime$") {
|
|
51
|
-
memo[`.+${cur}`] = aliasValue[0];
|
|
52
|
-
return memo;
|
|
53
|
-
}
|
|
54
|
-
if (isFile) {
|
|
55
|
-
memo[cur] = aliasValue[0];
|
|
56
|
-
}
|
|
57
|
-
const key = `^${cur}/(.*)$`;
|
|
58
|
-
const value = path.normalize(`${aliasValue}/$1`);
|
|
59
|
-
memo[key] = value;
|
|
60
|
-
return memo;
|
|
61
|
-
}, {});
|
|
62
|
-
export {
|
|
63
|
-
debug,
|
|
64
|
-
getModuleNameMapper,
|
|
65
|
-
readCompilerOptions
|
|
66
|
-
};
|
|
@@ -1,58 +0,0 @@
|
|
|
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
|
-
import { AsyncLocalStorage } from "async_hooks";
|
|
22
|
-
import { Server } from "@modern-js/prod-server";
|
|
23
|
-
const store = new AsyncLocalStorage();
|
|
24
|
-
const isInHandler = () => Boolean(store.getStore());
|
|
25
|
-
let server = null;
|
|
26
|
-
const createApp = (pwd, config, plugins, routes) => __async(void 0, null, function* () {
|
|
27
|
-
if (!server) {
|
|
28
|
-
config.output.path = "./";
|
|
29
|
-
server = new Server({
|
|
30
|
-
apiOnly: true,
|
|
31
|
-
pwd,
|
|
32
|
-
config,
|
|
33
|
-
internalPlugins: plugins,
|
|
34
|
-
routes
|
|
35
|
-
});
|
|
36
|
-
yield server.init();
|
|
37
|
-
}
|
|
38
|
-
const app = server.getRequestHandler();
|
|
39
|
-
return app;
|
|
40
|
-
});
|
|
41
|
-
const getApp = () => {
|
|
42
|
-
if (!server) {
|
|
43
|
-
throw new Error("please createApp first");
|
|
44
|
-
}
|
|
45
|
-
return server.getRequestHandler();
|
|
46
|
-
};
|
|
47
|
-
const closeServer = () => __async(void 0, null, function* () {
|
|
48
|
-
if (!server) {
|
|
49
|
-
throw new Error("please createApp first");
|
|
50
|
-
}
|
|
51
|
-
yield server.close();
|
|
52
|
-
});
|
|
53
|
-
export {
|
|
54
|
-
closeServer,
|
|
55
|
-
createApp,
|
|
56
|
-
getApp,
|
|
57
|
-
isInHandler
|
|
58
|
-
};
|