@modern-js/plugin-testing 2.21.0 → 2.21.2-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/base/config/index.js +9 -3
  3. package/dist/cjs/base/config/patches/assetsModule.js +3 -1
  4. package/dist/cjs/base/config/patches/filemock.js +3 -1
  5. package/dist/cjs/base/config/patches/index.js +3 -1
  6. package/dist/cjs/base/config/patches/transformer.js +3 -1
  7. package/dist/cjs/base/config/testConfigOperator.js +3 -1
  8. package/dist/cjs/base/config/transformer/babelTransformer.js +3 -1
  9. package/dist/cjs/base/hook.js +9 -3
  10. package/dist/cjs/base/index.js +18 -6
  11. package/dist/cjs/base/runJest.js +6 -2
  12. package/dist/cjs/base/utils.js +9 -3
  13. package/dist/cjs/cli/bff/app.js +12 -4
  14. package/dist/cjs/cli/bff/constant.js +3 -1
  15. package/dist/cjs/cli/bff/index.js +6 -2
  16. package/dist/cjs/cli/bff/mockAPI.js +3 -1
  17. package/dist/cjs/cli/bff/setup.js +14 -14
  18. package/dist/cjs/cli/bff/utils/index.js +3 -1
  19. package/dist/cjs/cli/index.js +7 -2
  20. package/dist/cjs/cli/test.js +3 -1
  21. package/dist/cjs/constant.js +3 -1
  22. package/dist/cjs/runtime-testing/app.js +3 -1
  23. package/dist/cjs/runtime-testing/base.js +5 -11
  24. package/dist/cjs/runtime-testing/{request.js → bff.js} +4 -2
  25. package/dist/cjs/runtime-testing/customRender.js +3 -1
  26. package/dist/cjs/runtime-testing/reduck.js +12 -4
  27. package/dist/cjs/runtime-testing/resolvePlugins.js +3 -1
  28. package/dist/esm/cli/bff/setup.js +15 -14
  29. package/dist/esm/cli/index.js +1 -0
  30. package/dist/esm/runtime-testing/base.js +0 -1
  31. package/dist/esm/runtime-testing/{request.js → bff.js} +1 -1
  32. package/dist/esm-node/cli/bff/setup.js +14 -14
  33. package/dist/esm-node/cli/index.js +1 -0
  34. package/dist/esm-node/runtime-testing/base.js +0 -1
  35. package/dist/esm-node/runtime-testing/bff.js +14 -0
  36. package/dist/js/modern/base/config/index.js +36 -0
  37. package/dist/js/modern/base/config/patches/assetsModule.js +11 -0
  38. package/dist/js/modern/base/config/patches/filemock.js +4 -0
  39. package/dist/js/modern/base/config/patches/index.js +34 -0
  40. package/dist/js/modern/base/config/patches/transformer.js +38 -0
  41. package/dist/js/modern/base/config/resolver.js +21 -0
  42. package/dist/js/modern/base/config/testConfigOperator.js +69 -0
  43. package/dist/js/modern/base/config/transformer/babelTransformer.js +19 -0
  44. package/dist/js/modern/base/hook.js +12 -0
  45. package/dist/js/modern/base/index.js +14 -0
  46. package/dist/js/modern/base/runJest.js +102 -0
  47. package/dist/js/modern/base/types/index.js +0 -0
  48. package/dist/js/modern/base/utils.js +66 -0
  49. package/dist/js/modern/cli/bff/app.js +58 -0
  50. package/dist/js/modern/cli/bff/constant.js +4 -0
  51. package/dist/js/modern/cli/bff/index.js +149 -0
  52. package/dist/js/modern/cli/bff/mockAPI.js +109 -0
  53. package/dist/js/modern/cli/bff/setup.js +75 -0
  54. package/dist/js/modern/cli/bff/utils/index.js +37 -0
  55. package/dist/js/modern/cli/index.js +115 -0
  56. package/dist/js/modern/cli/test.js +61 -0
  57. package/dist/js/modern/constant.js +4 -0
  58. package/dist/js/modern/index.js +3 -0
  59. package/dist/js/modern/runtime-testing/app.js +48 -0
  60. package/dist/js/modern/runtime-testing/base.js +7 -0
  61. package/dist/js/modern/runtime-testing/customRender.js +25 -0
  62. package/dist/js/modern/runtime-testing/index.js +2 -0
  63. package/dist/js/modern/runtime-testing/reduck.js +55 -0
  64. package/dist/{esm-node → js/modern}/runtime-testing/request.js +3 -1
  65. package/dist/js/modern/runtime-testing/resolvePlugins.js +33 -0
  66. package/dist/js/node/base/config/index.js +67 -0
  67. package/dist/js/node/base/config/patches/assetsModule.js +40 -0
  68. package/dist/js/node/base/config/patches/filemock.js +25 -0
  69. package/dist/js/node/base/config/patches/index.js +57 -0
  70. package/dist/js/node/base/config/patches/transformer.js +67 -0
  71. package/dist/js/node/base/config/resolver.js +30 -0
  72. package/dist/js/node/base/config/testConfigOperator.js +90 -0
  73. package/dist/js/node/base/config/transformer/babelTransformer.js +46 -0
  74. package/dist/js/node/base/hook.js +37 -0
  75. package/dist/js/node/base/index.js +43 -0
  76. package/dist/js/node/base/runJest.js +132 -0
  77. package/dist/js/node/base/types/index.js +15 -0
  78. package/dist/js/node/base/utils.js +95 -0
  79. package/dist/js/node/cli/bff/app.js +84 -0
  80. package/dist/js/node/cli/bff/constant.js +27 -0
  81. package/dist/js/node/cli/bff/index.js +173 -0
  82. package/dist/js/node/cli/bff/mockAPI.js +134 -0
  83. package/dist/js/node/cli/bff/setup.js +84 -0
  84. package/dist/js/node/cli/bff/utils/index.js +64 -0
  85. package/dist/js/node/cli/index.js +135 -0
  86. package/dist/js/node/cli/test.js +88 -0
  87. package/dist/js/node/constant.js +27 -0
  88. package/dist/js/node/index.js +19 -0
  89. package/dist/js/node/runtime-testing/app.js +73 -0
  90. package/dist/js/node/runtime-testing/base.js +38 -0
  91. package/dist/js/node/runtime-testing/customRender.js +50 -0
  92. package/dist/js/node/runtime-testing/index.js +18 -0
  93. package/dist/js/node/runtime-testing/reduck.js +85 -0
  94. package/dist/js/node/runtime-testing/request.js +45 -0
  95. package/dist/js/node/runtime-testing/resolvePlugins.js +52 -0
  96. package/dist/js/treeshaking/base/config/index.js +154 -0
  97. package/dist/js/treeshaking/base/config/patches/assetsModule.js +9 -0
  98. package/dist/js/treeshaking/base/config/patches/filemock.js +2 -0
  99. package/dist/js/treeshaking/base/config/patches/index.js +225 -0
  100. package/dist/js/treeshaking/base/config/patches/transformer.js +36 -0
  101. package/dist/js/treeshaking/base/config/resolver.js +37 -0
  102. package/dist/js/treeshaking/base/config/testConfigOperator.js +127 -0
  103. package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +17 -0
  104. package/dist/js/treeshaking/base/hook.js +8 -0
  105. package/dist/js/treeshaking/base/index.js +7 -0
  106. package/dist/js/treeshaking/base/runJest.js +292 -0
  107. package/dist/js/treeshaking/base/types/index.js +1 -0
  108. package/dist/js/treeshaking/base/utils.js +76 -0
  109. package/dist/js/treeshaking/cli/bff/app.js +200 -0
  110. package/dist/js/treeshaking/cli/bff/constant.js +2 -0
  111. package/dist/js/treeshaking/cli/bff/index.js +297 -0
  112. package/dist/js/treeshaking/cli/bff/mockAPI.js +188 -0
  113. package/dist/js/treeshaking/cli/bff/setup.js +192 -0
  114. package/dist/js/treeshaking/cli/bff/utils/index.js +47 -0
  115. package/dist/js/treeshaking/cli/index.js +255 -0
  116. package/dist/js/treeshaking/cli/test.js +180 -0
  117. package/dist/js/treeshaking/constant.js +2 -0
  118. package/dist/js/treeshaking/index.js +3 -0
  119. package/dist/js/treeshaking/runtime-testing/app.js +90 -0
  120. package/dist/js/treeshaking/runtime-testing/base.js +4 -0
  121. package/dist/js/treeshaking/runtime-testing/customRender.js +41 -0
  122. package/dist/js/treeshaking/runtime-testing/index.js +2 -0
  123. package/dist/js/treeshaking/runtime-testing/reduck.js +89 -0
  124. package/dist/js/treeshaking/runtime-testing/request.js +51 -0
  125. package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +46 -0
  126. package/dist/types/runtime-testing/base.d.ts +1 -2
  127. package/dist/types/runtime-testing/{request.d.ts → bff.d.ts} +1 -1
  128. package/package.json +23 -14
  129. package/types/index.d.ts +6 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @modern-js/plugin-testing
2
2
 
3
+ ## 2.21.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [78e3ac8]
8
+ - Updated dependencies [2728724]
9
+ - @modern-js/prod-server@2.21.1
10
+ - @modern-js/runtime@2.21.1
11
+ - @modern-js/babel-preset-app@2.21.1
12
+ - @modern-js/babel-compiler@2.21.1
13
+ - @modern-js/plugin@2.21.1
14
+ - @modern-js/utils@2.21.1
15
+
3
16
  ## 2.21.0
4
17
 
5
18
  ### Patch Changes
@@ -10,9 +10,15 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- DEFAULT_RESOLVER_PATH: () => DEFAULT_RESOLVER_PATH,
14
- getJestUtils: () => getJestUtils,
15
- patchConfig: () => patchConfig
13
+ DEFAULT_RESOLVER_PATH: function() {
14
+ return DEFAULT_RESOLVER_PATH;
15
+ },
16
+ getJestUtils: function() {
17
+ return getJestUtils;
18
+ },
19
+ patchConfig: function() {
20
+ return patchConfig;
21
+ }
16
22
  });
17
23
  const _patches = require("./patches");
18
24
  const _testConfigOperator = require("./testConfigOperator");
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "patchAssetsModule", {
6
6
  enumerable: true,
7
- get: () => patchAssetsModule
7
+ get: function() {
8
+ return patchAssetsModule;
9
+ }
8
10
  });
9
11
  const patchAssetsModule = (testOperator) => {
10
12
  testOperator.mergeJestConfig({
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "default", {
6
6
  enumerable: true,
7
- get: () => _default
7
+ get: function() {
8
+ return _default;
9
+ }
8
10
  });
9
11
  const _default = "test-file-stub";
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "applyPatches", {
6
6
  enumerable: true,
7
- get: () => applyPatches
7
+ get: function() {
8
+ return applyPatches;
9
+ }
8
10
  });
9
11
  const _transformer = require("./transformer");
10
12
  const _assetsModule = require("./assetsModule");
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "patchTransformer", {
6
6
  enumerable: true,
7
- get: () => patchTransformer
7
+ get: function() {
8
+ return patchTransformer;
9
+ }
8
10
  });
9
11
  const _utils = require("../../utils");
10
12
  const resolveTsCompilerOptions = () => {
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "TestConfigOperator", {
6
6
  enumerable: true,
7
- get: () => TestConfigOperator
7
+ get: function() {
8
+ return TestConfigOperator;
9
+ }
8
10
  });
9
11
  const _define_property = require("@swc/helpers/_/_define_property");
10
12
  const _lodash = require("@modern-js/utils/lodash");
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "default", {
6
6
  enumerable: true,
7
- get: () => _default
7
+ get: function() {
8
+ return _default;
9
+ }
8
10
  });
9
11
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
10
12
  const _babeljest = /* @__PURE__ */ _interop_require_default._(require("babel-jest"));
@@ -10,9 +10,15 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- jestConfigHook: () => jestConfigHook,
14
- afterTestHook: () => afterTestHook,
15
- testingHooks: () => testingHooks
13
+ jestConfigHook: function() {
14
+ return jestConfigHook;
15
+ },
16
+ afterTestHook: function() {
17
+ return afterTestHook;
18
+ },
19
+ testingHooks: function() {
20
+ return testingHooks;
21
+ }
16
22
  });
17
23
  const _plugin = require("@modern-js/plugin");
18
24
  const jestConfigHook = (0, _plugin.createAsyncPipeline)();
@@ -10,12 +10,24 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- runTest: () => _runJest.runTest,
14
- runJest: () => _runJest.runJest,
15
- getModuleNameMapper: () => _utils.getModuleNameMapper,
16
- DEFAULT_RESOLVER_PATH: () => _config.DEFAULT_RESOLVER_PATH,
17
- TestConfigOperator: () => _testConfigOperator.TestConfigOperator,
18
- testingHooks: () => _hook.testingHooks
13
+ runTest: function() {
14
+ return _runJest.runTest;
15
+ },
16
+ runJest: function() {
17
+ return _runJest.runJest;
18
+ },
19
+ getModuleNameMapper: function() {
20
+ return _utils.getModuleNameMapper;
21
+ },
22
+ DEFAULT_RESOLVER_PATH: function() {
23
+ return _config.DEFAULT_RESOLVER_PATH;
24
+ },
25
+ TestConfigOperator: function() {
26
+ return _testConfigOperator.TestConfigOperator;
27
+ },
28
+ testingHooks: function() {
29
+ return _hook.testingHooks;
30
+ }
19
31
  });
20
32
  const _export_star = require("@swc/helpers/_/_export_star");
21
33
  const _runJest = require("./runJest");
@@ -10,8 +10,12 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- runJest: () => runJest,
14
- runTest: () => runTest
13
+ runJest: function() {
14
+ return runJest;
15
+ },
16
+ runTest: function() {
17
+ return runTest;
18
+ }
15
19
  });
16
20
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
17
21
  const _yargs = /* @__PURE__ */ _interop_require_default._(require("yargs/yargs"));
@@ -10,9 +10,15 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- debug: () => debug,
14
- readCompilerOptions: () => readCompilerOptions,
15
- getModuleNameMapper: () => getModuleNameMapper
13
+ debug: function() {
14
+ return debug;
15
+ },
16
+ readCompilerOptions: function() {
17
+ return readCompilerOptions;
18
+ },
19
+ getModuleNameMapper: function() {
20
+ return getModuleNameMapper;
21
+ }
16
22
  });
17
23
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
18
24
  const _fs = /* @__PURE__ */ _interop_require_default._(require("fs"));
@@ -10,10 +10,18 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- isInHandler: () => isInHandler,
14
- createApp: () => createApp,
15
- getApp: () => getApp,
16
- closeServer: () => closeServer
13
+ isInHandler: function() {
14
+ return isInHandler;
15
+ },
16
+ createApp: function() {
17
+ return createApp;
18
+ },
19
+ getApp: function() {
20
+ return getApp;
21
+ },
22
+ closeServer: function() {
23
+ return closeServer;
24
+ }
17
25
  });
18
26
  const _async_hooks = require("async_hooks");
19
27
  const _prodserver = require("@modern-js/prod-server");
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "bff_info_key", {
6
6
  enumerable: true,
7
- get: () => bff_info_key
7
+ get: function() {
8
+ return bff_info_key;
9
+ }
8
10
  });
9
11
  const bff_info_key = "modern_bff_info";
@@ -10,8 +10,12 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- setJestConfigForBFF: () => setJestConfigForBFF,
14
- default: () => _default
13
+ setJestConfigForBFF: function() {
14
+ return setJestConfigForBFF;
15
+ },
16
+ default: function() {
17
+ return _default;
18
+ }
15
19
  });
16
20
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
17
21
  const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "default", {
6
6
  enumerable: true,
7
- get: () => _default
7
+ get: function() {
8
+ return _default;
9
+ }
8
10
  });
9
11
  const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
10
12
  const _pathtoregexp = /* @__PURE__ */ _interop_require_wildcard._(require("path-to-regexp"));
@@ -18,21 +18,22 @@ const setup = () => {
18
18
  const bff_info = global[_constant.bff_info_key];
19
19
  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;
20
20
  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
- const apiRouter = new _bffcore.ApiRouter({
22
- apiDir: _path.default.join(bff_info.appDir, "./api"),
23
- prefix,
24
- httpMethodDecider
25
- });
26
- const apiInfos = apiRouter.getApiHandlers();
27
- const apiInfosByFile = apiInfos.reduce((res, apiInfo) => {
28
- if (!res[apiInfo.filename]) {
29
- res[apiInfo.filename] = [];
30
- }
31
- res[apiInfo.filename].push(apiInfo);
32
- return res;
33
- }, {});
34
21
  let app = null;
35
22
  beforeAll(async () => {
23
+ const apiRouter = new _bffcore.ApiRouter({
24
+ apiDir: _path.default.join(bff_info.appDir, "./api"),
25
+ prefix,
26
+ httpMethodDecider
27
+ });
28
+ const apiInfos = apiRouter.getApiHandlers();
29
+ const apiInfosByFile = apiInfos.reduce((res, apiInfo) => {
30
+ if (!res[apiInfo.filename]) {
31
+ res[apiInfo.filename] = [];
32
+ }
33
+ res[apiInfo.filename].push(apiInfo);
34
+ return res;
35
+ }, {});
36
+ (0, _mockAPI.default)(apiInfosByFile);
36
37
  if (!app) {
37
38
  app = await (0, _app.createApp)(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
38
39
  }
@@ -40,6 +41,5 @@ const setup = () => {
40
41
  afterAll(async () => {
41
42
  await (0, _app.closeServer)();
42
43
  });
43
- (0, _mockAPI.default)(apiInfosByFile);
44
44
  };
45
45
  setup();
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "isBFFProject", {
6
6
  enumerable: true,
7
- get: () => isBFFProject
7
+ get: function() {
8
+ return isBFFProject;
9
+ }
8
10
  });
9
11
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
10
12
  const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
@@ -10,8 +10,12 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- mergeUserJestConfig: () => mergeUserJestConfig,
14
- default: () => _default
13
+ mergeUserJestConfig: function() {
14
+ return mergeUserJestConfig;
15
+ },
16
+ default: function() {
17
+ return _default;
18
+ }
15
19
  });
16
20
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
17
21
  const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
@@ -57,6 +61,7 @@ const _default = () => {
57
61
  // The module-tools alias configuration is different and more specific than app-tools.
58
62
  // So for the time being, the @ alias is configured here.
59
63
  "@": _path.default.join(appContext.appDirectory, "src"),
64
+ "@modern-js/runtime/testing/bff": require.resolve("@modern-js/plugin-testing/bff"),
60
65
  "@modern-js/runtime/testing": testingExportsUtils.getPath()
61
66
  }
62
67
  }
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "default", {
6
6
  enumerable: true,
7
- get: () => _default
7
+ get: function() {
8
+ return _default;
9
+ }
8
10
  });
9
11
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
10
12
  const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "MODERNJS_CONFIG_KEY", {
6
6
  enumerable: true,
7
- get: () => MODERNJS_CONFIG_KEY
7
+ get: function() {
8
+ return MODERNJS_CONFIG_KEY;
9
+ }
8
10
  });
9
11
  const MODERNJS_CONFIG_KEY = "__modernjs_config__";
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "default", {
6
6
  enumerable: true,
7
- get: () => _default
7
+ get: function() {
8
+ return _default;
9
+ }
8
10
  });
9
11
  const _define_property = require("@swc/helpers/_/_define_property");
10
12
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
@@ -2,19 +2,13 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- function _export(target, all) {
6
- for (var name in all)
7
- Object.defineProperty(target, name, {
8
- enumerable: true,
9
- get: all[name]
10
- });
11
- }
12
- _export(exports, {
13
- renderApp: () => _customRender.default,
14
- testBff: () => _request.request
5
+ Object.defineProperty(exports, "renderApp", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _customRender.default;
9
+ }
15
10
  });
16
11
  const _export_star = require("@swc/helpers/_/_export_star");
17
12
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
18
13
  const _customRender = /* @__PURE__ */ _interop_require_default._(require("./customRender"));
19
14
  _export_star._(require("@testing-library/react"), exports);
20
- const _request = require("./request");
@@ -2,9 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "request", {
5
+ Object.defineProperty(exports, "testBff", {
6
6
  enumerable: true,
7
- get: () => request
7
+ get: function() {
8
+ return request;
9
+ }
8
10
  });
9
11
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
10
12
  const _supertest = /* @__PURE__ */ _interop_require_default._(require("supertest"));
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "default", {
6
6
  enumerable: true,
7
- get: () => _default
7
+ get: function() {
8
+ return _default;
9
+ }
8
10
  });
9
11
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
10
12
  const _react = /* @__PURE__ */ _interop_require_default._(require("react"));
@@ -10,10 +10,18 @@ function _export(target, all) {
10
10
  });
11
11
  }
12
12
  _export(exports, {
13
- effects: () => effects,
14
- immer: () => immer,
15
- autoActions: () => autoActions,
16
- createStore: () => createStore
13
+ effects: function() {
14
+ return effects;
15
+ },
16
+ immer: function() {
17
+ return immer;
18
+ },
19
+ autoActions: function() {
20
+ return autoActions;
21
+ },
22
+ createStore: function() {
23
+ return createStore;
24
+ }
17
25
  });
18
26
  const _interop_require_default = require("@swc/helpers/_/_interop_require_default");
19
27
  const _store = require("@modern-js-reduck/store");
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  Object.defineProperty(exports, "default", {
6
6
  enumerable: true,
7
- get: () => resolvePlugins
7
+ get: function() {
8
+ return resolvePlugins;
9
+ }
8
10
  });
9
11
  const allowedFeatures = [
10
12
  "router",
@@ -15,24 +15,26 @@ var setup = function() {
15
15
  var bff_info = global[bff_info_key];
16
16
  var 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;
17
17
  var 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;
18
- var apiRouter = new ApiRouter({
19
- apiDir: path.join(bff_info.appDir, "./api"),
20
- prefix: prefix,
21
- httpMethodDecider: httpMethodDecider
22
- });
23
- var apiInfos = apiRouter.getApiHandlers();
24
- var apiInfosByFile = apiInfos.reduce(function(res, apiInfo) {
25
- if (!res[apiInfo.filename]) {
26
- res[apiInfo.filename] = [];
27
- }
28
- res[apiInfo.filename].push(apiInfo);
29
- return res;
30
- }, {});
31
18
  var app = null;
32
19
  beforeAll(/* @__PURE__ */ _async_to_generator(function() {
20
+ var apiRouter, apiInfos, apiInfosByFile;
33
21
  return _ts_generator(this, function(_state) {
34
22
  switch (_state.label) {
35
23
  case 0:
24
+ apiRouter = new ApiRouter({
25
+ apiDir: path.join(bff_info.appDir, "./api"),
26
+ prefix: prefix,
27
+ httpMethodDecider: httpMethodDecider
28
+ });
29
+ apiInfos = apiRouter.getApiHandlers();
30
+ apiInfosByFile = apiInfos.reduce(function(res, apiInfo) {
31
+ if (!res[apiInfo.filename]) {
32
+ res[apiInfo.filename] = [];
33
+ }
34
+ res[apiInfo.filename].push(apiInfo);
35
+ return res;
36
+ }, {});
37
+ mockAPI(apiInfosByFile);
36
38
  if (!!app)
37
39
  return [
38
40
  3,
@@ -68,6 +70,5 @@ var setup = function() {
68
70
  }
69
71
  });
70
72
  }));
71
- mockAPI(apiInfosByFile);
72
73
  };
73
74
  setup();
@@ -58,6 +58,7 @@ export default function() {
58
58
  // The module-tools alias configuration is different and more specific than app-tools.
59
59
  // So for the time being, the @ alias is configured here.
60
60
  "@": path.join(appContext.appDirectory, "src"),
61
+ "@modern-js/runtime/testing/bff": require.resolve("@modern-js/plugin-testing/bff"),
61
62
  "@modern-js/runtime/testing": testingExportsUtils.getPath()
62
63
  }
63
64
  }
@@ -1,3 +1,2 @@
1
1
  export { default as renderApp } from "./customRender";
2
2
  export * from "@testing-library/react";
3
- export { request as testBff } from "./request";
@@ -16,4 +16,4 @@ function request() {
16
16
  fn.returnHttp = false;
17
17
  return res;
18
18
  }
19
- export { request };
19
+ export { request as testBff };
@@ -13,21 +13,22 @@ const setup = () => {
13
13
  const bff_info = global[bff_info_key];
14
14
  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;
15
15
  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;
16
- const apiRouter = new ApiRouter({
17
- apiDir: path.join(bff_info.appDir, "./api"),
18
- prefix,
19
- httpMethodDecider
20
- });
21
- const apiInfos = apiRouter.getApiHandlers();
22
- const apiInfosByFile = apiInfos.reduce((res, apiInfo) => {
23
- if (!res[apiInfo.filename]) {
24
- res[apiInfo.filename] = [];
25
- }
26
- res[apiInfo.filename].push(apiInfo);
27
- return res;
28
- }, {});
29
16
  let app = null;
30
17
  beforeAll(async () => {
18
+ const apiRouter = new ApiRouter({
19
+ apiDir: path.join(bff_info.appDir, "./api"),
20
+ prefix,
21
+ httpMethodDecider
22
+ });
23
+ const apiInfos = apiRouter.getApiHandlers();
24
+ const apiInfosByFile = apiInfos.reduce((res, apiInfo) => {
25
+ if (!res[apiInfo.filename]) {
26
+ res[apiInfo.filename] = [];
27
+ }
28
+ res[apiInfo.filename].push(apiInfo);
29
+ return res;
30
+ }, {});
31
+ mockAPI(apiInfosByFile);
31
32
  if (!app) {
32
33
  app = await createApp(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
33
34
  }
@@ -35,6 +36,5 @@ const setup = () => {
35
36
  afterAll(async () => {
36
37
  await closeServer();
37
38
  });
38
- mockAPI(apiInfosByFile);
39
39
  };
40
40
  setup();
@@ -41,6 +41,7 @@ export default () => {
41
41
  // The module-tools alias configuration is different and more specific than app-tools.
42
42
  // So for the time being, the @ alias is configured here.
43
43
  "@": path.join(appContext.appDirectory, "src"),
44
+ "@modern-js/runtime/testing/bff": require.resolve("@modern-js/plugin-testing/bff"),
44
45
  "@modern-js/runtime/testing": testingExportsUtils.getPath()
45
46
  }
46
47
  }
@@ -1,3 +1,2 @@
1
1
  export { default as renderApp } from "./customRender";
2
2
  export * from "@testing-library/react";
3
- export { request as testBff } from "./request";
@@ -0,0 +1,14 @@
1
+ import supertest from "supertest";
2
+ import { getApp } from "../cli/bff/app";
3
+ function request(...args) {
4
+ const [fn, ...extraArgs] = args;
5
+ const app = getApp();
6
+ if (!fn) {
7
+ return supertest(app);
8
+ }
9
+ fn.returnHttp = true;
10
+ const res = fn(...extraArgs);
11
+ fn.returnHttp = false;
12
+ return res;
13
+ }
14
+ export { request as testBff };
@@ -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,11 @@
1
+ const patchAssetsModule = (testOperator) => {
2
+ testOperator.mergeJestConfig({
3
+ moduleNameMapper: {
4
+ "\\.(css|less|scss|sass)$": require.resolve("identity-obj-proxy"),
5
+ "\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": require.resolve("./filemock.js")
6
+ }
7
+ });
8
+ };
9
+ export {
10
+ patchAssetsModule
11
+ };