@modern-js/plugin-testing 0.0.0-next-20221202071629 → 0.0.0-next-20221202125525
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 +7 -8
- package/dist/js/modern/base/config/index.js +29 -9
- package/dist/js/modern/base/config/patches/assetsModule.js +7 -7
- package/dist/js/modern/base/config/patches/filemock.js +4 -1
- package/dist/js/modern/base/config/patches/index.js +30 -7
- package/dist/js/modern/base/config/patches/transformer.js +13 -18
- package/dist/js/modern/base/config/resolver.js +20 -11
- package/dist/js/modern/base/config/testConfigOperator.js +29 -25
- package/dist/js/modern/base/config/transformer/babelTransformer.js +16 -8
- package/dist/js/modern/base/hook.js +10 -5
- package/dist/js/modern/base/index.js +14 -6
- package/dist/js/modern/base/runJest.js +73 -62
- package/dist/js/modern/base/utils.js +40 -25
- package/dist/js/modern/cli/bff/app.js +37 -12
- package/dist/js/modern/cli/bff/constant.js +4 -1
- package/dist/js/modern/cli/bff/index.js +95 -54
- package/dist/js/modern/cli/bff/mockAPI.js +79 -66
- package/dist/js/modern/cli/bff/setup.js +71 -34
- package/dist/js/modern/cli/bff/utils/index.js +31 -17
- package/dist/js/modern/cli/index.js +65 -30
- package/dist/js/modern/cli/test.js +50 -16
- package/dist/js/modern/constant.js +4 -1
- package/dist/js/modern/index.js +3 -3
- package/dist/js/modern/modern-app.env.d.js +0 -0
- package/dist/js/modern/runtime-testing/app.js +25 -16
- package/dist/js/modern/runtime-testing/base.js +7 -3
- package/dist/js/modern/runtime-testing/customRender.js +24 -12
- package/dist/js/modern/runtime-testing/index.js +1 -1
- package/dist/js/modern/runtime-testing/reduck.js +41 -21
- package/dist/js/modern/runtime-testing/request.js +4 -4
- package/dist/js/modern/runtime-testing/resolvePlugins.js +24 -10
- package/dist/js/node/base/config/index.js +56 -18
- package/dist/js/node/base/config/patches/assetsModule.js +30 -12
- package/dist/js/node/base/config/patches/filemock.js +22 -7
- package/dist/js/node/base/config/patches/index.js +50 -15
- package/dist/js/node/base/config/patches/transformer.js +38 -25
- package/dist/js/node/base/config/resolver.js +47 -13
- package/dist/js/node/base/config/testConfigOperator.js +49 -32
- package/dist/js/node/base/config/transformer/babelTransformer.js +40 -15
- package/dist/js/node/base/hook.js +28 -13
- package/dist/js/node/base/index.js +31 -63
- package/dist/js/node/base/runJest.js +99 -71
- package/dist/js/node/base/utils.js +66 -36
- package/dist/js/node/cli/bff/app.js +57 -22
- package/dist/js/node/cli/bff/constant.js +22 -7
- package/dist/js/node/cli/bff/index.js +121 -67
- package/dist/js/node/cli/bff/mockAPI.js +103 -73
- package/dist/js/node/cli/bff/setup.js +100 -38
- package/dist/js/node/cli/bff/utils/index.js +55 -24
- package/dist/js/node/cli/index.js +88 -46
- package/dist/js/node/cli/test.js +76 -25
- package/dist/js/node/constant.js +22 -7
- package/dist/js/node/index.js +19 -18
- package/dist/js/node/modern-app.env.d.js +0 -0
- package/dist/js/node/runtime-testing/app.js +53 -27
- package/dist/js/node/runtime-testing/base.js +30 -33
- package/dist/js/node/runtime-testing/customRender.js +49 -20
- package/dist/js/node/runtime-testing/index.js +18 -27
- package/dist/js/node/runtime-testing/reduck.js +67 -33
- package/dist/js/node/runtime-testing/request.js +32 -13
- package/dist/js/node/runtime-testing/resolvePlugins.js +41 -14
- package/dist/js/treeshaking/base/config/index.js +150 -31
- package/dist/js/treeshaking/base/config/patches/assetsModule.js +9 -11
- package/dist/js/treeshaking/base/config/patches/filemock.js +2 -1
- package/dist/js/treeshaking/base/config/patches/index.js +221 -64
- package/dist/js/treeshaking/base/config/patches/transformer.js +34 -37
- package/dist/js/treeshaking/base/config/resolver.js +36 -13
- package/dist/js/treeshaking/base/config/testConfigOperator.js +120 -69
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +16 -10
- package/dist/js/treeshaking/base/hook.js +8 -7
- package/dist/js/treeshaking/base/index.js +7 -6
- package/dist/js/treeshaking/base/runJest.js +281 -164
- package/dist/js/treeshaking/base/utils.js +72 -48
- package/dist/js/treeshaking/cli/bff/app.js +192 -68
- package/dist/js/treeshaking/cli/bff/constant.js +2 -1
- package/dist/js/treeshaking/cli/bff/index.js +291 -130
- package/dist/js/treeshaking/cli/bff/mockAPI.js +181 -91
- package/dist/js/treeshaking/cli/bff/setup.js +185 -59
- package/dist/js/treeshaking/cli/bff/utils/index.js +47 -21
- package/dist/js/treeshaking/cli/index.js +249 -108
- package/dist/js/treeshaking/cli/test.js +177 -44
- package/dist/js/treeshaking/constant.js +2 -1
- package/dist/js/treeshaking/index.js +3 -3
- package/dist/js/treeshaking/modern-app.env.d.js +0 -0
- package/dist/js/treeshaking/runtime-testing/app.js +85 -39
- package/dist/js/treeshaking/runtime-testing/base.js +4 -3
- package/dist/js/treeshaking/runtime-testing/customRender.js +38 -10
- package/dist/js/treeshaking/runtime-testing/index.js +1 -1
- package/dist/js/treeshaking/runtime-testing/reduck.js +85 -33
- package/dist/js/treeshaking/runtime-testing/request.js +49 -19
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +45 -14
- package/dist/types/base/config/index.d.ts +1 -0
- package/dist/types/base/config/patches/assetsModule.d.ts +1 -0
- package/dist/types/base/config/patches/filemock.d.ts +1 -0
- package/dist/types/base/config/patches/transformer.d.ts +1 -0
- package/dist/types/base/config/testConfigOperator.d.ts +2 -0
- package/dist/types/base/runJest.d.ts +2 -0
- package/dist/types/base/utils.d.ts +1 -0
- package/dist/types/cli/bff/index.d.ts +2 -0
- package/dist/types/cli/bff/mockAPI.d.ts +1 -0
- package/dist/types/cli/index.d.ts +2 -0
- package/dist/types/runtime-testing/app.d.ts +3 -0
- package/dist/types/runtime-testing/customRender.d.ts +2 -0
- package/package.json +13 -13
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-20221202125525
|
|
4
4
|
|
|
5
5
|
### Major Changes
|
|
6
6
|
|
|
@@ -43,19 +43,18 @@
|
|
|
43
43
|
- Updated dependencies [3bbea92b2]
|
|
44
44
|
- Updated dependencies [73cd29dd9]
|
|
45
45
|
- Updated dependencies [b710adb84]
|
|
46
|
-
- Updated dependencies [cce8ecee2]
|
|
47
46
|
- Updated dependencies [18aaf4224]
|
|
48
47
|
- Updated dependencies [f17974937]
|
|
49
48
|
- Updated dependencies [fcace5b5b]
|
|
50
49
|
- Updated dependencies [abf3421a7]
|
|
51
50
|
- Updated dependencies [543be9558]
|
|
52
51
|
- Updated dependencies [14b712da8]
|
|
53
|
-
- @modern-js/runtime@0.0.0-next-
|
|
54
|
-
- @modern-js/prod-server@0.0.0-next-
|
|
55
|
-
- @modern-js/babel-preset-app@0.0.0-next-
|
|
56
|
-
- @modern-js/utils@0.0.0-next-
|
|
57
|
-
- @modern-js/plugin@0.0.0-next-
|
|
58
|
-
- @modern-js/babel-compiler@0.0.0-next-
|
|
52
|
+
- @modern-js/runtime@0.0.0-next-20221202125525
|
|
53
|
+
- @modern-js/prod-server@0.0.0-next-20221202125525
|
|
54
|
+
- @modern-js/babel-preset-app@0.0.0-next-20221202125525
|
|
55
|
+
- @modern-js/utils@0.0.0-next-20221202125525
|
|
56
|
+
- @modern-js/plugin@0.0.0-next-20221202125525
|
|
57
|
+
- @modern-js/babel-compiler@0.0.0-next-20221202125525
|
|
59
58
|
|
|
60
59
|
## 2.0.0-beta.2
|
|
61
60
|
|
|
@@ -1,16 +1,36 @@
|
|
|
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
|
+
};
|
|
1
21
|
import { applyPatches } from "./patches";
|
|
2
22
|
import { TestConfigOperator } from "./testConfigOperator";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Parse jest config
|
|
6
|
-
*/
|
|
7
|
-
const getJestUtils = testConfig => {
|
|
23
|
+
const getJestUtils = (testConfig) => {
|
|
8
24
|
const testOperator = new TestConfigOperator(testConfig);
|
|
9
25
|
return testOperator;
|
|
10
26
|
};
|
|
11
|
-
const patchConfig =
|
|
12
|
-
|
|
27
|
+
const patchConfig = (testOperator) => __async(void 0, null, function* () {
|
|
28
|
+
yield applyPatches(testOperator);
|
|
13
29
|
return testOperator.jestConfig;
|
|
30
|
+
});
|
|
31
|
+
const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
|
32
|
+
export {
|
|
33
|
+
DEFAULT_RESOLVER_PATH,
|
|
34
|
+
getJestUtils,
|
|
35
|
+
patchConfig
|
|
14
36
|
};
|
|
15
|
-
export const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
|
16
|
-
export { getJestUtils, patchConfig };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
* Merge config from testConfig.jest
|
|
3
|
-
*/
|
|
4
|
-
export const patchAssetsModule = testOperator => {
|
|
1
|
+
const patchAssetsModule = (testOperator) => {
|
|
5
2
|
testOperator.mergeJestConfig({
|
|
6
3
|
moduleNameMapper: {
|
|
7
|
-
|
|
8
|
-
|
|
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")
|
|
9
6
|
}
|
|
10
7
|
});
|
|
11
|
-
};
|
|
8
|
+
};
|
|
9
|
+
export {
|
|
10
|
+
patchAssetsModule
|
|
11
|
+
};
|
|
@@ -1,11 +1,34 @@
|
|
|
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
|
+
};
|
|
1
21
|
import { patchTransformer } from "./transformer";
|
|
2
22
|
import { patchAssetsModule } from "./assetsModule";
|
|
3
|
-
const _applyPatches =
|
|
4
|
-
for (const patch of
|
|
5
|
-
|
|
23
|
+
const _applyPatches = (patches2, testOperator) => __async(void 0, null, function* () {
|
|
24
|
+
for (const patch of patches2) {
|
|
25
|
+
yield patch(testOperator);
|
|
6
26
|
}
|
|
7
|
-
};
|
|
27
|
+
});
|
|
8
28
|
const patches = [patchTransformer, patchAssetsModule];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
29
|
+
const applyPatches = (testConfig) => __async(void 0, null, function* () {
|
|
30
|
+
yield _applyPatches(patches, testConfig);
|
|
31
|
+
});
|
|
32
|
+
export {
|
|
33
|
+
applyPatches
|
|
34
|
+
};
|
|
@@ -1,43 +1,38 @@
|
|
|
1
1
|
import { readCompilerOptions } from "../../utils";
|
|
2
2
|
const resolveTsCompilerOptions = () => {
|
|
3
3
|
const tsCompilerOptions = readCompilerOptions() || {};
|
|
4
|
-
const {
|
|
5
|
-
jsx
|
|
6
|
-
} = tsCompilerOptions;
|
|
4
|
+
const { jsx } = tsCompilerOptions;
|
|
7
5
|
if (!jsx) {
|
|
8
6
|
return null;
|
|
9
7
|
}
|
|
10
|
-
tsCompilerOptions.jsx =
|
|
8
|
+
tsCompilerOptions.jsx = "react-jsx";
|
|
11
9
|
return tsCompilerOptions;
|
|
12
10
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*/
|
|
17
|
-
export const patchTransformer = testOperator => {
|
|
18
|
-
const {
|
|
19
|
-
transformer
|
|
20
|
-
} = testOperator.testConfig;
|
|
21
|
-
if (transformer === 'babel-jest') {
|
|
11
|
+
const patchTransformer = (testOperator) => {
|
|
12
|
+
const { transformer } = testOperator.testConfig;
|
|
13
|
+
if (transformer === "babel-jest") {
|
|
22
14
|
testOperator.mergeJestConfig({
|
|
23
15
|
transform: {
|
|
24
|
-
|
|
16
|
+
"\\.[jt]sx?$": require.resolve("../transformer/babelTransformer")
|
|
25
17
|
}
|
|
26
18
|
});
|
|
27
19
|
}
|
|
28
|
-
if (transformer ===
|
|
20
|
+
if (transformer === "ts-jest") {
|
|
29
21
|
testOperator.mergeJestConfig({
|
|
30
22
|
transform: {
|
|
31
|
-
|
|
23
|
+
"\\.[jt]sx?$": require.resolve("ts-jest")
|
|
32
24
|
}
|
|
33
25
|
});
|
|
34
26
|
const compilerOptions = resolveTsCompilerOptions();
|
|
35
27
|
compilerOptions && testOperator.mergeJestConfig({
|
|
36
28
|
globals: {
|
|
37
|
-
|
|
29
|
+
"ts-jest": {
|
|
38
30
|
tsconfig: compilerOptions
|
|
39
31
|
}
|
|
40
32
|
}
|
|
41
33
|
});
|
|
42
34
|
}
|
|
43
|
-
};
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
patchTransformer
|
|
38
|
+
};
|
|
@@ -1,12 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
};
|
|
10
19
|
}
|
|
11
|
-
|
|
12
|
-
|
|
20
|
+
});
|
|
21
|
+
export default require_resolver();
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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";
|
|
7
18
|
class TestConfigOperator {
|
|
8
19
|
constructor(testConfig) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
_defineProperty(this, "defaultTestConfig", {
|
|
13
|
-
transformer: 'babel-jest'
|
|
14
|
-
});
|
|
20
|
+
this.defaultTestConfig = {
|
|
21
|
+
transformer: "babel-jest"
|
|
22
|
+
};
|
|
15
23
|
this._testConfig = testConfig;
|
|
16
24
|
this._jestConfig = {};
|
|
17
25
|
this.userJestConfig = testConfig.jest;
|
|
@@ -30,36 +38,32 @@ class TestConfigOperator {
|
|
|
30
38
|
this._jestConfig = merge({}, this._jestConfig, sourceConfig);
|
|
31
39
|
}
|
|
32
40
|
setJestUserConfig() {
|
|
33
|
-
const {
|
|
34
|
-
|
|
35
|
-
} = this;
|
|
36
|
-
if (typeof userJestConfig === 'object') {
|
|
41
|
+
const { userJestConfig } = this;
|
|
42
|
+
if (typeof userJestConfig === "object") {
|
|
37
43
|
this.setJestConfig(userJestConfig);
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
setJestConfig(sourceConfig, options) {
|
|
41
47
|
if (options) {
|
|
42
|
-
const {
|
|
43
|
-
force
|
|
44
|
-
} = options;
|
|
48
|
+
const { force } = options;
|
|
45
49
|
if (force) {
|
|
46
50
|
this._jestConfig = sourceConfig;
|
|
47
51
|
return;
|
|
48
52
|
}
|
|
49
53
|
}
|
|
50
|
-
this._jestConfig =
|
|
54
|
+
this._jestConfig = __spreadValues(__spreadValues({}, this._jestConfig), sourceConfig);
|
|
51
55
|
}
|
|
52
56
|
getFinalConfig() {
|
|
53
|
-
const {
|
|
54
|
-
userJestConfig
|
|
55
|
-
} = this;
|
|
57
|
+
const { userJestConfig } = this;
|
|
56
58
|
if (!userJestConfig) {
|
|
57
59
|
return this._jestConfig;
|
|
58
60
|
}
|
|
59
|
-
if (typeof userJestConfig ===
|
|
61
|
+
if (typeof userJestConfig === "function") {
|
|
60
62
|
return userJestConfig(this._jestConfig);
|
|
61
63
|
}
|
|
62
64
|
return this.jestConfig;
|
|
63
65
|
}
|
|
64
66
|
}
|
|
65
|
-
export {
|
|
67
|
+
export {
|
|
68
|
+
TestConfigOperator
|
|
69
|
+
};
|
|
@@ -1,11 +1,19 @@
|
|
|
1
|
-
var
|
|
2
|
-
import babelJest from
|
|
3
|
-
const babelTransformer = (
|
|
4
|
-
presets: [
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
],
|
|
8
13
|
configFile: false,
|
|
9
14
|
babelrc: false
|
|
10
15
|
});
|
|
11
|
-
|
|
16
|
+
var babelTransformer_default = babelTransformer;
|
|
17
|
+
export {
|
|
18
|
+
babelTransformer_default as default
|
|
19
|
+
};
|
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import { createAsyncPipeline, createParallelWorkflow } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { createAsyncPipeline, createParallelWorkflow } from "@modern-js/plugin";
|
|
2
|
+
const jestConfigHook = createAsyncPipeline();
|
|
3
|
+
const afterTestHook = createParallelWorkflow();
|
|
4
|
+
const testingHooks = {
|
|
5
5
|
jestConfig: createAsyncPipeline(),
|
|
6
6
|
afterTest: createParallelWorkflow()
|
|
7
|
-
};
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
afterTestHook,
|
|
10
|
+
jestConfigHook,
|
|
11
|
+
testingHooks
|
|
12
|
+
};
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export * from "./types";
|
|
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,24 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
import yargs from "yargs/yargs";
|
|
22
|
+
import { runCLI } from "jest";
|
|
23
|
+
import { chalk } from "@modern-js/utils";
|
|
12
24
|
import { getJestUtils, patchConfig } from "./config";
|
|
13
25
|
import { debug } from "./utils";
|
|
14
|
-
const buildArgv =
|
|
15
|
-
const argv =
|
|
26
|
+
const buildArgv = (rawArgv, config) => __async(void 0, null, function* () {
|
|
27
|
+
const argv = yield yargs(rawArgv).argv;
|
|
16
28
|
const result = {
|
|
17
29
|
$0: argv.$0,
|
|
18
30
|
_: argv._.slice(1)
|
|
19
31
|
};
|
|
20
|
-
Object.keys(argv).forEach(key => {
|
|
21
|
-
if (key.includes(
|
|
32
|
+
Object.keys(argv).forEach((key) => {
|
|
33
|
+
if (key.includes("-") || key === "_") {
|
|
22
34
|
return;
|
|
23
35
|
}
|
|
24
36
|
result[key] = argv[key];
|
|
@@ -27,65 +39,64 @@ const buildArgv = async (rawArgv, config) => {
|
|
|
27
39
|
result.config = JSON.stringify(config);
|
|
28
40
|
}
|
|
29
41
|
return result;
|
|
30
|
-
};
|
|
42
|
+
});
|
|
31
43
|
const readResultsAndExit = (result, globalConfig) => {
|
|
32
44
|
const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
process.on('exit', () => {
|
|
36
|
-
if (typeof code === 'number' && code !== 0) {
|
|
45
|
+
process.on("exit", () => {
|
|
46
|
+
if (typeof code === "number" && code !== 0) {
|
|
37
47
|
process.exitCode = code;
|
|
38
48
|
}
|
|
39
49
|
});
|
|
40
50
|
if (globalConfig.forceExit) {
|
|
41
51
|
if (!globalConfig.detectOpenHandles) {
|
|
42
|
-
console.warn(
|
|
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
|
+
);
|
|
43
57
|
}
|
|
44
|
-
|
|
45
|
-
// eslint-disable-next-line no-process-exit
|
|
46
58
|
process.exit(code);
|
|
47
59
|
} else if (!globalConfig.detectOpenHandles) {
|
|
48
60
|
setTimeout(() => {
|
|
49
|
-
console.warn(
|
|
50
|
-
|
|
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();
|
|
51
69
|
}
|
|
52
70
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
}
|
|
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
|
+
});
|
|
71
82
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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();
|
|
86
97
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
runJest,
|
|
101
|
+
runTest
|
|
102
|
+
};
|
|
@@ -1,19 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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") => {
|
|
14
22
|
let tsConfig = {};
|
|
15
23
|
let extendedCompilerOptions = {};
|
|
16
|
-
let tsconfigFile =
|
|
24
|
+
let tsconfigFile = "";
|
|
17
25
|
try {
|
|
18
26
|
const maybeTsconfigFile = path.join(pwd, filename);
|
|
19
27
|
if (fs.existsSync(maybeTsconfigFile)) {
|
|
@@ -21,23 +29,25 @@ export const readCompilerOptions = (pwd = process.cwd(), filename = 'tsconfig.js
|
|
|
21
29
|
} else {
|
|
22
30
|
tsconfigFile = require.resolve(filename);
|
|
23
31
|
}
|
|
24
|
-
({
|
|
25
|
-
|
|
26
|
-
|
|
32
|
+
({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(
|
|
33
|
+
tsconfigFile,
|
|
34
|
+
fs.readFileSync(tsconfigFile, "utf8")
|
|
35
|
+
));
|
|
27
36
|
} catch (e) {
|
|
28
37
|
return {};
|
|
29
38
|
}
|
|
30
39
|
if (tsConfig.extends) {
|
|
31
|
-
extendedCompilerOptions = readCompilerOptions(
|
|
40
|
+
extendedCompilerOptions = readCompilerOptions(
|
|
41
|
+
path.dirname(tsconfigFile),
|
|
42
|
+
tsConfig.extends
|
|
43
|
+
);
|
|
32
44
|
}
|
|
33
|
-
return
|
|
45
|
+
return __spreadValues(__spreadValues({}, extendedCompilerOptions), tsConfig.compilerOptions);
|
|
34
46
|
};
|
|
35
|
-
|
|
47
|
+
const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
|
|
36
48
|
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
|
|
37
|
-
const isFile = aliasValue.some(s => s.endsWith(
|
|
38
|
-
|
|
39
|
-
// It's special for if using @modern-js/runtime alias other module @modern-js/runtime/model would not work.
|
|
40
|
-
if (cur === '@modern-js/runtime$') {
|
|
49
|
+
const isFile = aliasValue.some((s) => s.endsWith(".js"));
|
|
50
|
+
if (cur === "@modern-js/runtime$") {
|
|
41
51
|
memo[`.+${cur}`] = aliasValue[0];
|
|
42
52
|
return memo;
|
|
43
53
|
}
|
|
@@ -48,4 +58,9 @@ export const getModuleNameMapper = alias => Object.keys(alias).reduce((memo, cur
|
|
|
48
58
|
const value = path.normalize(`${aliasValue}/$1`);
|
|
49
59
|
memo[key] = value;
|
|
50
60
|
return memo;
|
|
51
|
-
}, {});
|
|
61
|
+
}, {});
|
|
62
|
+
export {
|
|
63
|
+
debug,
|
|
64
|
+
getModuleNameMapper,
|
|
65
|
+
readCompilerOptions
|
|
66
|
+
};
|