@modern-js/plugin-testing 2.21.2-alpha.1 → 2.22.1

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/package.json +12 -13
  3. package/dist/js/modern/base/config/index.js +0 -36
  4. package/dist/js/modern/base/config/patches/assetsModule.js +0 -11
  5. package/dist/js/modern/base/config/patches/filemock.js +0 -4
  6. package/dist/js/modern/base/config/patches/index.js +0 -34
  7. package/dist/js/modern/base/config/patches/transformer.js +0 -38
  8. package/dist/js/modern/base/config/resolver.js +0 -21
  9. package/dist/js/modern/base/config/testConfigOperator.js +0 -69
  10. package/dist/js/modern/base/config/transformer/babelTransformer.js +0 -19
  11. package/dist/js/modern/base/hook.js +0 -12
  12. package/dist/js/modern/base/index.js +0 -14
  13. package/dist/js/modern/base/runJest.js +0 -102
  14. package/dist/js/modern/base/types/index.js +0 -0
  15. package/dist/js/modern/base/utils.js +0 -66
  16. package/dist/js/modern/cli/bff/app.js +0 -58
  17. package/dist/js/modern/cli/bff/constant.js +0 -4
  18. package/dist/js/modern/cli/bff/index.js +0 -149
  19. package/dist/js/modern/cli/bff/mockAPI.js +0 -109
  20. package/dist/js/modern/cli/bff/setup.js +0 -75
  21. package/dist/js/modern/cli/bff/utils/index.js +0 -37
  22. package/dist/js/modern/cli/index.js +0 -115
  23. package/dist/js/modern/cli/test.js +0 -61
  24. package/dist/js/modern/constant.js +0 -4
  25. package/dist/js/modern/index.js +0 -3
  26. package/dist/js/modern/runtime-testing/app.js +0 -48
  27. package/dist/js/modern/runtime-testing/base.js +0 -7
  28. package/dist/js/modern/runtime-testing/customRender.js +0 -25
  29. package/dist/js/modern/runtime-testing/index.js +0 -2
  30. package/dist/js/modern/runtime-testing/reduck.js +0 -55
  31. package/dist/js/modern/runtime-testing/request.js +0 -16
  32. package/dist/js/modern/runtime-testing/resolvePlugins.js +0 -33
  33. package/dist/js/node/base/config/index.js +0 -67
  34. package/dist/js/node/base/config/patches/assetsModule.js +0 -40
  35. package/dist/js/node/base/config/patches/filemock.js +0 -25
  36. package/dist/js/node/base/config/patches/index.js +0 -57
  37. package/dist/js/node/base/config/patches/transformer.js +0 -67
  38. package/dist/js/node/base/config/resolver.js +0 -30
  39. package/dist/js/node/base/config/testConfigOperator.js +0 -90
  40. package/dist/js/node/base/config/transformer/babelTransformer.js +0 -46
  41. package/dist/js/node/base/hook.js +0 -37
  42. package/dist/js/node/base/index.js +0 -43
  43. package/dist/js/node/base/runJest.js +0 -132
  44. package/dist/js/node/base/types/index.js +0 -15
  45. package/dist/js/node/base/utils.js +0 -95
  46. package/dist/js/node/cli/bff/app.js +0 -84
  47. package/dist/js/node/cli/bff/constant.js +0 -27
  48. package/dist/js/node/cli/bff/index.js +0 -173
  49. package/dist/js/node/cli/bff/mockAPI.js +0 -134
  50. package/dist/js/node/cli/bff/setup.js +0 -84
  51. package/dist/js/node/cli/bff/utils/index.js +0 -64
  52. package/dist/js/node/cli/index.js +0 -135
  53. package/dist/js/node/cli/test.js +0 -88
  54. package/dist/js/node/constant.js +0 -27
  55. package/dist/js/node/index.js +0 -19
  56. package/dist/js/node/runtime-testing/app.js +0 -73
  57. package/dist/js/node/runtime-testing/base.js +0 -38
  58. package/dist/js/node/runtime-testing/customRender.js +0 -50
  59. package/dist/js/node/runtime-testing/index.js +0 -18
  60. package/dist/js/node/runtime-testing/reduck.js +0 -85
  61. package/dist/js/node/runtime-testing/request.js +0 -45
  62. package/dist/js/node/runtime-testing/resolvePlugins.js +0 -52
  63. package/dist/js/treeshaking/base/config/index.js +0 -154
  64. package/dist/js/treeshaking/base/config/patches/assetsModule.js +0 -9
  65. package/dist/js/treeshaking/base/config/patches/filemock.js +0 -2
  66. package/dist/js/treeshaking/base/config/patches/index.js +0 -225
  67. package/dist/js/treeshaking/base/config/patches/transformer.js +0 -36
  68. package/dist/js/treeshaking/base/config/resolver.js +0 -37
  69. package/dist/js/treeshaking/base/config/testConfigOperator.js +0 -127
  70. package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +0 -17
  71. package/dist/js/treeshaking/base/hook.js +0 -8
  72. package/dist/js/treeshaking/base/index.js +0 -7
  73. package/dist/js/treeshaking/base/runJest.js +0 -292
  74. package/dist/js/treeshaking/base/types/index.js +0 -1
  75. package/dist/js/treeshaking/base/utils.js +0 -76
  76. package/dist/js/treeshaking/cli/bff/app.js +0 -200
  77. package/dist/js/treeshaking/cli/bff/constant.js +0 -2
  78. package/dist/js/treeshaking/cli/bff/index.js +0 -297
  79. package/dist/js/treeshaking/cli/bff/mockAPI.js +0 -188
  80. package/dist/js/treeshaking/cli/bff/setup.js +0 -192
  81. package/dist/js/treeshaking/cli/bff/utils/index.js +0 -47
  82. package/dist/js/treeshaking/cli/index.js +0 -255
  83. package/dist/js/treeshaking/cli/test.js +0 -180
  84. package/dist/js/treeshaking/constant.js +0 -2
  85. package/dist/js/treeshaking/index.js +0 -3
  86. package/dist/js/treeshaking/runtime-testing/app.js +0 -90
  87. package/dist/js/treeshaking/runtime-testing/base.js +0 -4
  88. package/dist/js/treeshaking/runtime-testing/customRender.js +0 -41
  89. package/dist/js/treeshaking/runtime-testing/index.js +0 -2
  90. package/dist/js/treeshaking/runtime-testing/reduck.js +0 -89
  91. package/dist/js/treeshaking/runtime-testing/request.js +0 -51
  92. package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +0 -46
@@ -1,132 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
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
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
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
- var runJest_exports = {};
45
- __export(runJest_exports, {
46
- runJest: () => runJest,
47
- runTest: () => runTest
48
- });
49
- module.exports = __toCommonJS(runJest_exports);
50
- var import_yargs = __toESM(require("yargs/yargs"));
51
- var import_jest = require("jest");
52
- var import_utils = require("@modern-js/utils");
53
- var import_config = require("./config");
54
- var import_utils2 = require("./utils");
55
- const buildArgv = (rawArgv, config) => __async(void 0, null, function* () {
56
- const argv = yield (0, import_yargs.default)(rawArgv).argv;
57
- const result = {
58
- $0: argv.$0,
59
- _: argv._.slice(1)
60
- };
61
- Object.keys(argv).forEach((key) => {
62
- if (key.includes("-") || key === "_") {
63
- return;
64
- }
65
- result[key] = argv[key];
66
- });
67
- if (config) {
68
- result.config = JSON.stringify(config);
69
- }
70
- return result;
71
- });
72
- const readResultsAndExit = (result, globalConfig) => {
73
- const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
74
- process.on("exit", () => {
75
- if (typeof code === "number" && code !== 0) {
76
- process.exitCode = code;
77
- }
78
- });
79
- if (globalConfig.forceExit) {
80
- if (!globalConfig.detectOpenHandles) {
81
- console.warn(
82
- `${import_utils.chalk.bold(
83
- "Force exiting Jest: "
84
- )}Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?`
85
- );
86
- }
87
- process.exit(code);
88
- } else if (!globalConfig.detectOpenHandles) {
89
- setTimeout(() => {
90
- console.warn(
91
- import_utils.chalk.yellow.bold(
92
- "Jest did not exit one second after the test run has completed.\n\n"
93
- ) + import_utils.chalk.yellow(
94
- "This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue."
95
- )
96
- );
97
- }, 1e3).unref();
98
- }
99
- };
100
- function runJest(_0) {
101
- return __async(this, arguments, function* (config, pwd = process.cwd()) {
102
- try {
103
- const argvConfig = yield buildArgv(process.argv.slice(2), config);
104
- const { results, globalConfig } = yield (0, import_jest.runCLI)(argvConfig, [pwd]);
105
- readResultsAndExit(results, globalConfig);
106
- } catch (e) {
107
- console.error(import_utils.chalk.red((e == null ? void 0 : e.stack) || e));
108
- process.exit(1);
109
- }
110
- });
111
- }
112
- function runTest(_0, _1) {
113
- return __async(this, arguments, function* (api, config, pwd = process.cwd()) {
114
- process.env.NODE_ENV = "test";
115
- const jestUtils = (0, import_config.getJestUtils)(config);
116
- yield (0, import_config.patchConfig)(jestUtils);
117
- jestUtils.setJestUserConfig();
118
- const hookRunners = api.useHookRunners();
119
- const testConfigOperator = yield hookRunners.jestConfig(jestUtils, {
120
- onLast: (input) => input
121
- });
122
- const finalConfig = testConfigOperator.getFinalConfig();
123
- (0, import_utils2.debug)("Jest config:", finalConfig);
124
- yield runJest(finalConfig, pwd);
125
- yield hookRunners.afterTest();
126
- });
127
- }
128
- // Annotate the CommonJS export names for ESM import in node:
129
- 0 && (module.exports = {
130
- runJest,
131
- runTest
132
- });
@@ -1,15 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
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,95 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- 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
- var __export = (target, all) => {
22
- for (var name in all)
23
- __defProp(target, name, { get: all[name], enumerable: true });
24
- };
25
- var __copyProps = (to, from, except, desc) => {
26
- if (from && typeof from === "object" || typeof from === "function") {
27
- for (let key of __getOwnPropNames(from))
28
- if (!__hasOwnProp.call(to, key) && key !== except)
29
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
- }
31
- return to;
32
- };
33
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var utils_exports = {};
39
- __export(utils_exports, {
40
- debug: () => debug,
41
- getModuleNameMapper: () => getModuleNameMapper,
42
- readCompilerOptions: () => readCompilerOptions
43
- });
44
- module.exports = __toCommonJS(utils_exports);
45
- var import_fs = __toESM(require("fs"));
46
- var import_path = __toESM(require("path"));
47
- var import_utils = require("@modern-js/utils");
48
- const debug = (0, import_utils.createDebugger)("test");
49
- const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
50
- let tsConfig = {};
51
- let extendedCompilerOptions = {};
52
- let tsconfigFile = "";
53
- try {
54
- const maybeTsconfigFile = import_path.default.join(pwd, filename);
55
- if (import_fs.default.existsSync(maybeTsconfigFile)) {
56
- tsconfigFile = maybeTsconfigFile;
57
- } else {
58
- tsconfigFile = require.resolve(filename);
59
- }
60
- ({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(
61
- tsconfigFile,
62
- import_fs.default.readFileSync(tsconfigFile, "utf8")
63
- ));
64
- } catch (e) {
65
- return {};
66
- }
67
- if (tsConfig.extends) {
68
- extendedCompilerOptions = readCompilerOptions(
69
- import_path.default.dirname(tsconfigFile),
70
- tsConfig.extends
71
- );
72
- }
73
- return __spreadValues(__spreadValues({}, extendedCompilerOptions), tsConfig.compilerOptions);
74
- };
75
- const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
76
- const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
77
- const isFile = aliasValue.some((s) => s.endsWith(".js"));
78
- if (cur === "@modern-js/runtime$") {
79
- memo[`.+${cur}`] = aliasValue[0];
80
- return memo;
81
- }
82
- if (isFile) {
83
- memo[cur] = aliasValue[0];
84
- }
85
- const key = `^${cur}/(.*)$`;
86
- const value = import_path.default.normalize(`${aliasValue}/$1`);
87
- memo[key] = value;
88
- return memo;
89
- }, {});
90
- // Annotate the CommonJS export names for ESM import in node:
91
- 0 && (module.exports = {
92
- debug,
93
- getModuleNameMapper,
94
- readCompilerOptions
95
- });
@@ -1,84 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
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 __async = (__this, __arguments, generator) => {
19
- return new Promise((resolve, reject) => {
20
- var fulfilled = (value) => {
21
- try {
22
- step(generator.next(value));
23
- } catch (e) {
24
- reject(e);
25
- }
26
- };
27
- var rejected = (value) => {
28
- try {
29
- step(generator.throw(value));
30
- } catch (e) {
31
- reject(e);
32
- }
33
- };
34
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
35
- step((generator = generator.apply(__this, __arguments)).next());
36
- });
37
- };
38
- var app_exports = {};
39
- __export(app_exports, {
40
- closeServer: () => closeServer,
41
- createApp: () => createApp,
42
- getApp: () => getApp,
43
- isInHandler: () => isInHandler
44
- });
45
- module.exports = __toCommonJS(app_exports);
46
- var import_async_hooks = require("async_hooks");
47
- var import_prod_server = require("@modern-js/prod-server");
48
- const store = new import_async_hooks.AsyncLocalStorage();
49
- const isInHandler = () => Boolean(store.getStore());
50
- let server = null;
51
- const createApp = (pwd, config, plugins, routes) => __async(void 0, null, function* () {
52
- if (!server) {
53
- config.output.path = "./";
54
- server = new import_prod_server.Server({
55
- apiOnly: true,
56
- pwd,
57
- config,
58
- internalPlugins: plugins,
59
- routes
60
- });
61
- yield server.init();
62
- }
63
- const app = server.getRequestHandler();
64
- return app;
65
- });
66
- const getApp = () => {
67
- if (!server) {
68
- throw new Error("please createApp first");
69
- }
70
- return server.getRequestHandler();
71
- };
72
- const closeServer = () => __async(void 0, null, function* () {
73
- if (!server) {
74
- throw new Error("please createApp first");
75
- }
76
- yield server.close();
77
- });
78
- // Annotate the CommonJS export names for ESM import in node:
79
- 0 && (module.exports = {
80
- closeServer,
81
- createApp,
82
- getApp,
83
- isInHandler
84
- });
@@ -1,27 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
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
21
- });
22
- module.exports = __toCommonJS(constant_exports);
23
- const bff_info_key = "modern_bff_info";
24
- // Annotate the CommonJS export names for ESM import in node:
25
- 0 && (module.exports = {
26
- bff_info_key
27
- });
@@ -1,173 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- 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
- var __export = (target, all) => {
22
- for (var name in all)
23
- __defProp(target, name, { get: all[name], enumerable: true });
24
- };
25
- var __copyProps = (to, from, except, desc) => {
26
- if (from && typeof from === "object" || typeof from === "function") {
27
- for (let key of __getOwnPropNames(from))
28
- if (!__hasOwnProp.call(to, key) && key !== except)
29
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
- }
31
- return to;
32
- };
33
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var __async = (__this, __arguments, generator) => {
39
- return new Promise((resolve, reject) => {
40
- var fulfilled = (value) => {
41
- try {
42
- step(generator.next(value));
43
- } catch (e) {
44
- reject(e);
45
- }
46
- };
47
- var rejected = (value) => {
48
- try {
49
- step(generator.throw(value));
50
- } catch (e) {
51
- reject(e);
52
- }
53
- };
54
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
55
- step((generator = generator.apply(__this, __arguments)).next());
56
- });
57
- };
58
- var bff_exports = {};
59
- __export(bff_exports, {
60
- default: () => bff_default,
61
- setJestConfigForBFF: () => setJestConfigForBFF
62
- });
63
- module.exports = __toCommonJS(bff_exports);
64
- var import_path = __toESM(require("path"));
65
- var import_utils = require("@modern-js/utils");
66
- var import_base = require("../../base");
67
- var import_constant = require("./constant");
68
- var import_utils2 = require("./utils");
69
- const setJestConfigForBFF = (_0) => __async(void 0, [_0], function* ({
70
- pwd,
71
- userConfig,
72
- plugins,
73
- routes,
74
- utils
75
- }) {
76
- var _a;
77
- const bffConfig = {
78
- rootDir: import_path.default.join(pwd, "./api"),
79
- setupFilesAfterEnv: [require.resolve("./setup")],
80
- testEnvironment: "node",
81
- testMatch: [`**/api/**/*.test.[jt]s`],
82
- globals: {
83
- "ts-jest": {
84
- diagnostics: {
85
- warnOnly: true
86
- }
87
- },
88
- [import_constant.bff_info_key]: {
89
- appDir: pwd,
90
- modernUserConfig: userConfig,
91
- plugins,
92
- routes
93
- }
94
- }
95
- };
96
- const { jestConfig } = utils;
97
- const alias = ((_a = userConfig == null ? void 0 : userConfig.source) == null ? void 0 : _a.alias) || {};
98
- const aliasMapper = (0, import_base.getModuleNameMapper)(alias);
99
- const { moduleNameMapper } = jestConfig;
100
- const transform = {
101
- "\\.[jt]sx?$": require.resolve("ts-jest")
102
- };
103
- const apiOnly = yield (0, import_utils.isApiOnly)(pwd);
104
- const mergedModuleNameMapper = __spreadValues(__spreadValues({}, moduleNameMapper), aliasMapper);
105
- const resolver = jestConfig.resolver || import_base.DEFAULT_RESOLVER_PATH;
106
- const configFields = ["coverage", "collectCoverage", "testTimeout"];
107
- const commonConfig = configFields.reduce((obj, field) => {
108
- if (jestConfig.hasOwnProperty(field)) {
109
- obj[field] = jestConfig[field];
110
- }
111
- return obj;
112
- }, {});
113
- if (!apiOnly) {
114
- utils.setJestConfig(
115
- {
116
- projects: [
117
- __spreadValues({}, jestConfig),
118
- __spreadValues({
119
- transform,
120
- moduleNameMapper: mergedModuleNameMapper,
121
- resolver
122
- }, bffConfig)
123
- ]
124
- },
125
- {
126
- force: true
127
- }
128
- );
129
- } else {
130
- utils.setJestConfig(
131
- {
132
- projects: [
133
- __spreadValues({
134
- transform,
135
- moduleNameMapper: mergedModuleNameMapper,
136
- resolver
137
- }, bffConfig)
138
- ]
139
- },
140
- {
141
- force: true
142
- }
143
- );
144
- }
145
- utils.setJestConfig(commonConfig);
146
- });
147
- var bff_default = () => ({
148
- name: "@modern-js/testing-plugin-bff",
149
- setup(api) {
150
- return {
151
- jestConfig: (utils, next) => __async(this, null, function* () {
152
- const appContext = api.useAppContext();
153
- const pwd = appContext.appDirectory;
154
- if (!(0, import_utils2.isBFFProject)(pwd)) {
155
- return next(utils);
156
- }
157
- const userConfig = api.useResolvedConfigContext();
158
- yield setJestConfigForBFF({
159
- pwd,
160
- userConfig,
161
- routes: appContext.serverRoutes,
162
- plugins: appContext.serverInternalPlugins,
163
- utils
164
- });
165
- return next(utils);
166
- })
167
- };
168
- }
169
- });
170
- // Annotate the CommonJS export names for ESM import in node:
171
- 0 && (module.exports = {
172
- setJestConfigForBFF
173
- });
@@ -1,134 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- 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
- var __export = (target, all) => {
22
- for (var name in all)
23
- __defProp(target, name, { get: all[name], enumerable: true });
24
- };
25
- var __copyProps = (to, from, except, desc) => {
26
- if (from && typeof from === "object" || typeof from === "function") {
27
- for (let key of __getOwnPropNames(from))
28
- if (!__hasOwnProp.call(to, key) && key !== except)
29
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
30
- }
31
- return to;
32
- };
33
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
- var mockAPI_exports = {};
39
- __export(mockAPI_exports, {
40
- default: () => mockAPI_default
41
- });
42
- module.exports = __toCommonJS(mockAPI_exports);
43
- var ptr = __toESM(require("path-to-regexp"));
44
- var mockAppModule = __toESM(require("./app"));
45
- const mock_replaceUrlWithParams = (url, paramValues, payload) => {
46
- const keys = [];
47
- ptr.pathToRegexp(url, keys);
48
- const params = keys.reduce((cur, key, index) => {
49
- if (paramValues[index]) {
50
- cur[key.name] = paramValues[index];
51
- }
52
- return cur;
53
- }, {});
54
- const getFinalPath = ptr.compile(url, { encode: encodeURIComponent });
55
- return getFinalPath(__spreadValues(__spreadValues({}, params), payload));
56
- };
57
- const mock_getParamsAndPayload = (args) => {
58
- if (args.length === 0) {
59
- return [[], {}];
60
- }
61
- const head = args[0];
62
- if (typeof head === "object") {
63
- return [[], head];
64
- } else {
65
- const latest = args[args.length - 1];
66
- if (typeof latest === "object") {
67
- return [args.slice(0, args.length - 1), latest];
68
- } else {
69
- return [args, {}];
70
- }
71
- }
72
- };
73
- var mockAPI_default = (mockApiInfosByFile) => {
74
- const files = Object.keys(mockApiInfosByFile);
75
- files.forEach((mockedFile) => {
76
- jest.mock(mockedFile, () => {
77
- const supertest = require("supertest");
78
- return mockApiInfosByFile[mockedFile].reduce(
79
- (res, info) => {
80
- const module2 = {
81
- [info.name]: (...args) => {
82
- if (mockAppModule.isInHandler()) {
83
- return info.handler(...args);
84
- }
85
- const [params, payload] = mock_getParamsAndPayload(args);
86
- const { returnHttp } = module2[info.name];
87
- const url = mock_replaceUrlWithParams(
88
- info.routePath,
89
- params,
90
- payload.params
91
- );
92
- const app = mockAppModule.getApp();
93
- let test = supertest(app)[info.httpMethod.toLowerCase()](url);
94
- if (payload.query) {
95
- test = test.query(payload.query);
96
- }
97
- if (payload.body) {
98
- test = test.send(payload.body);
99
- }
100
- if (payload.data) {
101
- test = test.send(payload.data);
102
- }
103
- if (payload.headers) {
104
- for (const name in payload.headers) {
105
- test = test.set(name, payload.headers[name]);
106
- }
107
- }
108
- if (payload.cookies) {
109
- test = test.set("Cookie", [payload.cookies]);
110
- }
111
- if (returnHttp) {
112
- return test;
113
- }
114
- return test.then((value) => {
115
- try {
116
- return JSON.parse(value.text);
117
- } catch (e) {
118
- return value.text;
119
- }
120
- });
121
- }
122
- };
123
- res[info.name] = module2[info.name];
124
- Object.assign(res[info.name], info.handler);
125
- res.__esModule = true;
126
- return res;
127
- },
128
- {}
129
- );
130
- });
131
- });
132
- };
133
- // Annotate the CommonJS export names for ESM import in node:
134
- 0 && (module.exports = {});