@modern-js/plugin-testing 0.0.0-nightly-20230918160602 → 0.0.0-nightly-20230922160540
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/dist/cjs/base/config/index.js +41 -22
- package/dist/cjs/base/config/patches/assetsModule.js +34 -7
- package/dist/cjs/base/config/patches/filemock.js +21 -8
- package/dist/cjs/base/config/patches/index.js +28 -11
- package/dist/cjs/base/config/patches/transformer.js +36 -9
- package/dist/cjs/base/config/resolver.js +24 -6
- package/dist/cjs/base/config/testConfigOperator.js +32 -15
- package/dist/cjs/base/config/transformer/babelTransformer.js +34 -12
- package/dist/cjs/base/hook.js +32 -23
- package/dist/cjs/base/index.js +41 -34
- package/dist/cjs/base/runJest.js +48 -30
- package/dist/cjs/base/types/index.js +15 -3
- package/dist/cjs/base/utils.js +46 -28
- package/dist/cjs/cli/bff/app.js +33 -25
- package/dist/cjs/cli/bff/constant.js +24 -7
- package/dist/cjs/cli/bff/index.js +48 -29
- package/dist/cjs/cli/bff/mockAPI.js +40 -18
- package/dist/cjs/cli/bff/setup.js +36 -18
- package/dist/cjs/cli/bff/utils/index.js +38 -12
- package/dist/cjs/cli/index.js +56 -40
- package/dist/cjs/cli/test.js +40 -18
- package/dist/cjs/constant.js +24 -7
- package/dist/cjs/index.js +22 -6
- package/dist/cjs/runtime-testing/app.js +38 -17
- package/dist/cjs/runtime-testing/base.js +38 -11
- package/dist/cjs/runtime-testing/bff.js +38 -12
- package/dist/cjs/runtime-testing/customRender.js +36 -14
- package/dist/cjs/runtime-testing/index.js +22 -5
- package/dist/cjs/runtime-testing/reduck.js +55 -38
- package/dist/cjs/runtime-testing/resolvePlugins.js +21 -8
- package/dist/esm/base/config/index.js +6 -2
- package/dist/esm/base/config/patches/assetsModule.js +4 -1
- package/dist/esm/base/config/patches/filemock.js +4 -1
- package/dist/esm/base/config/patches/index.js +4 -1
- package/dist/esm/base/config/patches/transformer.js +4 -1
- package/dist/esm/base/config/resolver.js +31 -22
- package/dist/esm/base/config/testConfigOperator.js +3 -1
- package/dist/esm/base/config/transformer/babelTransformer.js +6 -3
- package/dist/esm/base/hook.js +8 -3
- package/dist/esm/base/index.js +13 -5
- package/dist/esm/base/runJest.js +8 -4
- package/dist/esm/base/types/index.js +0 -1
- package/dist/esm/base/utils.js +8 -3
- package/dist/esm/cli/bff/app.js +10 -5
- package/dist/esm/cli/bff/constant.js +4 -1
- package/dist/esm/cli/bff/index.js +17 -13
- package/dist/esm/cli/bff/mockAPI.js +4 -1
- package/dist/esm/cli/bff/setup.js +5 -5
- package/dist/esm/cli/bff/utils/index.js +4 -1
- package/dist/esm/cli/index.js +10 -4
- package/dist/esm/cli/test.js +7 -4
- package/dist/esm/constant.js +4 -1
- package/dist/esm/runtime-testing/app.js +4 -1
- package/dist/esm/runtime-testing/base.js +4 -1
- package/dist/esm/runtime-testing/bff.js +3 -1
- package/dist/esm/runtime-testing/customRender.js +4 -1
- package/dist/esm/runtime-testing/reduck.js +16 -10
- package/dist/esm/runtime-testing/resolvePlugins.js +4 -1
- package/dist/esm-node/base/config/index.js +6 -2
- package/dist/esm-node/base/config/patches/assetsModule.js +4 -1
- package/dist/esm-node/base/config/patches/filemock.js +4 -1
- package/dist/esm-node/base/config/patches/index.js +4 -1
- package/dist/esm-node/base/config/patches/transformer.js +4 -1
- package/dist/esm-node/base/config/resolver.js +29 -20
- package/dist/esm-node/base/config/testConfigOperator.js +3 -1
- package/dist/esm-node/base/config/transformer/babelTransformer.js +6 -3
- package/dist/esm-node/base/hook.js +8 -3
- package/dist/esm-node/base/index.js +13 -5
- package/dist/esm-node/base/runJest.js +7 -4
- package/dist/esm-node/base/types/index.js +0 -1
- package/dist/esm-node/base/utils.js +8 -3
- package/dist/esm-node/cli/bff/app.js +7 -2
- package/dist/esm-node/cli/bff/constant.js +4 -1
- package/dist/esm-node/cli/bff/index.js +8 -4
- package/dist/esm-node/cli/bff/mockAPI.js +4 -1
- package/dist/esm-node/cli/bff/setup.js +3 -3
- package/dist/esm-node/cli/bff/utils/index.js +4 -1
- package/dist/esm-node/cli/index.js +10 -4
- package/dist/esm-node/cli/test.js +7 -4
- package/dist/esm-node/constant.js +4 -1
- package/dist/esm-node/runtime-testing/app.js +4 -1
- package/dist/esm-node/runtime-testing/base.js +4 -1
- package/dist/esm-node/runtime-testing/bff.js +3 -1
- package/dist/esm-node/runtime-testing/customRender.js +4 -1
- package/dist/esm-node/runtime-testing/reduck.js +16 -10
- package/dist/esm-node/runtime-testing/resolvePlugins.js +5 -2
- package/package.json +13 -13
package/dist/cjs/base/runJest.js
CHANGED
@@ -1,30 +1,44 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
6
9
|
for (var name in all)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
return runJest;
|
15
|
-
},
|
16
|
-
runTest: function() {
|
17
|
-
return runTest;
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
18
17
|
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var runJest_exports = {};
|
30
|
+
__export(runJest_exports, {
|
31
|
+
runJest: () => runJest,
|
32
|
+
runTest: () => runTest
|
19
33
|
});
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
34
|
+
module.exports = __toCommonJS(runJest_exports);
|
35
|
+
var import_yargs = __toESM(require("yargs/yargs"));
|
36
|
+
var import_jest = require("jest");
|
37
|
+
var import_utils = require("@modern-js/utils");
|
38
|
+
var import_config = require("./config");
|
39
|
+
var import_utils2 = require("./utils");
|
26
40
|
const buildArgv = async (rawArgv, config) => {
|
27
|
-
const argv = await (0,
|
41
|
+
const argv = await (0, import_yargs.default)(rawArgv).argv;
|
28
42
|
const result = {
|
29
43
|
$0: argv.$0,
|
30
44
|
_: argv._.slice(1)
|
@@ -49,39 +63,43 @@ const readResultsAndExit = (result, globalConfig) => {
|
|
49
63
|
});
|
50
64
|
if (globalConfig.forceExit) {
|
51
65
|
if (!globalConfig.detectOpenHandles) {
|
52
|
-
console.warn(`${
|
66
|
+
console.warn(`${import_utils.chalk.bold("Force exiting Jest: ")}Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?`);
|
53
67
|
}
|
54
68
|
process.exit(code);
|
55
69
|
} else if (!globalConfig.detectOpenHandles) {
|
56
70
|
setTimeout(() => {
|
57
|
-
console.warn(
|
71
|
+
console.warn(import_utils.chalk.yellow.bold("Jest did not exit one second after the test run has completed.\n\n") + import_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."));
|
58
72
|
}, 1e3).unref();
|
59
73
|
}
|
60
74
|
};
|
61
75
|
async function runJest(config, pwd = process.cwd()) {
|
62
76
|
try {
|
63
77
|
const argvConfig = await buildArgv(process.argv.slice(2), config);
|
64
|
-
const { results, globalConfig } = await (0,
|
78
|
+
const { results, globalConfig } = await (0, import_jest.runCLI)(argvConfig, [
|
65
79
|
pwd
|
66
80
|
]);
|
67
81
|
readResultsAndExit(results, globalConfig);
|
68
82
|
} catch (e) {
|
69
|
-
|
70
|
-
console.error(_utils.chalk.red(((_e = e) === null || _e === void 0 ? void 0 : _e.stack) || e));
|
83
|
+
console.error(import_utils.chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
|
71
84
|
process.exit(1);
|
72
85
|
}
|
73
86
|
}
|
74
87
|
async function runTest(api, config, pwd = process.cwd()) {
|
75
88
|
process.env.NODE_ENV = "test";
|
76
|
-
const jestUtils = (0,
|
77
|
-
await (0,
|
89
|
+
const jestUtils = (0, import_config.getJestUtils)(config);
|
90
|
+
await (0, import_config.patchConfig)(jestUtils);
|
78
91
|
jestUtils.setJestUserConfig();
|
79
92
|
const hookRunners = api.useHookRunners();
|
80
93
|
const testConfigOperator = await hookRunners.jestConfig(jestUtils, {
|
81
94
|
onLast: (input) => input
|
82
95
|
});
|
83
96
|
const finalConfig = testConfigOperator.getFinalConfig();
|
84
|
-
(0,
|
97
|
+
(0, import_utils2.debug)("Jest config:", finalConfig);
|
85
98
|
await runJest(finalConfig, pwd);
|
86
99
|
await hookRunners.afterTest();
|
87
100
|
}
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
102
|
+
0 && (module.exports = {
|
103
|
+
runJest,
|
104
|
+
runTest
|
105
|
+
});
|
@@ -1,4 +1,16 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty
|
3
|
-
|
4
|
-
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
8
|
+
for (let key of __getOwnPropNames(from))
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
11
|
+
}
|
12
|
+
return to;
|
13
|
+
};
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
15
|
+
var types_exports = {};
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/cjs/base/utils.js
CHANGED
@@ -1,47 +1,59 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
6
9
|
for (var name in all)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
return debug;
|
15
|
-
},
|
16
|
-
readCompilerOptions: function() {
|
17
|
-
return readCompilerOptions;
|
18
|
-
},
|
19
|
-
getModuleNameMapper: function() {
|
20
|
-
return getModuleNameMapper;
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
21
17
|
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var utils_exports = {};
|
30
|
+
__export(utils_exports, {
|
31
|
+
debug: () => debug,
|
32
|
+
getModuleNameMapper: () => getModuleNameMapper,
|
33
|
+
readCompilerOptions: () => readCompilerOptions
|
22
34
|
});
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
const debug = (0,
|
35
|
+
module.exports = __toCommonJS(utils_exports);
|
36
|
+
var import_fs = __toESM(require("fs"));
|
37
|
+
var import_path = __toESM(require("path"));
|
38
|
+
var import_utils = require("@modern-js/utils");
|
39
|
+
const debug = (0, import_utils.createDebugger)("test");
|
28
40
|
const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
|
29
41
|
let tsConfig = {};
|
30
42
|
let extendedCompilerOptions = {};
|
31
43
|
let tsconfigFile = "";
|
32
44
|
try {
|
33
|
-
const maybeTsconfigFile =
|
34
|
-
if (
|
45
|
+
const maybeTsconfigFile = import_path.default.join(pwd, filename);
|
46
|
+
if (import_fs.default.existsSync(maybeTsconfigFile)) {
|
35
47
|
tsconfigFile = maybeTsconfigFile;
|
36
48
|
} else {
|
37
49
|
tsconfigFile = require.resolve(filename);
|
38
50
|
}
|
39
|
-
({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(tsconfigFile,
|
51
|
+
({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(tsconfigFile, import_fs.default.readFileSync(tsconfigFile, "utf8")));
|
40
52
|
} catch (e) {
|
41
53
|
return {};
|
42
54
|
}
|
43
55
|
if (tsConfig.extends) {
|
44
|
-
extendedCompilerOptions = readCompilerOptions(
|
56
|
+
extendedCompilerOptions = readCompilerOptions(import_path.default.dirname(tsconfigFile), tsConfig.extends);
|
45
57
|
}
|
46
58
|
return {
|
47
59
|
...extendedCompilerOptions,
|
@@ -61,7 +73,13 @@ const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) =>
|
|
61
73
|
memo[cur] = aliasValue[0];
|
62
74
|
}
|
63
75
|
const key = `^${cur}/(.*)$`;
|
64
|
-
const value =
|
76
|
+
const value = import_path.default.normalize(`${aliasValue}/$1`);
|
65
77
|
memo[key] = value;
|
66
78
|
return memo;
|
67
79
|
}, {});
|
80
|
+
// Annotate the CommonJS export names for ESM import in node:
|
81
|
+
0 && (module.exports = {
|
82
|
+
debug,
|
83
|
+
getModuleNameMapper,
|
84
|
+
readCompilerOptions
|
85
|
+
});
|
package/dist/cjs/cli/bff/app.js
CHANGED
@@ -1,37 +1,38 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
6
7
|
for (var name in all)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
return isInHandler;
|
15
|
-
},
|
16
|
-
createApp: function() {
|
17
|
-
return createApp;
|
18
|
-
},
|
19
|
-
getApp: function() {
|
20
|
-
return getApp;
|
21
|
-
},
|
22
|
-
closeServer: function() {
|
23
|
-
return closeServer;
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
24
15
|
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var app_exports = {};
|
20
|
+
__export(app_exports, {
|
21
|
+
closeServer: () => closeServer,
|
22
|
+
createApp: () => createApp,
|
23
|
+
getApp: () => getApp,
|
24
|
+
isInHandler: () => isInHandler
|
25
25
|
});
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
module.exports = __toCommonJS(app_exports);
|
27
|
+
var import_async_hooks = require("async_hooks");
|
28
|
+
var import_prod_server = require("@modern-js/prod-server");
|
29
|
+
const store = new import_async_hooks.AsyncLocalStorage();
|
29
30
|
const isInHandler = () => Boolean(store.getStore());
|
30
31
|
let server = null;
|
31
32
|
const createApp = async (pwd, config, plugins, routes) => {
|
32
33
|
if (!server) {
|
33
34
|
config.output.path = "./";
|
34
|
-
server = new
|
35
|
+
server = new import_prod_server.Server({
|
35
36
|
apiOnly: true,
|
36
37
|
pwd,
|
37
38
|
config,
|
@@ -55,3 +56,10 @@ const closeServer = async () => {
|
|
55
56
|
}
|
56
57
|
await server.close();
|
57
58
|
};
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
60
|
+
0 && (module.exports = {
|
61
|
+
closeServer,
|
62
|
+
createApp,
|
63
|
+
getApp,
|
64
|
+
isInHandler
|
65
|
+
});
|
@@ -1,11 +1,28 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.defineProperty
|
3
|
-
|
4
|
-
|
5
|
-
Object.
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
9
15
|
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var constant_exports = {};
|
20
|
+
__export(constant_exports, {
|
21
|
+
bff_info_key: () => bff_info_key
|
10
22
|
});
|
23
|
+
module.exports = __toCommonJS(constant_exports);
|
11
24
|
const bff_info_key = "modern_bff_info";
|
25
|
+
// Annotate the CommonJS export names for ESM import in node:
|
26
|
+
0 && (module.exports = {
|
27
|
+
bff_info_key
|
28
|
+
});
|
@@ -1,32 +1,46 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
6
9
|
for (var name in all)
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
return setJestConfigForBFF;
|
15
|
-
},
|
16
|
-
testingBffPlugin: function() {
|
17
|
-
return testingBffPlugin;
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
18
17
|
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var bff_exports = {};
|
30
|
+
__export(bff_exports, {
|
31
|
+
setJestConfigForBFF: () => setJestConfigForBFF,
|
32
|
+
testingBffPlugin: () => testingBffPlugin
|
19
33
|
});
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
34
|
+
module.exports = __toCommonJS(bff_exports);
|
35
|
+
var import_path = __toESM(require("path"));
|
36
|
+
var import_utils = require("@modern-js/utils");
|
37
|
+
var import_base = require("../../base");
|
38
|
+
var import_constant = require("./constant");
|
39
|
+
var import_utils2 = require("./utils");
|
26
40
|
const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils }) => {
|
27
|
-
var _userConfig_source
|
41
|
+
var _userConfig_source;
|
28
42
|
const bffConfig = {
|
29
|
-
rootDir:
|
43
|
+
rootDir: import_path.default.join(pwd, "./api"),
|
30
44
|
setupFilesAfterEnv: [
|
31
45
|
require.resolve("./setup")
|
32
46
|
],
|
@@ -38,7 +52,7 @@ const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils })
|
|
38
52
|
"config.test.ts"
|
39
53
|
],
|
40
54
|
globals: {
|
41
|
-
[
|
55
|
+
[import_constant.bff_info_key]: {
|
42
56
|
appDir: pwd,
|
43
57
|
modernUserConfig: userConfig,
|
44
58
|
plugins,
|
@@ -47,8 +61,8 @@ const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils })
|
|
47
61
|
}
|
48
62
|
};
|
49
63
|
const { jestConfig } = utils;
|
50
|
-
const alias = (
|
51
|
-
const aliasMapper = (0,
|
64
|
+
const alias = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.alias) || {};
|
65
|
+
const aliasMapper = (0, import_base.getModuleNameMapper)(alias);
|
52
66
|
const { moduleNameMapper } = jestConfig;
|
53
67
|
const transform = {
|
54
68
|
"\\.[jt]sx?$": [
|
@@ -60,12 +74,12 @@ const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils })
|
|
60
74
|
}
|
61
75
|
]
|
62
76
|
};
|
63
|
-
const apiOnly = await (0,
|
77
|
+
const apiOnly = await (0, import_utils.isApiOnly)(pwd);
|
64
78
|
const mergedModuleNameMapper = {
|
65
79
|
...moduleNameMapper,
|
66
80
|
...aliasMapper
|
67
81
|
};
|
68
|
-
const resolver = jestConfig.resolver ||
|
82
|
+
const resolver = jestConfig.resolver || import_base.DEFAULT_RESOLVER_PATH;
|
69
83
|
const configFields = [
|
70
84
|
"coverage",
|
71
85
|
"collectCoverage",
|
@@ -116,7 +130,7 @@ const testingBffPlugin = () => ({
|
|
116
130
|
jestConfig: async (utils, next) => {
|
117
131
|
const appContext = api.useAppContext();
|
118
132
|
const pwd = appContext.appDirectory;
|
119
|
-
if (!(0,
|
133
|
+
if (!(0, import_utils2.isBFFProject)(pwd)) {
|
120
134
|
return next(utils);
|
121
135
|
}
|
122
136
|
const userConfig = api.useResolvedConfigContext();
|
@@ -132,3 +146,8 @@ const testingBffPlugin = () => ({
|
|
132
146
|
};
|
133
147
|
}
|
134
148
|
});
|
149
|
+
// Annotate the CommonJS export names for ESM import in node:
|
150
|
+
0 && (module.exports = {
|
151
|
+
setJestConfigForBFF,
|
152
|
+
testingBffPlugin
|
153
|
+
});
|
@@ -1,26 +1,48 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.
|
3
|
-
|
4
|
-
|
5
|
-
Object.
|
6
|
-
|
7
|
-
|
8
|
-
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
9
17
|
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var mockAPI_exports = {};
|
30
|
+
__export(mockAPI_exports, {
|
31
|
+
default: () => mockAPI_default
|
10
32
|
});
|
11
|
-
|
12
|
-
|
13
|
-
|
33
|
+
module.exports = __toCommonJS(mockAPI_exports);
|
34
|
+
var ptr = __toESM(require("path-to-regexp"));
|
35
|
+
var mockAppModule = __toESM(require("./app"));
|
14
36
|
const mock_replaceUrlWithParams = (url, paramValues, payload) => {
|
15
37
|
const keys = [];
|
16
|
-
|
38
|
+
ptr.pathToRegexp(url, keys);
|
17
39
|
const params = keys.reduce((cur, key, index) => {
|
18
40
|
if (paramValues[index]) {
|
19
41
|
cur[key.name] = paramValues[index];
|
20
42
|
}
|
21
43
|
return cur;
|
22
44
|
}, {});
|
23
|
-
const getFinalPath =
|
45
|
+
const getFinalPath = ptr.compile(url, {
|
24
46
|
encode: encodeURIComponent
|
25
47
|
});
|
26
48
|
return getFinalPath({
|
@@ -56,21 +78,21 @@ const mock_getParamsAndPayload = (args) => {
|
|
56
78
|
}
|
57
79
|
}
|
58
80
|
};
|
59
|
-
|
81
|
+
var mockAPI_default = (mockApiInfosByFile) => {
|
60
82
|
const files = Object.keys(mockApiInfosByFile);
|
61
83
|
files.forEach((mockedFile) => {
|
62
84
|
jest.mock(mockedFile, () => {
|
63
85
|
const supertest = require("supertest");
|
64
86
|
return mockApiInfosByFile[mockedFile].reduce((res, info) => {
|
65
|
-
const
|
87
|
+
const module2 = {
|
66
88
|
[info.name]: (...args) => {
|
67
|
-
if (
|
89
|
+
if (mockAppModule.isInHandler()) {
|
68
90
|
return info.handler(...args);
|
69
91
|
}
|
70
92
|
const [params, payload] = mock_getParamsAndPayload(args);
|
71
|
-
const { returnHttp } =
|
93
|
+
const { returnHttp } = module2[info.name];
|
72
94
|
const url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
|
73
|
-
const app =
|
95
|
+
const app = mockAppModule.getApp();
|
74
96
|
let test = supertest(app)[info.httpMethod.toLowerCase()](url);
|
75
97
|
if (payload.query) {
|
76
98
|
test = test.query(payload.query);
|
@@ -103,7 +125,7 @@ const _default = (mockApiInfosByFile) => {
|
|
103
125
|
});
|
104
126
|
}
|
105
127
|
};
|
106
|
-
res[info.name] =
|
128
|
+
res[info.name] = module2[info.name];
|
107
129
|
Object.assign(res[info.name], info.handler);
|
108
130
|
res.__esModule = true;
|
109
131
|
return res;
|
@@ -1,28 +1,46 @@
|
|
1
1
|
"use strict";
|
2
|
-
Object.
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
10
|
+
for (let key of __getOwnPropNames(from))
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
13
|
+
}
|
14
|
+
return to;
|
15
|
+
};
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
22
|
+
mod
|
23
|
+
));
|
24
|
+
var import_path = __toESM(require("path"));
|
25
|
+
var import_bff_core = require("@modern-js/bff-core");
|
26
|
+
var import_constant = require("./constant");
|
27
|
+
var import_mockAPI = __toESM(require("./mockAPI"));
|
28
|
+
var import_app = require("./app");
|
11
29
|
let uped = false;
|
12
30
|
const setup = () => {
|
13
|
-
var _bff_info_modernUserConfig_bff, _bff_info_modernUserConfig,
|
31
|
+
var _bff_info_modernUserConfig_bff, _bff_info_modernUserConfig, _bff_info_modernUserConfig_bff1, _bff_info_modernUserConfig1;
|
14
32
|
if (uped) {
|
15
33
|
return;
|
16
34
|
}
|
17
35
|
uped = true;
|
18
|
-
const bff_info = global[
|
19
|
-
const prefix =
|
20
|
-
const httpMethodDecider =
|
36
|
+
const bff_info = global[import_constant.bff_info_key];
|
37
|
+
const prefix = bff_info === null || bff_info === void 0 ? void 0 : (_bff_info_modernUserConfig = bff_info.modernUserConfig) === null || _bff_info_modernUserConfig === void 0 ? void 0 : (_bff_info_modernUserConfig_bff = _bff_info_modernUserConfig.bff) === null || _bff_info_modernUserConfig_bff === void 0 ? void 0 : _bff_info_modernUserConfig_bff.prefix;
|
38
|
+
const httpMethodDecider = bff_info === null || bff_info === void 0 ? void 0 : (_bff_info_modernUserConfig1 = bff_info.modernUserConfig) === null || _bff_info_modernUserConfig1 === void 0 ? void 0 : (_bff_info_modernUserConfig_bff1 = _bff_info_modernUserConfig1.bff) === null || _bff_info_modernUserConfig_bff1 === void 0 ? void 0 : _bff_info_modernUserConfig_bff1.httpMethodDecider;
|
21
39
|
let app = null;
|
22
40
|
beforeAll(async () => {
|
23
|
-
const apiRouter = new
|
41
|
+
const apiRouter = new import_bff_core.ApiRouter({
|
24
42
|
appDir: bff_info.appDir,
|
25
|
-
apiDir:
|
43
|
+
apiDir: import_path.default.join(bff_info.appDir, "./api"),
|
26
44
|
prefix,
|
27
45
|
httpMethodDecider
|
28
46
|
});
|
@@ -34,13 +52,13 @@ const setup = () => {
|
|
34
52
|
res[apiInfo.filename].push(apiInfo);
|
35
53
|
return res;
|
36
54
|
}, {});
|
37
|
-
(0,
|
55
|
+
(0, import_mockAPI.default)(apiInfosByFile);
|
38
56
|
if (!app) {
|
39
|
-
app = await (0,
|
57
|
+
app = await (0, import_app.createApp)(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
|
40
58
|
}
|
41
59
|
});
|
42
60
|
afterAll(async () => {
|
43
|
-
await (0,
|
61
|
+
await (0, import_app.closeServer)();
|
44
62
|
});
|
45
63
|
};
|
46
64
|
setup();
|