@modern-js/plugin-testing 2.4.1-beta.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +21 -6
- package/dist/{js/node → cjs}/base/config/index.js +3 -23
- package/dist/{js/node → cjs}/base/config/patches/assetsModule.js +0 -0
- package/dist/{js/node → cjs}/base/config/patches/filemock.js +0 -0
- package/dist/{js/node → cjs}/base/config/patches/index.js +6 -26
- package/dist/{js/node → cjs}/base/config/patches/transformer.js +0 -0
- package/dist/{js/node → cjs}/base/config/resolver.js +0 -0
- package/dist/{js/node → cjs}/base/config/testConfigOperator.js +1 -15
- package/dist/{js/node → cjs}/base/config/transformer/babelTransformer.js +0 -0
- package/dist/{js/node → cjs}/base/hook.js +0 -0
- package/dist/{js/node → cjs}/base/index.js +0 -0
- package/dist/{js/node → cjs}/base/runJest.js +24 -48
- package/dist/{js/node → cjs}/base/types/index.js +0 -0
- package/dist/{js/node → cjs}/base/utils.js +4 -15
- package/dist/{js/node → cjs}/cli/bff/app.js +6 -26
- package/dist/{js/node → cjs}/cli/bff/constant.js +0 -0
- package/dist/{js/node → cjs}/cli/bff/index.js +22 -49
- package/dist/{js/node → cjs}/cli/bff/mockAPI.js +5 -16
- package/dist/{js/node → cjs}/cli/bff/setup.js +6 -26
- package/dist/{js/node → cjs}/cli/bff/utils/index.js +1 -15
- package/dist/{js/node → cjs}/cli/index.js +6 -26
- package/dist/{js/node → cjs}/cli/test.js +4 -24
- package/dist/{js/node → cjs}/constant.js +0 -0
- package/dist/{js/node → cjs}/index.js +0 -0
- package/dist/{js/node → cjs}/runtime-testing/app.js +4 -15
- package/dist/{js/node → cjs}/runtime-testing/base.js +0 -0
- package/dist/{js/node → cjs}/runtime-testing/customRender.js +1 -15
- package/dist/{js/node → cjs}/runtime-testing/index.js +0 -0
- package/dist/{js/node → cjs}/runtime-testing/reduck.js +3 -19
- package/dist/{js/node → cjs}/runtime-testing/request.js +0 -0
- package/dist/{js/node → cjs}/runtime-testing/resolvePlugins.js +3 -15
- package/dist/{js/treeshaking → esm}/base/config/index.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/patches/assetsModule.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/patches/filemock.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/patches/index.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/patches/transformer.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/resolver.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/testConfigOperator.js +0 -0
- package/dist/{js/treeshaking → esm}/base/config/transformer/babelTransformer.js +0 -0
- package/dist/{js/treeshaking → esm}/base/hook.js +0 -0
- package/dist/{js/treeshaking → esm}/base/index.js +0 -0
- package/dist/{js/treeshaking → esm}/base/runJest.js +0 -0
- package/dist/{js/treeshaking → esm}/base/types/index.js +0 -0
- package/dist/{js/treeshaking → esm}/base/utils.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/app.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/constant.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/index.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/mockAPI.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/setup.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/bff/utils/index.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/index.js +0 -0
- package/dist/{js/treeshaking → esm}/cli/test.js +0 -0
- package/dist/{js/treeshaking → esm}/constant.js +0 -0
- package/dist/{js/treeshaking → esm}/index.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/app.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/base.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/customRender.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/index.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/reduck.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/request.js +0 -0
- package/dist/{js/treeshaking → esm}/runtime-testing/resolvePlugins.js +0 -0
- package/dist/esm-node/base/config/index.js +16 -0
- package/dist/{js/modern → esm-node}/base/config/patches/assetsModule.js +0 -0
- package/dist/{js/modern → esm-node}/base/config/patches/filemock.js +0 -0
- package/dist/esm-node/base/config/patches/index.js +14 -0
- package/dist/{js/modern → esm-node}/base/config/patches/transformer.js +0 -0
- package/dist/{js/modern → esm-node}/base/config/resolver.js +0 -0
- package/dist/{js/modern → esm-node}/base/config/testConfigOperator.js +1 -17
- package/dist/{js/modern → esm-node}/base/config/transformer/babelTransformer.js +0 -0
- package/dist/{js/modern → esm-node}/base/hook.js +0 -0
- package/dist/{js/modern → esm-node}/base/index.js +0 -0
- package/dist/esm-node/base/runJest.js +78 -0
- package/dist/{js/modern → esm-node}/base/types/index.js +0 -0
- package/dist/{js/modern → esm-node}/base/utils.js +4 -17
- package/dist/esm-node/cli/bff/app.js +38 -0
- package/dist/{js/modern → esm-node}/cli/bff/constant.js +0 -0
- package/dist/{js/modern → esm-node}/cli/bff/index.js +22 -51
- package/dist/{js/modern → esm-node}/cli/bff/mockAPI.js +5 -18
- package/dist/esm-node/cli/bff/setup.js +46 -0
- package/dist/esm-node/cli/bff/utils/index.js +21 -0
- package/dist/{js/modern → esm-node}/cli/index.js +6 -26
- package/dist/{js/modern → esm-node}/cli/test.js +4 -24
- package/dist/{js/modern → esm-node}/constant.js +0 -0
- package/dist/{js/modern → esm-node}/index.js +0 -0
- package/dist/esm-node/runtime-testing/app.js +35 -0
- package/dist/{js/modern → esm-node}/runtime-testing/base.js +0 -0
- package/dist/esm-node/runtime-testing/customRender.js +9 -0
- package/dist/{js/modern → esm-node}/runtime-testing/index.js +0 -0
- package/dist/{js/modern → esm-node}/runtime-testing/reduck.js +3 -21
- package/dist/{js/modern → esm-node}/runtime-testing/request.js +0 -0
- package/dist/esm-node/runtime-testing/resolvePlugins.js +19 -0
- package/package.json +25 -26
- package/dist/js/modern/base/config/index.js +0 -36
- package/dist/js/modern/base/config/patches/index.js +0 -34
- package/dist/js/modern/base/runJest.js +0 -102
- package/dist/js/modern/cli/bff/app.js +0 -58
- 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/runtime-testing/app.js +0 -48
- package/dist/js/modern/runtime-testing/customRender.js +0 -25
- package/dist/js/modern/runtime-testing/resolvePlugins.js +0 -33
@@ -21,26 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
21
21
|
mod
|
22
22
|
));
|
23
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
24
|
-
var __async = (__this, __arguments, generator) => {
|
25
|
-
return new Promise((resolve, reject) => {
|
26
|
-
var fulfilled = (value) => {
|
27
|
-
try {
|
28
|
-
step(generator.next(value));
|
29
|
-
} catch (e) {
|
30
|
-
reject(e);
|
31
|
-
}
|
32
|
-
};
|
33
|
-
var rejected = (value) => {
|
34
|
-
try {
|
35
|
-
step(generator.throw(value));
|
36
|
-
} catch (e) {
|
37
|
-
reject(e);
|
38
|
-
}
|
39
|
-
};
|
40
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
41
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
42
|
-
});
|
43
|
-
};
|
44
24
|
var cli_exports = {};
|
45
25
|
__export(cli_exports, {
|
46
26
|
default: () => cli_default,
|
@@ -70,9 +50,9 @@ var cli_default = () => {
|
|
70
50
|
let testingExportsUtils;
|
71
51
|
return {
|
72
52
|
commands: ({ program }) => {
|
73
|
-
program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(() =>
|
74
|
-
|
75
|
-
})
|
53
|
+
program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(async () => {
|
54
|
+
await (0, import_test.default)(api);
|
55
|
+
});
|
76
56
|
},
|
77
57
|
validateSchema() {
|
78
58
|
return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-testing"];
|
@@ -96,10 +76,10 @@ var cli_default = () => {
|
|
96
76
|
const testingPath = import_path.default.resolve(__dirname, "../");
|
97
77
|
testingExportsUtils.addExport(`export * from '${testingPath}'`);
|
98
78
|
},
|
99
|
-
jestConfig: (utils, next) =>
|
79
|
+
jestConfig: async (utils, next) => {
|
100
80
|
const appContext = api.useAppContext();
|
101
81
|
const userConfig = api.useResolvedConfigContext();
|
102
|
-
const apiOnly =
|
82
|
+
const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory);
|
103
83
|
if (apiOnly) {
|
104
84
|
return next(utils);
|
105
85
|
}
|
@@ -124,7 +104,7 @@ var cli_default = () => {
|
|
124
104
|
});
|
125
105
|
mergeUserJestConfig(utils);
|
126
106
|
return next(utils);
|
127
|
-
}
|
107
|
+
}
|
128
108
|
};
|
129
109
|
}
|
130
110
|
};
|
@@ -21,26 +21,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
21
21
|
mod
|
22
22
|
));
|
23
23
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
24
|
-
var __async = (__this, __arguments, generator) => {
|
25
|
-
return new Promise((resolve, reject) => {
|
26
|
-
var fulfilled = (value) => {
|
27
|
-
try {
|
28
|
-
step(generator.next(value));
|
29
|
-
} catch (e) {
|
30
|
-
reject(e);
|
31
|
-
}
|
32
|
-
};
|
33
|
-
var rejected = (value) => {
|
34
|
-
try {
|
35
|
-
step(generator.throw(value));
|
36
|
-
} catch (e) {
|
37
|
-
reject(e);
|
38
|
-
}
|
39
|
-
};
|
40
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
41
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
42
|
-
});
|
43
|
-
};
|
44
24
|
var test_exports = {};
|
45
25
|
__export(test_exports, {
|
46
26
|
default: () => test_default
|
@@ -49,7 +29,7 @@ module.exports = __toCommonJS(test_exports);
|
|
49
29
|
var import_path = __toESM(require("path"));
|
50
30
|
var import_babel_compiler = require("@modern-js/babel-compiler");
|
51
31
|
var import_base = require("../base");
|
52
|
-
const test = (api) =>
|
32
|
+
const test = async (api) => {
|
53
33
|
var _a, _b;
|
54
34
|
const userConfig = api.useResolvedConfigContext();
|
55
35
|
const appContext = api.useAppContext();
|
@@ -63,7 +43,7 @@ const test = (api) => __async(void 0, null, function* () {
|
|
63
43
|
appContext.internalDirectory,
|
64
44
|
".runtime-exports"
|
65
45
|
);
|
66
|
-
|
46
|
+
await (0, import_babel_compiler.compiler)(
|
67
47
|
{
|
68
48
|
sourceDir: runtimeExportsPath,
|
69
49
|
rootDir: runtimeExportsPath,
|
@@ -81,8 +61,8 @@ const test = (api) => __async(void 0, null, function* () {
|
|
81
61
|
]
|
82
62
|
}
|
83
63
|
);
|
84
|
-
|
85
|
-
}
|
64
|
+
await (0, import_base.runTest)(api, userConfig.testing);
|
65
|
+
};
|
86
66
|
var test_default = test;
|
87
67
|
// Annotate the CommonJS export names for ESM import in node:
|
88
68
|
0 && (module.exports = {});
|
File without changes
|
File without changes
|
@@ -2,22 +2,8 @@ var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
6
5
|
var __getProtoOf = Object.getPrototypeOf;
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
-
var __spreadValues = (a, b) => {
|
11
|
-
for (var prop in b || (b = {}))
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
14
|
-
if (__getOwnPropSymbols)
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
-
if (__propIsEnum.call(b, prop))
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
18
|
-
}
|
19
|
-
return a;
|
20
|
-
};
|
21
7
|
var __export = (target, all) => {
|
22
8
|
for (var name in all)
|
23
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -55,7 +41,10 @@ class ModernRuntime {
|
|
55
41
|
const { entry, children } = props || {};
|
56
42
|
let runtimeFeatures = (_a = this.options) == null ? void 0 : _a.runtime;
|
57
43
|
if (entry) {
|
58
|
-
runtimeFeatures =
|
44
|
+
runtimeFeatures = {
|
45
|
+
...runtimeFeatures || {},
|
46
|
+
...(_b = this.options.runtimeByEntries) == null ? void 0 : _b[entry]
|
47
|
+
};
|
59
48
|
}
|
60
49
|
const Component = () => {
|
61
50
|
if (!children) {
|
File without changes
|
@@ -2,22 +2,8 @@ var __create = Object.create;
|
|
2
2
|
var __defProp = Object.defineProperty;
|
3
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
6
5
|
var __getProtoOf = Object.getPrototypeOf;
|
7
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
-
var __spreadValues = (a, b) => {
|
11
|
-
for (var prop in b || (b = {}))
|
12
|
-
if (__hasOwnProp.call(b, prop))
|
13
|
-
__defNormalProp(a, prop, b[prop]);
|
14
|
-
if (__getOwnPropSymbols)
|
15
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
-
if (__propIsEnum.call(b, prop))
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
18
|
-
}
|
19
|
-
return a;
|
20
|
-
};
|
21
7
|
var __export = (target, all) => {
|
22
8
|
for (var name in all)
|
23
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -44,7 +30,7 @@ var import_react = __toESM(require("react"));
|
|
44
30
|
var import_react2 = require("@testing-library/react");
|
45
31
|
var import_app = __toESM(require("./app"));
|
46
32
|
const WrapModernProviders = (props) => import_react.default.createElement(import_app.default.createApp(props));
|
47
|
-
const customRender = (ui, options) => (0, import_react2.render)(ui,
|
33
|
+
const customRender = (ui, options) => (0, import_react2.render)(ui, { wrapper: WrapModernProviders, ...options });
|
48
34
|
var customRender_default = customRender;
|
49
35
|
// Annotate the CommonJS export names for ESM import in node:
|
50
36
|
0 && (module.exports = {});
|
File without changes
|
@@ -1,26 +1,9 @@
|
|
1
1
|
var __create = Object.create;
|
2
2
|
var __defProp = Object.defineProperty;
|
3
|
-
var __defProps = Object.defineProperties;
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
8
5
|
var __getProtoOf = Object.getPrototypeOf;
|
9
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
10
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
11
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
12
|
-
var __spreadValues = (a, b) => {
|
13
|
-
for (var prop in b || (b = {}))
|
14
|
-
if (__hasOwnProp.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
if (__getOwnPropSymbols)
|
17
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
18
|
-
if (__propIsEnum.call(b, prop))
|
19
|
-
__defNormalProp(a, prop, b[prop]);
|
20
|
-
}
|
21
|
-
return a;
|
22
|
-
};
|
23
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
24
7
|
var __export = (target, all) => {
|
25
8
|
for (var name in all)
|
26
9
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -71,9 +54,10 @@ const createStore = (props) => {
|
|
71
54
|
}
|
72
55
|
return ((props == null ? void 0 : props.plugins) || []).concat(plugins);
|
73
56
|
};
|
74
|
-
const config =
|
57
|
+
const config = {
|
58
|
+
...props || {},
|
75
59
|
plugins: createStatePlugins()
|
76
|
-
}
|
60
|
+
};
|
77
61
|
return (0, import_store.createStore)(config);
|
78
62
|
};
|
79
63
|
// Annotate the CommonJS export names for ESM import in node:
|
File without changes
|
@@ -1,21 +1,7 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
-
var __spreadValues = (a, b) => {
|
9
|
-
for (var prop in b || (b = {}))
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
12
|
-
if (__getOwnPropSymbols)
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
-
if (__propIsEnum.call(b, prop))
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
16
|
-
}
|
17
|
-
return a;
|
18
|
-
};
|
19
5
|
var __export = (target, all) => {
|
20
6
|
for (var name in all)
|
21
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -42,7 +28,9 @@ function resolvePlugins(features) {
|
|
42
28
|
}
|
43
29
|
Object.keys(features).forEach((feature) => {
|
44
30
|
if (allowedFeatures.includes(feature)) {
|
45
|
-
const curPluginRes = require(`@modern-js/runtime/plugins`)[feature](
|
31
|
+
const curPluginRes = require(`@modern-js/runtime/plugins`)[feature]({
|
32
|
+
...features[feature]
|
33
|
+
});
|
46
34
|
plugins.push(curPluginRes);
|
47
35
|
}
|
48
36
|
});
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { applyPatches } from "./patches";
|
2
|
+
import { TestConfigOperator } from "./testConfigOperator";
|
3
|
+
const getJestUtils = (testConfig) => {
|
4
|
+
const testOperator = new TestConfigOperator(testConfig);
|
5
|
+
return testOperator;
|
6
|
+
};
|
7
|
+
const patchConfig = async (testOperator) => {
|
8
|
+
await applyPatches(testOperator);
|
9
|
+
return testOperator.jestConfig;
|
10
|
+
};
|
11
|
+
const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
12
|
+
export {
|
13
|
+
DEFAULT_RESOLVER_PATH,
|
14
|
+
getJestUtils,
|
15
|
+
patchConfig
|
16
|
+
};
|
File without changes
|
File without changes
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { patchTransformer } from "./transformer";
|
2
|
+
import { patchAssetsModule } from "./assetsModule";
|
3
|
+
const _applyPatches = async (patches2, testOperator) => {
|
4
|
+
for (const patch of patches2) {
|
5
|
+
await patch(testOperator);
|
6
|
+
}
|
7
|
+
};
|
8
|
+
const patches = [patchTransformer, patchAssetsModule];
|
9
|
+
const applyPatches = async (testConfig) => {
|
10
|
+
await _applyPatches(patches, testConfig);
|
11
|
+
};
|
12
|
+
export {
|
13
|
+
applyPatches
|
14
|
+
};
|
File without changes
|
File without changes
|
@@ -1,19 +1,3 @@
|
|
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
1
|
import { merge } from "@modern-js/utils/lodash";
|
18
2
|
class TestConfigOperator {
|
19
3
|
constructor(testConfig) {
|
@@ -51,7 +35,7 @@ class TestConfigOperator {
|
|
51
35
|
return;
|
52
36
|
}
|
53
37
|
}
|
54
|
-
this._jestConfig =
|
38
|
+
this._jestConfig = { ...this._jestConfig, ...sourceConfig };
|
55
39
|
}
|
56
40
|
getFinalConfig() {
|
57
41
|
const { userJestConfig } = this;
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import yargs from "yargs/yargs";
|
2
|
+
import { runCLI } from "jest";
|
3
|
+
import { chalk } from "@modern-js/utils";
|
4
|
+
import { getJestUtils, patchConfig } from "./config";
|
5
|
+
import { debug } from "./utils";
|
6
|
+
const buildArgv = async (rawArgv, config) => {
|
7
|
+
const argv = await yargs(rawArgv).argv;
|
8
|
+
const result = {
|
9
|
+
$0: argv.$0,
|
10
|
+
_: argv._.slice(1)
|
11
|
+
};
|
12
|
+
Object.keys(argv).forEach((key) => {
|
13
|
+
if (key.includes("-") || key === "_") {
|
14
|
+
return;
|
15
|
+
}
|
16
|
+
result[key] = argv[key];
|
17
|
+
});
|
18
|
+
if (config) {
|
19
|
+
result.config = JSON.stringify(config);
|
20
|
+
}
|
21
|
+
return result;
|
22
|
+
};
|
23
|
+
const readResultsAndExit = (result, globalConfig) => {
|
24
|
+
const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
|
25
|
+
process.on("exit", () => {
|
26
|
+
if (typeof code === "number" && code !== 0) {
|
27
|
+
process.exitCode = code;
|
28
|
+
}
|
29
|
+
});
|
30
|
+
if (globalConfig.forceExit) {
|
31
|
+
if (!globalConfig.detectOpenHandles) {
|
32
|
+
console.warn(
|
33
|
+
`${chalk.bold(
|
34
|
+
"Force exiting Jest: "
|
35
|
+
)}Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?`
|
36
|
+
);
|
37
|
+
}
|
38
|
+
process.exit(code);
|
39
|
+
} else if (!globalConfig.detectOpenHandles) {
|
40
|
+
setTimeout(() => {
|
41
|
+
console.warn(
|
42
|
+
chalk.yellow.bold(
|
43
|
+
"Jest did not exit one second after the test run has completed.\n\n"
|
44
|
+
) + chalk.yellow(
|
45
|
+
"This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue."
|
46
|
+
)
|
47
|
+
);
|
48
|
+
}, 1e3).unref();
|
49
|
+
}
|
50
|
+
};
|
51
|
+
async function runJest(config, pwd = process.cwd()) {
|
52
|
+
try {
|
53
|
+
const argvConfig = await buildArgv(process.argv.slice(2), config);
|
54
|
+
const { results, globalConfig } = await runCLI(argvConfig, [pwd]);
|
55
|
+
readResultsAndExit(results, globalConfig);
|
56
|
+
} catch (e) {
|
57
|
+
console.error(chalk.red((e == null ? void 0 : e.stack) || e));
|
58
|
+
process.exit(1);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
async function runTest(api, config, pwd = process.cwd()) {
|
62
|
+
process.env.NODE_ENV = "test";
|
63
|
+
const jestUtils = getJestUtils(config);
|
64
|
+
await patchConfig(jestUtils);
|
65
|
+
jestUtils.setJestUserConfig();
|
66
|
+
const hookRunners = api.useHookRunners();
|
67
|
+
const testConfigOperator = await hookRunners.jestConfig(jestUtils, {
|
68
|
+
onLast: (input) => input
|
69
|
+
});
|
70
|
+
const finalConfig = testConfigOperator.getFinalConfig();
|
71
|
+
debug("Jest config:", finalConfig);
|
72
|
+
await runJest(finalConfig, pwd);
|
73
|
+
await hookRunners.afterTest();
|
74
|
+
}
|
75
|
+
export {
|
76
|
+
runJest,
|
77
|
+
runTest
|
78
|
+
};
|
File without changes
|
@@ -1,19 +1,3 @@
|
|
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
1
|
import fs from "fs";
|
18
2
|
import path from "path";
|
19
3
|
import { createDebugger } from "@modern-js/utils";
|
@@ -42,7 +26,10 @@ const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") =>
|
|
42
26
|
tsConfig.extends
|
43
27
|
);
|
44
28
|
}
|
45
|
-
return
|
29
|
+
return {
|
30
|
+
...extendedCompilerOptions,
|
31
|
+
...tsConfig.compilerOptions
|
32
|
+
};
|
46
33
|
};
|
47
34
|
const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
|
48
35
|
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { AsyncLocalStorage } from "async_hooks";
|
2
|
+
import { Server } from "@modern-js/prod-server";
|
3
|
+
const store = new AsyncLocalStorage();
|
4
|
+
const isInHandler = () => Boolean(store.getStore());
|
5
|
+
let server = null;
|
6
|
+
const createApp = async (pwd, config, plugins, routes) => {
|
7
|
+
if (!server) {
|
8
|
+
config.output.path = "./";
|
9
|
+
server = new Server({
|
10
|
+
apiOnly: true,
|
11
|
+
pwd,
|
12
|
+
config,
|
13
|
+
internalPlugins: plugins,
|
14
|
+
routes
|
15
|
+
});
|
16
|
+
await server.init();
|
17
|
+
}
|
18
|
+
const app = server.getRequestHandler();
|
19
|
+
return app;
|
20
|
+
};
|
21
|
+
const getApp = () => {
|
22
|
+
if (!server) {
|
23
|
+
throw new Error("please createApp first");
|
24
|
+
}
|
25
|
+
return server.getRequestHandler();
|
26
|
+
};
|
27
|
+
const closeServer = async () => {
|
28
|
+
if (!server) {
|
29
|
+
throw new Error("please createApp first");
|
30
|
+
}
|
31
|
+
await server.close();
|
32
|
+
};
|
33
|
+
export {
|
34
|
+
closeServer,
|
35
|
+
createApp,
|
36
|
+
getApp,
|
37
|
+
isInHandler
|
38
|
+
};
|
File without changes
|