@modern-js/plugin-testing 2.15.0 → 2.16.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/base/config/index.js +15 -39
- package/dist/cjs/base/config/patches/assetsModule.js +7 -35
- package/dist/cjs/base/config/patches/filemock.js +8 -24
- package/dist/cjs/base/config/patches/index.js +13 -28
- package/dist/cjs/base/config/patches/transformer.js +13 -38
- package/dist/cjs/base/config/resolver.js +23 -26
- package/dist/cjs/base/config/testConfigOperator.js +39 -38
- package/dist/cjs/base/config/transformer/babelTransformer.js +16 -37
- package/dist/cjs/base/hook.js +17 -31
- package/dist/cjs/base/index.js +36 -41
- package/dist/cjs/base/runJest.js +31 -57
- package/dist/cjs/base/types/index.js +4 -15
- package/dist/cjs/base/utils.js +30 -53
- package/dist/cjs/cli/bff/app.js +17 -32
- package/dist/cjs/cli/bff/constant.js +7 -25
- package/dist/cjs/cli/bff/index.js +71 -92
- package/dist/cjs/cli/bff/mockAPI.js +115 -92
- package/dist/cjs/cli/bff/setup.js +30 -51
- package/dist/cjs/cli/bff/utils/index.js +21 -45
- package/dist/cjs/cli/index.js +43 -59
- package/dist/cjs/cli/test.js +35 -62
- package/dist/cjs/constant.js +7 -25
- package/dist/cjs/index.js +20 -19
- package/dist/cjs/runtime-testing/app.js +40 -45
- package/dist/cjs/runtime-testing/base.js +34 -40
- package/dist/cjs/runtime-testing/customRender.js +21 -39
- package/dist/cjs/runtime-testing/index.js +19 -18
- package/dist/cjs/runtime-testing/reduck.js +35 -55
- package/dist/cjs/runtime-testing/request.js +16 -39
- package/dist/cjs/runtime-testing/resolvePlugins.js +12 -25
- package/dist/esm/base/config/index.js +146 -139
- package/dist/esm/base/config/patches/assetsModule.js +7 -8
- package/dist/esm/base/config/patches/filemock.js +1 -2
- package/dist/esm/base/config/patches/index.js +214 -207
- package/dist/esm/base/config/patches/transformer.js +27 -28
- package/dist/esm/base/config/resolver.js +22 -35
- package/dist/esm/base/config/testConfigOperator.js +119 -116
- package/dist/esm/base/config/transformer/babelTransformer.js +12 -13
- package/dist/esm/base/hook.js +5 -6
- package/dist/esm/base/index.js +5 -6
- package/dist/esm/base/runJest.js +270 -264
- package/dist/esm/base/types/index.js +1 -1
- package/dist/esm/base/utils.js +66 -67
- package/dist/esm/cli/bff/app.js +187 -179
- package/dist/esm/cli/bff/constant.js +1 -2
- package/dist/esm/cli/bff/index.js +285 -278
- package/dist/esm/cli/bff/mockAPI.js +177 -163
- package/dist/esm/cli/bff/setup.js +182 -174
- package/dist/esm/cli/bff/utils/index.js +40 -41
- package/dist/esm/cli/index.js +249 -242
- package/dist/esm/cli/test.js +172 -166
- package/dist/esm/constant.js +1 -2
- package/dist/esm/runtime-testing/app.js +79 -77
- package/dist/esm/runtime-testing/base.js +2 -3
- package/dist/esm/runtime-testing/customRender.js +30 -31
- package/dist/esm/runtime-testing/reduck.js +72 -73
- package/dist/esm/runtime-testing/request.js +55 -45
- package/dist/esm/runtime-testing/resolvePlugins.js +38 -39
- package/dist/esm-node/base/config/index.js +2 -6
- package/dist/esm-node/base/config/patches/assetsModule.js +1 -4
- package/dist/esm-node/base/config/patches/filemock.js +1 -4
- package/dist/esm-node/base/config/patches/index.js +5 -5
- package/dist/esm-node/base/config/patches/transformer.js +5 -5
- package/dist/esm-node/base/config/resolver.js +20 -19
- package/dist/esm-node/base/config/testConfigOperator.js +30 -13
- package/dist/esm-node/base/config/transformer/babelTransformer.js +3 -6
- package/dist/esm-node/base/hook.js +3 -8
- package/dist/esm-node/base/index.js +5 -13
- package/dist/esm-node/base/runJest.js +8 -20
- package/dist/esm-node/base/types/index.js +1 -0
- package/dist/esm-node/base/utils.js +8 -17
- package/dist/esm-node/cli/bff/app.js +2 -7
- package/dist/esm-node/cli/bff/constant.js +1 -4
- package/dist/esm-node/cli/bff/index.js +43 -54
- package/dist/esm-node/cli/bff/mockAPI.js +65 -59
- package/dist/esm-node/cli/bff/setup.js +11 -19
- package/dist/esm-node/cli/bff/utils/index.js +6 -10
- package/dist/esm-node/cli/index.js +11 -23
- package/dist/esm-node/cli/test.js +19 -28
- package/dist/esm-node/constant.js +1 -4
- package/dist/esm-node/runtime-testing/app.js +22 -10
- package/dist/esm-node/runtime-testing/base.js +2 -6
- package/dist/esm-node/runtime-testing/customRender.js +5 -5
- package/dist/esm-node/runtime-testing/reduck.js +10 -16
- package/dist/esm-node/runtime-testing/request.js +1 -3
- package/dist/esm-node/runtime-testing/resolvePlugins.js +6 -6
- package/package.json +18 -14
package/dist/cjs/base/runJest.js
CHANGED
@@ -1,43 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __export = (target, all) => {
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
8
6
|
for (var name in all)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
-
}
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var runJest_exports = {};
|
29
|
-
__export(runJest_exports, {
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
30
13
|
runJest: () => runJest,
|
31
14
|
runTest: () => runTest
|
32
15
|
});
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
16
|
+
const _yargs = /* @__PURE__ */ _interop_require_default(require("yargs/yargs"));
|
17
|
+
const _jest = require("jest");
|
18
|
+
const _utils = require("@modern-js/utils");
|
19
|
+
const _config = require("./config");
|
20
|
+
const _utils1 = require("./utils");
|
21
|
+
function _interop_require_default(obj) {
|
22
|
+
return obj && obj.__esModule ? obj : {
|
23
|
+
default: obj
|
24
|
+
};
|
25
|
+
}
|
39
26
|
const buildArgv = async (rawArgv, config) => {
|
40
|
-
const argv = await (0,
|
27
|
+
const argv = await (0, _yargs.default)(rawArgv).argv;
|
41
28
|
const result = {
|
42
29
|
$0: argv.$0,
|
43
30
|
_: argv._.slice(1)
|
@@ -62,51 +49,38 @@ const readResultsAndExit = (result, globalConfig) => {
|
|
62
49
|
});
|
63
50
|
if (globalConfig.forceExit) {
|
64
51
|
if (!globalConfig.detectOpenHandles) {
|
65
|
-
console.warn(
|
66
|
-
`${import_utils.chalk.bold(
|
67
|
-
"Force exiting Jest: "
|
68
|
-
)}Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?`
|
69
|
-
);
|
52
|
+
console.warn(`${_utils.chalk.bold("Force exiting Jest: ")}Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?`);
|
70
53
|
}
|
71
54
|
process.exit(code);
|
72
55
|
} else if (!globalConfig.detectOpenHandles) {
|
73
56
|
setTimeout(() => {
|
74
|
-
console.warn(
|
75
|
-
import_utils.chalk.yellow.bold(
|
76
|
-
"Jest did not exit one second after the test run has completed.\n\n"
|
77
|
-
) + import_utils.chalk.yellow(
|
78
|
-
"This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue."
|
79
|
-
)
|
80
|
-
);
|
57
|
+
console.warn(_utils.chalk.yellow.bold("Jest did not exit one second after the test run has completed.\n\n") + _utils.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."));
|
81
58
|
}, 1e3).unref();
|
82
59
|
}
|
83
60
|
};
|
84
61
|
async function runJest(config, pwd = process.cwd()) {
|
85
62
|
try {
|
86
63
|
const argvConfig = await buildArgv(process.argv.slice(2), config);
|
87
|
-
const { results, globalConfig } = await (0,
|
64
|
+
const { results, globalConfig } = await (0, _jest.runCLI)(argvConfig, [
|
65
|
+
pwd
|
66
|
+
]);
|
88
67
|
readResultsAndExit(results, globalConfig);
|
89
68
|
} catch (e) {
|
90
|
-
console.error(
|
69
|
+
console.error(_utils.chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
|
91
70
|
process.exit(1);
|
92
71
|
}
|
93
72
|
}
|
94
73
|
async function runTest(api, config, pwd = process.cwd()) {
|
95
74
|
process.env.NODE_ENV = "test";
|
96
|
-
const jestUtils = (0,
|
97
|
-
await (0,
|
75
|
+
const jestUtils = (0, _config.getJestUtils)(config);
|
76
|
+
await (0, _config.patchConfig)(jestUtils);
|
98
77
|
jestUtils.setJestUserConfig();
|
99
78
|
const hookRunners = api.useHookRunners();
|
100
79
|
const testConfigOperator = await hookRunners.jestConfig(jestUtils, {
|
101
80
|
onLast: (input) => input
|
102
81
|
});
|
103
82
|
const finalConfig = testConfigOperator.getFinalConfig();
|
104
|
-
(0,
|
83
|
+
(0, _utils1.debug)("Jest config:", finalConfig);
|
105
84
|
await runJest(finalConfig, pwd);
|
106
85
|
await hookRunners.afterTest();
|
107
86
|
}
|
108
|
-
// Annotate the CommonJS export names for ESM import in node:
|
109
|
-
0 && (module.exports = {
|
110
|
-
runJest,
|
111
|
-
runTest
|
112
|
-
});
|
@@ -1,15 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
var __copyProps = (to, from, except, desc) => {
|
6
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
7
|
-
for (let key of __getOwnPropNames(from))
|
8
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
9
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
10
|
-
}
|
11
|
-
return to;
|
12
|
-
};
|
13
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
14
|
-
var types_exports = {};
|
15
|
-
module.exports = __toCommonJS(types_exports);
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
package/dist/cjs/base/utils.js
CHANGED
@@ -1,64 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __export = (target, all) => {
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
8
6
|
for (var name in all)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
-
}
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var utils_exports = {};
|
29
|
-
__export(utils_exports, {
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
30
13
|
debug: () => debug,
|
31
|
-
|
32
|
-
|
14
|
+
readCompilerOptions: () => readCompilerOptions,
|
15
|
+
getModuleNameMapper: () => getModuleNameMapper
|
33
16
|
});
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
17
|
+
const _fs = /* @__PURE__ */ _interop_require_default(require("fs"));
|
18
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
19
|
+
const _utils = require("@modern-js/utils");
|
20
|
+
function _interop_require_default(obj) {
|
21
|
+
return obj && obj.__esModule ? obj : {
|
22
|
+
default: obj
|
23
|
+
};
|
24
|
+
}
|
25
|
+
const debug = (0, _utils.createDebugger)("test");
|
39
26
|
const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
|
40
27
|
let tsConfig = {};
|
41
28
|
let extendedCompilerOptions = {};
|
42
29
|
let tsconfigFile = "";
|
43
30
|
try {
|
44
|
-
const maybeTsconfigFile =
|
45
|
-
if (
|
31
|
+
const maybeTsconfigFile = _path.default.join(pwd, filename);
|
32
|
+
if (_fs.default.existsSync(maybeTsconfigFile)) {
|
46
33
|
tsconfigFile = maybeTsconfigFile;
|
47
34
|
} else {
|
48
35
|
tsconfigFile = require.resolve(filename);
|
49
36
|
}
|
50
|
-
({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(
|
51
|
-
tsconfigFile,
|
52
|
-
import_fs.default.readFileSync(tsconfigFile, "utf8")
|
53
|
-
));
|
37
|
+
({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(tsconfigFile, _fs.default.readFileSync(tsconfigFile, "utf8")));
|
54
38
|
} catch (e) {
|
55
39
|
return {};
|
56
40
|
}
|
57
41
|
if (tsConfig.extends) {
|
58
|
-
extendedCompilerOptions = readCompilerOptions(
|
59
|
-
import_path.default.dirname(tsconfigFile),
|
60
|
-
tsConfig.extends
|
61
|
-
);
|
42
|
+
extendedCompilerOptions = readCompilerOptions(_path.default.dirname(tsconfigFile), tsConfig.extends);
|
62
43
|
}
|
63
44
|
return {
|
64
45
|
...extendedCompilerOptions,
|
@@ -66,7 +47,9 @@ const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") =>
|
|
66
47
|
};
|
67
48
|
};
|
68
49
|
const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
|
69
|
-
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [
|
50
|
+
const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [
|
51
|
+
alias[cur]
|
52
|
+
];
|
70
53
|
const isFile = aliasValue.some((s) => s.endsWith(".js"));
|
71
54
|
if (cur === "@modern-js/runtime$") {
|
72
55
|
memo[`.+${cur}`] = aliasValue[0];
|
@@ -76,13 +59,7 @@ const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) =>
|
|
76
59
|
memo[cur] = aliasValue[0];
|
77
60
|
}
|
78
61
|
const key = `^${cur}/(.*)$`;
|
79
|
-
const value =
|
62
|
+
const value = _path.default.normalize(`${aliasValue}/$1`);
|
80
63
|
memo[key] = value;
|
81
64
|
return memo;
|
82
65
|
}, {});
|
83
|
-
// Annotate the CommonJS export names for ESM import in node:
|
84
|
-
0 && (module.exports = {
|
85
|
-
debug,
|
86
|
-
getModuleNameMapper,
|
87
|
-
readCompilerOptions
|
88
|
-
});
|
package/dist/cjs/cli/bff/app.js
CHANGED
@@ -1,37 +1,29 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
6
6
|
for (var name in all)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
}
|
15
|
-
return to;
|
16
|
-
};
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
-
var app_exports = {};
|
19
|
-
__export(app_exports, {
|
20
|
-
closeServer: () => closeServer,
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
isInHandler: () => isInHandler,
|
21
14
|
createApp: () => createApp,
|
22
15
|
getApp: () => getApp,
|
23
|
-
|
16
|
+
closeServer: () => closeServer
|
24
17
|
});
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
const store = new import_async_hooks.AsyncLocalStorage();
|
18
|
+
const _async_hooks = require("async_hooks");
|
19
|
+
const _prodserver = require("@modern-js/prod-server");
|
20
|
+
const store = new _async_hooks.AsyncLocalStorage();
|
29
21
|
const isInHandler = () => Boolean(store.getStore());
|
30
22
|
let server = null;
|
31
23
|
const createApp = async (pwd, config, plugins, routes) => {
|
32
24
|
if (!server) {
|
33
25
|
config.output.path = "./";
|
34
|
-
server = new
|
26
|
+
server = new _prodserver.Server({
|
35
27
|
apiOnly: true,
|
36
28
|
pwd,
|
37
29
|
config,
|
@@ -55,10 +47,3 @@ const closeServer = async () => {
|
|
55
47
|
}
|
56
48
|
await server.close();
|
57
49
|
};
|
58
|
-
// Annotate the CommonJS export names for ESM import in node:
|
59
|
-
0 && (module.exports = {
|
60
|
-
closeServer,
|
61
|
-
createApp,
|
62
|
-
getApp,
|
63
|
-
isInHandler
|
64
|
-
});
|
@@ -1,27 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
-
var __export = (target, all) => {
|
6
|
-
for (var name in all)
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
-
};
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
-
for (let key of __getOwnPropNames(from))
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
-
}
|
15
|
-
return to;
|
16
|
-
};
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
-
var constant_exports = {};
|
19
|
-
__export(constant_exports, {
|
20
|
-
bff_info_key: () => bff_info_key
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
21
4
|
});
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
0 && (module.exports = {
|
26
|
-
bff_info_key
|
5
|
+
Object.defineProperty(exports, "bff_info_key", {
|
6
|
+
enumerable: true,
|
7
|
+
get: () => bff_info_key
|
27
8
|
});
|
9
|
+
const bff_info_key = "modern_bff_info";
|
@@ -1,56 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
-
var __export = (target, all) => {
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
3
|
+
value: true
|
4
|
+
});
|
5
|
+
function _export(target, all) {
|
8
6
|
for (var name in all)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
return to;
|
18
|
-
};
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
-
mod
|
26
|
-
));
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
-
var bff_exports = {};
|
29
|
-
__export(bff_exports, {
|
30
|
-
default: () => bff_default,
|
31
|
-
setJestConfigForBFF: () => setJestConfigForBFF
|
7
|
+
Object.defineProperty(target, name, {
|
8
|
+
enumerable: true,
|
9
|
+
get: all[name]
|
10
|
+
});
|
11
|
+
}
|
12
|
+
_export(exports, {
|
13
|
+
setJestConfigForBFF: () => setJestConfigForBFF,
|
14
|
+
default: () => _default
|
32
15
|
});
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
}) => {
|
46
|
-
var _a;
|
16
|
+
const _path = /* @__PURE__ */ _interop_require_default(require("path"));
|
17
|
+
const _utils = require("@modern-js/utils");
|
18
|
+
const _base = require("../../base");
|
19
|
+
const _constant = require("./constant");
|
20
|
+
const _utils1 = require("./utils");
|
21
|
+
function _interop_require_default(obj) {
|
22
|
+
return obj && obj.__esModule ? obj : {
|
23
|
+
default: obj
|
24
|
+
};
|
25
|
+
}
|
26
|
+
const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils }) => {
|
27
|
+
var _userConfig_source;
|
47
28
|
const bffConfig = {
|
48
|
-
rootDir:
|
49
|
-
setupFilesAfterEnv: [
|
29
|
+
rootDir: _path.default.join(pwd, "./api"),
|
30
|
+
setupFilesAfterEnv: [
|
31
|
+
require.resolve("./setup")
|
32
|
+
],
|
50
33
|
testEnvironment: "node",
|
51
|
-
testMatch: [
|
34
|
+
testMatch: [
|
35
|
+
`**/api/**/*.test.[jt]s`
|
36
|
+
],
|
52
37
|
globals: {
|
53
|
-
[
|
38
|
+
[_constant.bff_info_key]: {
|
54
39
|
appDir: pwd,
|
55
40
|
modernUserConfig: userConfig,
|
56
41
|
plugins,
|
@@ -59,8 +44,8 @@ const setJestConfigForBFF = async ({
|
|
59
44
|
}
|
60
45
|
};
|
61
46
|
const { jestConfig } = utils;
|
62
|
-
const alias = (
|
63
|
-
const aliasMapper = (0,
|
47
|
+
const alias = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.alias) || {};
|
48
|
+
const aliasMapper = (0, _base.getModuleNameMapper)(alias);
|
64
49
|
const { moduleNameMapper } = jestConfig;
|
65
50
|
const transform = {
|
66
51
|
"\\.[jt]sx?$": [
|
@@ -72,13 +57,17 @@ const setJestConfigForBFF = async ({
|
|
72
57
|
}
|
73
58
|
]
|
74
59
|
};
|
75
|
-
const apiOnly = await (0,
|
60
|
+
const apiOnly = await (0, _utils.isApiOnly)(pwd);
|
76
61
|
const mergedModuleNameMapper = {
|
77
62
|
...moduleNameMapper,
|
78
63
|
...aliasMapper
|
79
64
|
};
|
80
|
-
const resolver = jestConfig.resolver ||
|
81
|
-
const configFields = [
|
65
|
+
const resolver = jestConfig.resolver || _base.DEFAULT_RESOLVER_PATH;
|
66
|
+
const configFields = [
|
67
|
+
"coverage",
|
68
|
+
"collectCoverage",
|
69
|
+
"testTimeout"
|
70
|
+
];
|
82
71
|
const commonConfig = configFields.reduce((obj, field) => {
|
83
72
|
if (jestConfig.hasOwnProperty(field)) {
|
84
73
|
obj[field] = jestConfig[field];
|
@@ -86,51 +75,45 @@ const setJestConfigForBFF = async ({
|
|
86
75
|
return obj;
|
87
76
|
}, {});
|
88
77
|
if (!apiOnly) {
|
89
|
-
utils.setJestConfig(
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
force: true
|
105
|
-
}
|
106
|
-
);
|
78
|
+
utils.setJestConfig({
|
79
|
+
projects: [
|
80
|
+
{
|
81
|
+
...jestConfig
|
82
|
+
},
|
83
|
+
{
|
84
|
+
transform,
|
85
|
+
moduleNameMapper: mergedModuleNameMapper,
|
86
|
+
resolver,
|
87
|
+
...bffConfig
|
88
|
+
}
|
89
|
+
]
|
90
|
+
}, {
|
91
|
+
force: true
|
92
|
+
});
|
107
93
|
} else {
|
108
|
-
utils.setJestConfig(
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
force: true
|
121
|
-
}
|
122
|
-
);
|
94
|
+
utils.setJestConfig({
|
95
|
+
projects: [
|
96
|
+
{
|
97
|
+
transform,
|
98
|
+
moduleNameMapper: mergedModuleNameMapper,
|
99
|
+
resolver,
|
100
|
+
...bffConfig
|
101
|
+
}
|
102
|
+
]
|
103
|
+
}, {
|
104
|
+
force: true
|
105
|
+
});
|
123
106
|
}
|
124
107
|
utils.setJestConfig(commonConfig);
|
125
108
|
};
|
126
|
-
|
109
|
+
const _default = () => ({
|
127
110
|
name: "@modern-js/testing-plugin-bff",
|
128
111
|
setup(api) {
|
129
112
|
return {
|
130
113
|
jestConfig: async (utils, next) => {
|
131
114
|
const appContext = api.useAppContext();
|
132
115
|
const pwd = appContext.appDirectory;
|
133
|
-
if (!(0,
|
116
|
+
if (!(0, _utils1.isBFFProject)(pwd)) {
|
134
117
|
return next(utils);
|
135
118
|
}
|
136
119
|
const userConfig = api.useResolvedConfigContext();
|
@@ -146,7 +129,3 @@ var bff_default = () => ({
|
|
146
129
|
};
|
147
130
|
}
|
148
131
|
});
|
149
|
-
// Annotate the CommonJS export names for ESM import in node:
|
150
|
-
0 && (module.exports = {
|
151
|
-
setJestConfigForBFF
|
152
|
-
});
|