@modern-js/plugin-testing 0.0.0-next-20230214035517 → 0.0.0-next-20230214132706

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 (101) hide show
  1. package/CHANGELOG.md +16 -20
  2. package/dist/js/modern/base/config/index.js +36 -0
  3. package/dist/{esm-node → js/modern}/base/config/patches/assetsModule.js +0 -0
  4. package/dist/{esm-node → js/modern}/base/config/patches/filemock.js +0 -0
  5. package/dist/js/modern/base/config/patches/index.js +34 -0
  6. package/dist/{esm-node → js/modern}/base/config/patches/transformer.js +0 -0
  7. package/dist/{esm-node → js/modern}/base/config/resolver.js +0 -0
  8. package/dist/{esm-node → js/modern}/base/config/testConfigOperator.js +17 -1
  9. package/dist/{esm-node → js/modern}/base/config/transformer/babelTransformer.js +0 -0
  10. package/dist/{esm-node → js/modern}/base/hook.js +0 -0
  11. package/dist/{esm-node → js/modern}/base/index.js +0 -0
  12. package/dist/js/modern/base/runJest.js +102 -0
  13. package/dist/{esm-node → js/modern}/base/types/index.js +0 -0
  14. package/dist/{esm-node → js/modern}/base/utils.js +17 -4
  15. package/dist/js/modern/cli/bff/app.js +58 -0
  16. package/dist/{esm-node → js/modern}/cli/bff/constant.js +0 -0
  17. package/dist/{esm-node → js/modern}/cli/bff/index.js +51 -22
  18. package/dist/{esm-node → js/modern}/cli/bff/mockAPI.js +18 -5
  19. package/dist/js/modern/cli/bff/setup.js +75 -0
  20. package/dist/js/modern/cli/bff/utils/index.js +37 -0
  21. package/dist/{esm-node → js/modern}/cli/index.js +26 -6
  22. package/dist/{esm-node → js/modern}/cli/test.js +24 -4
  23. package/dist/{esm-node → js/modern}/constant.js +0 -0
  24. package/dist/{esm-node → js/modern}/index.js +0 -0
  25. package/dist/js/modern/runtime-testing/app.js +48 -0
  26. package/dist/{esm-node → js/modern}/runtime-testing/base.js +0 -0
  27. package/dist/js/modern/runtime-testing/customRender.js +25 -0
  28. package/dist/{esm-node → js/modern}/runtime-testing/index.js +0 -0
  29. package/dist/{esm-node → js/modern}/runtime-testing/reduck.js +21 -3
  30. package/dist/{esm-node → js/modern}/runtime-testing/request.js +0 -0
  31. package/dist/js/modern/runtime-testing/resolvePlugins.js +33 -0
  32. package/dist/{cjs → js/node}/base/config/index.js +23 -3
  33. package/dist/{cjs → js/node}/base/config/patches/assetsModule.js +0 -0
  34. package/dist/{cjs → js/node}/base/config/patches/filemock.js +0 -0
  35. package/dist/{cjs → js/node}/base/config/patches/index.js +26 -6
  36. package/dist/{cjs → js/node}/base/config/patches/transformer.js +0 -0
  37. package/dist/{cjs → js/node}/base/config/resolver.js +0 -0
  38. package/dist/{cjs → js/node}/base/config/testConfigOperator.js +15 -1
  39. package/dist/{cjs → js/node}/base/config/transformer/babelTransformer.js +0 -0
  40. package/dist/{cjs → js/node}/base/hook.js +0 -0
  41. package/dist/{cjs → js/node}/base/index.js +0 -0
  42. package/dist/{cjs → js/node}/base/runJest.js +48 -24
  43. package/dist/{cjs → js/node}/base/types/index.js +0 -0
  44. package/dist/{cjs → js/node}/base/utils.js +15 -4
  45. package/dist/{cjs → js/node}/cli/bff/app.js +26 -6
  46. package/dist/{cjs → js/node}/cli/bff/constant.js +0 -0
  47. package/dist/{cjs → js/node}/cli/bff/index.js +49 -22
  48. package/dist/{cjs → js/node}/cli/bff/mockAPI.js +16 -5
  49. package/dist/{cjs → js/node}/cli/bff/setup.js +26 -6
  50. package/dist/{cjs → js/node}/cli/bff/utils/index.js +15 -1
  51. package/dist/{cjs → js/node}/cli/index.js +26 -6
  52. package/dist/{cjs → js/node}/cli/test.js +24 -4
  53. package/dist/{cjs → js/node}/constant.js +0 -0
  54. package/dist/{cjs → js/node}/index.js +0 -0
  55. package/dist/{cjs → js/node}/runtime-testing/app.js +15 -4
  56. package/dist/{cjs → js/node}/runtime-testing/base.js +0 -0
  57. package/dist/{cjs → js/node}/runtime-testing/customRender.js +15 -1
  58. package/dist/{cjs → js/node}/runtime-testing/index.js +0 -0
  59. package/dist/{cjs → js/node}/runtime-testing/reduck.js +19 -3
  60. package/dist/{cjs → js/node}/runtime-testing/request.js +0 -0
  61. package/dist/{cjs → js/node}/runtime-testing/resolvePlugins.js +15 -3
  62. package/dist/{esm → js/treeshaking}/base/config/index.js +0 -0
  63. package/dist/{esm → js/treeshaking}/base/config/patches/assetsModule.js +0 -0
  64. package/dist/{esm → js/treeshaking}/base/config/patches/filemock.js +0 -0
  65. package/dist/{esm → js/treeshaking}/base/config/patches/index.js +0 -0
  66. package/dist/{esm → js/treeshaking}/base/config/patches/transformer.js +0 -0
  67. package/dist/{esm → js/treeshaking}/base/config/resolver.js +0 -0
  68. package/dist/{esm → js/treeshaking}/base/config/testConfigOperator.js +0 -0
  69. package/dist/{esm → js/treeshaking}/base/config/transformer/babelTransformer.js +0 -0
  70. package/dist/{esm → js/treeshaking}/base/hook.js +0 -0
  71. package/dist/{esm → js/treeshaking}/base/index.js +0 -0
  72. package/dist/{esm → js/treeshaking}/base/runJest.js +0 -0
  73. package/dist/{esm → js/treeshaking}/base/types/index.js +0 -0
  74. package/dist/{esm → js/treeshaking}/base/utils.js +0 -0
  75. package/dist/{esm → js/treeshaking}/cli/bff/app.js +0 -0
  76. package/dist/{esm → js/treeshaking}/cli/bff/constant.js +0 -0
  77. package/dist/{esm → js/treeshaking}/cli/bff/index.js +0 -0
  78. package/dist/{esm → js/treeshaking}/cli/bff/mockAPI.js +0 -0
  79. package/dist/{esm → js/treeshaking}/cli/bff/setup.js +0 -0
  80. package/dist/{esm → js/treeshaking}/cli/bff/utils/index.js +0 -0
  81. package/dist/{esm → js/treeshaking}/cli/index.js +0 -0
  82. package/dist/{esm → js/treeshaking}/cli/test.js +0 -0
  83. package/dist/{esm → js/treeshaking}/constant.js +0 -0
  84. package/dist/{esm → js/treeshaking}/index.js +0 -0
  85. package/dist/{esm → js/treeshaking}/runtime-testing/app.js +0 -0
  86. package/dist/{esm → js/treeshaking}/runtime-testing/base.js +0 -0
  87. package/dist/{esm → js/treeshaking}/runtime-testing/customRender.js +0 -0
  88. package/dist/{esm → js/treeshaking}/runtime-testing/index.js +0 -0
  89. package/dist/{esm → js/treeshaking}/runtime-testing/reduck.js +0 -0
  90. package/dist/{esm → js/treeshaking}/runtime-testing/request.js +0 -0
  91. package/dist/{esm → js/treeshaking}/runtime-testing/resolvePlugins.js +0 -0
  92. package/package.json +26 -26
  93. package/dist/esm-node/base/config/index.js +0 -16
  94. package/dist/esm-node/base/config/patches/index.js +0 -14
  95. package/dist/esm-node/base/runJest.js +0 -78
  96. package/dist/esm-node/cli/bff/app.js +0 -38
  97. package/dist/esm-node/cli/bff/setup.js +0 -46
  98. package/dist/esm-node/cli/bff/utils/index.js +0 -21
  99. package/dist/esm-node/runtime-testing/app.js +0 -35
  100. package/dist/esm-node/runtime-testing/customRender.js +0 -9
  101. package/dist/esm-node/runtime-testing/resolvePlugins.js +0 -19
package/CHANGELOG.md CHANGED
@@ -1,25 +1,21 @@
1
1
  # @modern-js/plugin-testing
2
2
 
3
- ## 0.0.0-next-20230214035517
4
-
5
- ### Patch Changes
6
-
7
- - 57a96cbf3: chore: modify package.json entry fields and build config
8
- chore: 更改 package.json entry 字段以及构建配置
9
- - Updated dependencies [57a96cbf3]
10
- - Updated dependencies [7a2527142]
11
- - Updated dependencies [1b0ce87bc]
12
- - Updated dependencies [0d75c27b1]
13
- - Updated dependencies [11c053b46]
14
- - Updated dependencies [169c58bde]
15
- - Updated dependencies [a0f2ab1b2]
16
- - @modern-js/babel-preset-app@0.0.0-next-20230214035517
17
- - @modern-js/runtime@0.0.0-next-20230214035517
18
- - @modern-js/prod-server@0.0.0-next-20230214035517
19
- - @modern-js/build-config@0.0.0-next-20230214035517
20
- - @modern-js/babel-compiler@0.0.0-next-20230214035517
21
- - @modern-js/plugin@0.0.0-next-20230214035517
22
- - @modern-js/utils@0.0.0-next-20230214035517
3
+ ## 0.0.0-next-20230214132706
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [7a25271428]
8
+ - Updated dependencies [1b0ce87bc4]
9
+ - Updated dependencies [0d75c27b1f]
10
+ - Updated dependencies [11c053b461]
11
+ - Updated dependencies [169c58bdee]
12
+ - Updated dependencies [a0f2ab1b21]
13
+ - @modern-js/runtime@0.0.0-next-20230214132706
14
+ - @modern-js/utils@0.0.0-next-20230214132706
15
+ - @modern-js/prod-server@0.0.0-next-20230214132706
16
+ - @modern-js/babel-preset-app@0.0.0-next-20230214132706
17
+ - @modern-js/babel-compiler@0.0.0-next-20230214132706
18
+ - @modern-js/plugin@0.0.0-next-20230214132706
23
19
 
24
20
  ## 2.4.0
25
21
 
@@ -0,0 +1,36 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { applyPatches } from "./patches";
22
+ import { TestConfigOperator } from "./testConfigOperator";
23
+ const getJestUtils = (testConfig) => {
24
+ const testOperator = new TestConfigOperator(testConfig);
25
+ return testOperator;
26
+ };
27
+ const patchConfig = (testOperator) => __async(void 0, null, function* () {
28
+ yield applyPatches(testOperator);
29
+ return testOperator.jestConfig;
30
+ });
31
+ const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
32
+ export {
33
+ DEFAULT_RESOLVER_PATH,
34
+ getJestUtils,
35
+ patchConfig
36
+ };
@@ -0,0 +1,34 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { patchTransformer } from "./transformer";
22
+ import { patchAssetsModule } from "./assetsModule";
23
+ const _applyPatches = (patches2, testOperator) => __async(void 0, null, function* () {
24
+ for (const patch of patches2) {
25
+ yield patch(testOperator);
26
+ }
27
+ });
28
+ const patches = [patchTransformer, patchAssetsModule];
29
+ const applyPatches = (testConfig) => __async(void 0, null, function* () {
30
+ yield _applyPatches(patches, testConfig);
31
+ });
32
+ export {
33
+ applyPatches
34
+ };
@@ -1,3 +1,19 @@
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
+ };
1
17
  import { merge } from "@modern-js/utils/lodash";
2
18
  class TestConfigOperator {
3
19
  constructor(testConfig) {
@@ -35,7 +51,7 @@ class TestConfigOperator {
35
51
  return;
36
52
  }
37
53
  }
38
- this._jestConfig = { ...this._jestConfig, ...sourceConfig };
54
+ this._jestConfig = __spreadValues(__spreadValues({}, this._jestConfig), sourceConfig);
39
55
  }
40
56
  getFinalConfig() {
41
57
  const { userJestConfig } = this;
File without changes
File without changes
@@ -0,0 +1,102 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import yargs from "yargs/yargs";
22
+ import { runCLI } from "jest";
23
+ import { chalk } from "@modern-js/utils";
24
+ import { getJestUtils, patchConfig } from "./config";
25
+ import { debug } from "./utils";
26
+ const buildArgv = (rawArgv, config) => __async(void 0, null, function* () {
27
+ const argv = yield yargs(rawArgv).argv;
28
+ const result = {
29
+ $0: argv.$0,
30
+ _: argv._.slice(1)
31
+ };
32
+ Object.keys(argv).forEach((key) => {
33
+ if (key.includes("-") || key === "_") {
34
+ return;
35
+ }
36
+ result[key] = argv[key];
37
+ });
38
+ if (config) {
39
+ result.config = JSON.stringify(config);
40
+ }
41
+ return result;
42
+ });
43
+ const readResultsAndExit = (result, globalConfig) => {
44
+ const code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
45
+ process.on("exit", () => {
46
+ if (typeof code === "number" && code !== 0) {
47
+ process.exitCode = code;
48
+ }
49
+ });
50
+ if (globalConfig.forceExit) {
51
+ if (!globalConfig.detectOpenHandles) {
52
+ console.warn(
53
+ `${chalk.bold(
54
+ "Force exiting Jest: "
55
+ )}Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?`
56
+ );
57
+ }
58
+ process.exit(code);
59
+ } else if (!globalConfig.detectOpenHandles) {
60
+ setTimeout(() => {
61
+ console.warn(
62
+ chalk.yellow.bold(
63
+ "Jest did not exit one second after the test run has completed.\n\n"
64
+ ) + chalk.yellow(
65
+ "This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue."
66
+ )
67
+ );
68
+ }, 1e3).unref();
69
+ }
70
+ };
71
+ function runJest(_0) {
72
+ return __async(this, arguments, function* (config, pwd = process.cwd()) {
73
+ try {
74
+ const argvConfig = yield buildArgv(process.argv.slice(2), config);
75
+ const { results, globalConfig } = yield runCLI(argvConfig, [pwd]);
76
+ readResultsAndExit(results, globalConfig);
77
+ } catch (e) {
78
+ console.error(chalk.red((e == null ? void 0 : e.stack) || e));
79
+ process.exit(1);
80
+ }
81
+ });
82
+ }
83
+ function runTest(_0, _1) {
84
+ return __async(this, arguments, function* (api, config, pwd = process.cwd()) {
85
+ process.env.NODE_ENV = "test";
86
+ const jestUtils = getJestUtils(config);
87
+ yield patchConfig(jestUtils);
88
+ jestUtils.setJestUserConfig();
89
+ const hookRunners = api.useHookRunners();
90
+ const testConfigOperator = yield hookRunners.jestConfig(jestUtils, {
91
+ onLast: (input) => input
92
+ });
93
+ const finalConfig = testConfigOperator.getFinalConfig();
94
+ debug("Jest config:", finalConfig);
95
+ yield runJest(finalConfig, pwd);
96
+ yield hookRunners.afterTest();
97
+ });
98
+ }
99
+ export {
100
+ runJest,
101
+ runTest
102
+ };
File without changes
@@ -1,3 +1,19 @@
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
+ };
1
17
  import fs from "fs";
2
18
  import path from "path";
3
19
  import { createDebugger } from "@modern-js/utils";
@@ -26,10 +42,7 @@ const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") =>
26
42
  tsConfig.extends
27
43
  );
28
44
  }
29
- return {
30
- ...extendedCompilerOptions,
31
- ...tsConfig.compilerOptions
32
- };
45
+ return __spreadValues(__spreadValues({}, extendedCompilerOptions), tsConfig.compilerOptions);
33
46
  };
34
47
  const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
35
48
  const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
@@ -0,0 +1,58 @@
1
+ var __async = (__this, __arguments, generator) => {
2
+ return new Promise((resolve, reject) => {
3
+ var fulfilled = (value) => {
4
+ try {
5
+ step(generator.next(value));
6
+ } catch (e) {
7
+ reject(e);
8
+ }
9
+ };
10
+ var rejected = (value) => {
11
+ try {
12
+ step(generator.throw(value));
13
+ } catch (e) {
14
+ reject(e);
15
+ }
16
+ };
17
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
+ step((generator = generator.apply(__this, __arguments)).next());
19
+ });
20
+ };
21
+ import { AsyncLocalStorage } from "async_hooks";
22
+ import { Server } from "@modern-js/prod-server";
23
+ const store = new AsyncLocalStorage();
24
+ const isInHandler = () => Boolean(store.getStore());
25
+ let server = null;
26
+ const createApp = (pwd, config, plugins, routes) => __async(void 0, null, function* () {
27
+ if (!server) {
28
+ config.output.path = "./";
29
+ server = new Server({
30
+ apiOnly: true,
31
+ pwd,
32
+ config,
33
+ internalPlugins: plugins,
34
+ routes
35
+ });
36
+ yield server.init();
37
+ }
38
+ const app = server.getRequestHandler();
39
+ return app;
40
+ });
41
+ const getApp = () => {
42
+ if (!server) {
43
+ throw new Error("please createApp first");
44
+ }
45
+ return server.getRequestHandler();
46
+ };
47
+ const closeServer = () => __async(void 0, null, function* () {
48
+ if (!server) {
49
+ throw new Error("please createApp first");
50
+ }
51
+ yield server.close();
52
+ });
53
+ export {
54
+ closeServer,
55
+ createApp,
56
+ getApp,
57
+ isInHandler
58
+ };
File without changes
@@ -1,3 +1,39 @@
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
+ var __async = (__this, __arguments, generator) => {
18
+ return new Promise((resolve, reject) => {
19
+ var fulfilled = (value) => {
20
+ try {
21
+ step(generator.next(value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ };
26
+ var rejected = (value) => {
27
+ try {
28
+ step(generator.throw(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
+ step((generator = generator.apply(__this, __arguments)).next());
35
+ });
36
+ };
1
37
  import path from "path";
2
38
  import { isApiOnly } from "@modern-js/utils";
3
39
  import {
@@ -6,13 +42,13 @@ import {
6
42
  } from "../../base";
7
43
  import { bff_info_key } from "./constant";
8
44
  import { isBFFProject } from "./utils";
9
- const setJestConfigForBFF = async ({
45
+ const setJestConfigForBFF = (_0) => __async(void 0, [_0], function* ({
10
46
  pwd,
11
47
  userConfig,
12
48
  plugins,
13
49
  routes,
14
50
  utils
15
- }) => {
51
+ }) {
16
52
  var _a;
17
53
  const bffConfig = {
18
54
  rootDir: path.join(pwd, "./api"),
@@ -40,11 +76,8 @@ const setJestConfigForBFF = async ({
40
76
  const transform = {
41
77
  "\\.[jt]sx?$": require.resolve("ts-jest")
42
78
  };
43
- const apiOnly = await isApiOnly(pwd);
44
- const mergedModuleNameMapper = {
45
- ...moduleNameMapper,
46
- ...aliasMapper
47
- };
79
+ const apiOnly = yield isApiOnly(pwd);
80
+ const mergedModuleNameMapper = __spreadValues(__spreadValues({}, moduleNameMapper), aliasMapper);
48
81
  const resolver = jestConfig.resolver || DEFAULT_RESOLVER_PATH;
49
82
  const configFields = ["coverage", "collectCoverage", "testTimeout"];
50
83
  const commonConfig = configFields.reduce((obj, field) => {
@@ -57,15 +90,12 @@ const setJestConfigForBFF = async ({
57
90
  utils.setJestConfig(
58
91
  {
59
92
  projects: [
60
- {
61
- ...jestConfig
62
- },
63
- {
93
+ __spreadValues({}, jestConfig),
94
+ __spreadValues({
64
95
  transform,
65
96
  moduleNameMapper: mergedModuleNameMapper,
66
- resolver,
67
- ...bffConfig
68
- }
97
+ resolver
98
+ }, bffConfig)
69
99
  ]
70
100
  },
71
101
  {
@@ -76,12 +106,11 @@ const setJestConfigForBFF = async ({
76
106
  utils.setJestConfig(
77
107
  {
78
108
  projects: [
79
- {
109
+ __spreadValues({
80
110
  transform,
81
111
  moduleNameMapper: mergedModuleNameMapper,
82
- resolver,
83
- ...bffConfig
84
- }
112
+ resolver
113
+ }, bffConfig)
85
114
  ]
86
115
  },
87
116
  {
@@ -90,19 +119,19 @@ const setJestConfigForBFF = async ({
90
119
  );
91
120
  }
92
121
  utils.setJestConfig(commonConfig);
93
- };
122
+ });
94
123
  var bff_default = () => ({
95
124
  name: "@modern-js/testing-plugin-bff",
96
125
  setup(api) {
97
126
  return {
98
- jestConfig: async (utils, next) => {
127
+ jestConfig: (utils, next) => __async(this, null, function* () {
99
128
  const appContext = api.useAppContext();
100
129
  const pwd = appContext.appDirectory;
101
130
  if (!isBFFProject(pwd)) {
102
131
  return next(utils);
103
132
  }
104
133
  const userConfig = api.useResolvedConfigContext();
105
- await setJestConfigForBFF({
134
+ yield setJestConfigForBFF({
106
135
  pwd,
107
136
  userConfig,
108
137
  routes: appContext.serverRoutes,
@@ -110,7 +139,7 @@ var bff_default = () => ({
110
139
  utils
111
140
  });
112
141
  return next(utils);
113
- }
142
+ })
114
143
  };
115
144
  }
116
145
  });
@@ -1,3 +1,19 @@
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
+ };
1
17
  import * as ptr from "path-to-regexp";
2
18
  import * as mockAppModule from "./app";
3
19
  const mock_replaceUrlWithParams = (url, paramValues, payload) => {
@@ -10,10 +26,7 @@ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
10
26
  return cur;
11
27
  }, {});
12
28
  const getFinalPath = ptr.compile(url, { encode: encodeURIComponent });
13
- return getFinalPath({
14
- ...params,
15
- ...payload
16
- });
29
+ return getFinalPath(__spreadValues(__spreadValues({}, params), payload));
17
30
  };
18
31
  const mock_getParamsAndPayload = (args) => {
19
32
  if (args.length === 0) {
@@ -75,7 +88,7 @@ var mockAPI_default = (mockApiInfosByFile) => {
75
88
  return test.then((value) => {
76
89
  try {
77
90
  return JSON.parse(value.text);
78
- } catch {
91
+ } catch (e) {
79
92
  return value.text;
80
93
  }
81
94
  });
@@ -0,0 +1,75 @@
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
5
+ var __async = (__this, __arguments, generator) => {
6
+ return new Promise((resolve, reject) => {
7
+ var fulfilled = (value) => {
8
+ try {
9
+ step(generator.next(value));
10
+ } catch (e) {
11
+ reject(e);
12
+ }
13
+ };
14
+ var rejected = (value) => {
15
+ try {
16
+ step(generator.throw(value));
17
+ } catch (e) {
18
+ reject(e);
19
+ }
20
+ };
21
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
22
+ step((generator = generator.apply(__this, __arguments)).next());
23
+ });
24
+ };
25
+ import path from "path";
26
+ import { ApiRouter } from "@modern-js/bff-core";
27
+ import { bff_info_key } from "./constant";
28
+ import mockAPI from "./mockAPI";
29
+ import { createApp, closeServer } from "./app";
30
+ var require_setup = __commonJS({
31
+ "src/cli/bff/setup.ts"(exports) {
32
+ let uped = false;
33
+ const setup = () => {
34
+ var _a, _b;
35
+ if (uped) {
36
+ return;
37
+ }
38
+ uped = true;
39
+ const bff_info = global[bff_info_key];
40
+ const prefix = (_b = (_a = bff_info == null ? void 0 : bff_info.modernUserConfig) == null ? void 0 : _a.bff) == null ? void 0 : _b.prefix;
41
+ const apiRouter = new ApiRouter({
42
+ apiDir: path.join(bff_info.appDir, "./api"),
43
+ prefix
44
+ });
45
+ const apiInfos = apiRouter.getApiHandlers();
46
+ const apiInfosByFile = apiInfos.reduce(
47
+ (res, apiInfo) => {
48
+ if (!res[apiInfo.filename]) {
49
+ res[apiInfo.filename] = [];
50
+ }
51
+ res[apiInfo.filename].push(apiInfo);
52
+ return res;
53
+ },
54
+ {}
55
+ );
56
+ let app = null;
57
+ beforeAll(() => __async(exports, null, function* () {
58
+ if (!app) {
59
+ app = yield createApp(
60
+ bff_info.appDir,
61
+ bff_info.modernUserConfig,
62
+ bff_info.plugins,
63
+ bff_info.routes
64
+ );
65
+ }
66
+ }));
67
+ afterAll(() => __async(exports, null, function* () {
68
+ yield closeServer();
69
+ }));
70
+ mockAPI(apiInfosByFile);
71
+ };
72
+ setup();
73
+ }
74
+ });
75
+ export default require_setup();
@@ -0,0 +1,37 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import path from "path";
18
+ import { chalk } from "@modern-js/utils";
19
+ const isBFFProject = (pwd) => {
20
+ try {
21
+ const packageJson = require(path.join(pwd, "./package.json"));
22
+ const { dependencies, devDependencies } = packageJson;
23
+ const isBFF = Object.keys(__spreadValues(__spreadValues({}, dependencies), devDependencies)).some(
24
+ (dependency) => dependency.includes("plugin-bff")
25
+ );
26
+ const isMWA = Object.keys(devDependencies).some(
27
+ (devDependency) => devDependency.includes("app-tools")
28
+ );
29
+ return isMWA && isBFF;
30
+ } catch (error) {
31
+ console.log(chalk.red(error));
32
+ return false;
33
+ }
34
+ };
35
+ export {
36
+ isBFFProject
37
+ };