@modern-js/plugin-testing 2.14.0 → 2.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/cjs/base/config/index.js +15 -39
  3. package/dist/cjs/base/config/patches/assetsModule.js +7 -35
  4. package/dist/cjs/base/config/patches/filemock.js +8 -24
  5. package/dist/cjs/base/config/patches/index.js +13 -28
  6. package/dist/cjs/base/config/patches/transformer.js +13 -38
  7. package/dist/cjs/base/config/resolver.js +23 -26
  8. package/dist/cjs/base/config/testConfigOperator.js +39 -38
  9. package/dist/cjs/base/config/transformer/babelTransformer.js +16 -37
  10. package/dist/cjs/base/hook.js +17 -31
  11. package/dist/cjs/base/index.js +36 -41
  12. package/dist/cjs/base/runJest.js +31 -57
  13. package/dist/cjs/base/types/index.js +4 -15
  14. package/dist/cjs/base/utils.js +30 -53
  15. package/dist/cjs/cli/bff/app.js +17 -32
  16. package/dist/cjs/cli/bff/constant.js +7 -25
  17. package/dist/cjs/cli/bff/index.js +71 -92
  18. package/dist/cjs/cli/bff/mockAPI.js +115 -92
  19. package/dist/cjs/cli/bff/setup.js +30 -51
  20. package/dist/cjs/cli/bff/utils/index.js +21 -45
  21. package/dist/cjs/cli/index.js +43 -59
  22. package/dist/cjs/cli/test.js +35 -62
  23. package/dist/cjs/constant.js +7 -25
  24. package/dist/cjs/index.js +20 -19
  25. package/dist/cjs/runtime-testing/app.js +40 -45
  26. package/dist/cjs/runtime-testing/base.js +34 -40
  27. package/dist/cjs/runtime-testing/customRender.js +21 -39
  28. package/dist/cjs/runtime-testing/index.js +19 -18
  29. package/dist/cjs/runtime-testing/reduck.js +35 -55
  30. package/dist/cjs/runtime-testing/request.js +16 -39
  31. package/dist/cjs/runtime-testing/resolvePlugins.js +12 -25
  32. package/dist/esm/base/config/index.js +146 -139
  33. package/dist/esm/base/config/patches/assetsModule.js +7 -8
  34. package/dist/esm/base/config/patches/filemock.js +1 -2
  35. package/dist/esm/base/config/patches/index.js +214 -207
  36. package/dist/esm/base/config/patches/transformer.js +27 -28
  37. package/dist/esm/base/config/resolver.js +22 -35
  38. package/dist/esm/base/config/testConfigOperator.js +119 -116
  39. package/dist/esm/base/config/transformer/babelTransformer.js +12 -13
  40. package/dist/esm/base/hook.js +5 -6
  41. package/dist/esm/base/index.js +5 -6
  42. package/dist/esm/base/runJest.js +270 -264
  43. package/dist/esm/base/types/index.js +1 -1
  44. package/dist/esm/base/utils.js +66 -67
  45. package/dist/esm/cli/bff/app.js +187 -179
  46. package/dist/esm/cli/bff/constant.js +1 -2
  47. package/dist/esm/cli/bff/index.js +285 -278
  48. package/dist/esm/cli/bff/mockAPI.js +177 -163
  49. package/dist/esm/cli/bff/setup.js +182 -174
  50. package/dist/esm/cli/bff/utils/index.js +40 -41
  51. package/dist/esm/cli/index.js +249 -242
  52. package/dist/esm/cli/test.js +172 -166
  53. package/dist/esm/constant.js +1 -2
  54. package/dist/esm/runtime-testing/app.js +79 -77
  55. package/dist/esm/runtime-testing/base.js +2 -3
  56. package/dist/esm/runtime-testing/customRender.js +30 -31
  57. package/dist/esm/runtime-testing/reduck.js +72 -73
  58. package/dist/esm/runtime-testing/request.js +55 -45
  59. package/dist/esm/runtime-testing/resolvePlugins.js +38 -39
  60. package/dist/esm-node/base/config/index.js +2 -6
  61. package/dist/esm-node/base/config/patches/assetsModule.js +1 -4
  62. package/dist/esm-node/base/config/patches/filemock.js +1 -4
  63. package/dist/esm-node/base/config/patches/index.js +5 -5
  64. package/dist/esm-node/base/config/patches/transformer.js +5 -5
  65. package/dist/esm-node/base/config/resolver.js +20 -19
  66. package/dist/esm-node/base/config/testConfigOperator.js +30 -13
  67. package/dist/esm-node/base/config/transformer/babelTransformer.js +3 -6
  68. package/dist/esm-node/base/hook.js +3 -8
  69. package/dist/esm-node/base/index.js +5 -13
  70. package/dist/esm-node/base/runJest.js +8 -20
  71. package/dist/esm-node/base/types/index.js +1 -0
  72. package/dist/esm-node/base/utils.js +8 -17
  73. package/dist/esm-node/cli/bff/app.js +2 -7
  74. package/dist/esm-node/cli/bff/constant.js +1 -4
  75. package/dist/esm-node/cli/bff/index.js +43 -54
  76. package/dist/esm-node/cli/bff/mockAPI.js +65 -59
  77. package/dist/esm-node/cli/bff/setup.js +11 -19
  78. package/dist/esm-node/cli/bff/utils/index.js +6 -10
  79. package/dist/esm-node/cli/index.js +11 -23
  80. package/dist/esm-node/cli/test.js +19 -28
  81. package/dist/esm-node/constant.js +1 -4
  82. package/dist/esm-node/runtime-testing/app.js +22 -10
  83. package/dist/esm-node/runtime-testing/base.js +2 -6
  84. package/dist/esm-node/runtime-testing/customRender.js +5 -5
  85. package/dist/esm-node/runtime-testing/reduck.js +10 -16
  86. package/dist/esm-node/runtime-testing/request.js +1 -3
  87. package/dist/esm-node/runtime-testing/resolvePlugins.js +6 -6
  88. package/package.json +18 -14
@@ -1,8 +1,8 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
  import { createDebugger } from "@modern-js/utils";
4
- const debug = createDebugger("test");
5
- const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
4
+ export const debug = createDebugger("test");
5
+ export const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") => {
6
6
  let tsConfig = {};
7
7
  let extendedCompilerOptions = {};
8
8
  let tsconfigFile = "";
@@ -13,26 +13,22 @@ const readCompilerOptions = (pwd = process.cwd(), filename = "tsconfig.json") =>
13
13
  } else {
14
14
  tsconfigFile = require.resolve(filename);
15
15
  }
16
- ({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(
17
- tsconfigFile,
18
- fs.readFileSync(tsconfigFile, "utf8")
19
- ));
16
+ ({ config: tsConfig } = require("typescript").parseConfigFileTextToJson(tsconfigFile, fs.readFileSync(tsconfigFile, "utf8")));
20
17
  } catch (e) {
21
18
  return {};
22
19
  }
23
20
  if (tsConfig.extends) {
24
- extendedCompilerOptions = readCompilerOptions(
25
- path.dirname(tsconfigFile),
26
- tsConfig.extends
27
- );
21
+ extendedCompilerOptions = readCompilerOptions(path.dirname(tsconfigFile), tsConfig.extends);
28
22
  }
29
23
  return {
30
24
  ...extendedCompilerOptions,
31
25
  ...tsConfig.compilerOptions
32
26
  };
33
27
  };
34
- const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
35
- const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [alias[cur]];
28
+ export const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) => {
29
+ const aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [
30
+ alias[cur]
31
+ ];
36
32
  const isFile = aliasValue.some((s) => s.endsWith(".js"));
37
33
  if (cur === "@modern-js/runtime$") {
38
34
  memo[`.+${cur}`] = aliasValue[0];
@@ -46,8 +42,3 @@ const getModuleNameMapper = (alias) => Object.keys(alias).reduce((memo, cur) =>
46
42
  memo[key] = value;
47
43
  return memo;
48
44
  }, {});
49
- export {
50
- debug,
51
- getModuleNameMapper,
52
- readCompilerOptions
53
- };
@@ -1,7 +1,7 @@
1
1
  import { AsyncLocalStorage } from "async_hooks";
2
2
  import { Server } from "@modern-js/prod-server";
3
3
  const store = new AsyncLocalStorage();
4
- const isInHandler = () => Boolean(store.getStore());
4
+ export const isInHandler = () => Boolean(store.getStore());
5
5
  let server = null;
6
6
  const createApp = async (pwd, config, plugins, routes) => {
7
7
  if (!server) {
@@ -30,9 +30,4 @@ const closeServer = async () => {
30
30
  }
31
31
  await server.close();
32
32
  };
33
- export {
34
- closeServer,
35
- createApp,
36
- getApp,
37
- isInHandler
38
- };
33
+ export { createApp, getApp, closeServer };
@@ -1,4 +1 @@
1
- const bff_info_key = "modern_bff_info";
2
- export {
3
- bff_info_key
4
- };
1
+ export const bff_info_key = "modern_bff_info";
@@ -1,24 +1,19 @@
1
1
  import path from "path";
2
2
  import { isApiOnly } from "@modern-js/utils";
3
- import {
4
- getModuleNameMapper,
5
- DEFAULT_RESOLVER_PATH
6
- } from "../../base";
3
+ import { getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../../base";
7
4
  import { bff_info_key } from "./constant";
8
5
  import { isBFFProject } from "./utils";
9
- const setJestConfigForBFF = async ({
10
- pwd,
11
- userConfig,
12
- plugins,
13
- routes,
14
- utils
15
- }) => {
16
- var _a;
6
+ export const setJestConfigForBFF = async ({ pwd, userConfig, plugins, routes, utils }) => {
7
+ var _userConfig_source;
17
8
  const bffConfig = {
18
9
  rootDir: path.join(pwd, "./api"),
19
- setupFilesAfterEnv: [require.resolve("./setup")],
10
+ setupFilesAfterEnv: [
11
+ require.resolve("./setup")
12
+ ],
20
13
  testEnvironment: "node",
21
- testMatch: [`**/api/**/*.test.[jt]s`],
14
+ testMatch: [
15
+ `**/api/**/*.test.[jt]s`
16
+ ],
22
17
  globals: {
23
18
  [bff_info_key]: {
24
19
  appDir: pwd,
@@ -29,7 +24,7 @@ const setJestConfigForBFF = async ({
29
24
  }
30
25
  };
31
26
  const { jestConfig } = utils;
32
- const alias = ((_a = userConfig == null ? void 0 : userConfig.source) == null ? void 0 : _a.alias) || {};
27
+ const alias = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.alias) || {};
33
28
  const aliasMapper = getModuleNameMapper(alias);
34
29
  const { moduleNameMapper } = jestConfig;
35
30
  const transform = {
@@ -48,7 +43,11 @@ const setJestConfigForBFF = async ({
48
43
  ...aliasMapper
49
44
  };
50
45
  const resolver = jestConfig.resolver || DEFAULT_RESOLVER_PATH;
51
- const configFields = ["coverage", "collectCoverage", "testTimeout"];
46
+ const configFields = [
47
+ "coverage",
48
+ "collectCoverage",
49
+ "testTimeout"
50
+ ];
52
51
  const commonConfig = configFields.reduce((obj, field) => {
53
52
  if (jestConfig.hasOwnProperty(field)) {
54
53
  obj[field] = jestConfig[field];
@@ -56,44 +55,38 @@ const setJestConfigForBFF = async ({
56
55
  return obj;
57
56
  }, {});
58
57
  if (!apiOnly) {
59
- utils.setJestConfig(
60
- {
61
- projects: [
62
- {
63
- ...jestConfig
64
- },
65
- {
66
- transform,
67
- moduleNameMapper: mergedModuleNameMapper,
68
- resolver,
69
- ...bffConfig
70
- }
71
- ]
72
- },
73
- {
74
- force: true
75
- }
76
- );
58
+ utils.setJestConfig({
59
+ projects: [
60
+ {
61
+ ...jestConfig
62
+ },
63
+ {
64
+ transform,
65
+ moduleNameMapper: mergedModuleNameMapper,
66
+ resolver,
67
+ ...bffConfig
68
+ }
69
+ ]
70
+ }, {
71
+ force: true
72
+ });
77
73
  } else {
78
- utils.setJestConfig(
79
- {
80
- projects: [
81
- {
82
- transform,
83
- moduleNameMapper: mergedModuleNameMapper,
84
- resolver,
85
- ...bffConfig
86
- }
87
- ]
88
- },
89
- {
90
- force: true
91
- }
92
- );
74
+ utils.setJestConfig({
75
+ projects: [
76
+ {
77
+ transform,
78
+ moduleNameMapper: mergedModuleNameMapper,
79
+ resolver,
80
+ ...bffConfig
81
+ }
82
+ ]
83
+ }, {
84
+ force: true
85
+ });
93
86
  }
94
87
  utils.setJestConfig(commonConfig);
95
88
  };
96
- var bff_default = () => ({
89
+ export default () => ({
97
90
  name: "@modern-js/testing-plugin-bff",
98
91
  setup(api) {
99
92
  return {
@@ -116,7 +109,3 @@ var bff_default = () => ({
116
109
  };
117
110
  }
118
111
  });
119
- export {
120
- bff_default as default,
121
- setJestConfigForBFF
122
- };
@@ -9,7 +9,9 @@ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
9
9
  }
10
10
  return cur;
11
11
  }, {});
12
- const getFinalPath = ptr.compile(url, { encode: encodeURIComponent });
12
+ const getFinalPath = ptr.compile(url, {
13
+ encode: encodeURIComponent
14
+ });
13
15
  return getFinalPath({
14
16
  ...params,
15
17
  ...payload
@@ -17,80 +19,84 @@ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
17
19
  };
18
20
  const mock_getParamsAndPayload = (args) => {
19
21
  if (args.length === 0) {
20
- return [[], {}];
22
+ return [
23
+ [],
24
+ {}
25
+ ];
21
26
  }
22
27
  const head = args[0];
23
28
  if (typeof head === "object") {
24
- return [[], head];
29
+ return [
30
+ [],
31
+ head
32
+ ];
25
33
  } else {
26
34
  const latest = args[args.length - 1];
27
35
  if (typeof latest === "object") {
28
- return [args.slice(0, args.length - 1), latest];
36
+ return [
37
+ args.slice(0, args.length - 1),
38
+ latest
39
+ ];
29
40
  } else {
30
- return [args, {}];
41
+ return [
42
+ args,
43
+ {}
44
+ ];
31
45
  }
32
46
  }
33
47
  };
34
- var mockAPI_default = (mockApiInfosByFile) => {
48
+ export default (mockApiInfosByFile) => {
35
49
  const files = Object.keys(mockApiInfosByFile);
36
50
  files.forEach((mockedFile) => {
37
51
  jest.mock(mockedFile, () => {
38
52
  const supertest = require("supertest");
39
- return mockApiInfosByFile[mockedFile].reduce(
40
- (res, info) => {
41
- const module = {
42
- [info.name]: (...args) => {
43
- if (mockAppModule.isInHandler()) {
44
- return info.handler(...args);
45
- }
46
- const [params, payload] = mock_getParamsAndPayload(args);
47
- const { returnHttp } = module[info.name];
48
- const url = mock_replaceUrlWithParams(
49
- info.routePath,
50
- params,
51
- payload.params
52
- );
53
- const app = mockAppModule.getApp();
54
- let test = supertest(app)[info.httpMethod.toLowerCase()](url);
55
- if (payload.query) {
56
- test = test.query(payload.query);
57
- }
58
- if (payload.body) {
59
- test = test.send(payload.body);
60
- }
61
- if (payload.data) {
62
- test = test.send(payload.data);
63
- }
64
- if (payload.headers) {
65
- for (const name in payload.headers) {
66
- test = test.set(name, payload.headers[name]);
67
- }
68
- }
69
- if (payload.cookies) {
70
- test = test.set("Cookie", [payload.cookies]);
71
- }
72
- if (returnHttp) {
73
- return test;
53
+ return mockApiInfosByFile[mockedFile].reduce((res, info) => {
54
+ const module = {
55
+ [info.name]: (...args) => {
56
+ if (mockAppModule.isInHandler()) {
57
+ return info.handler(...args);
58
+ }
59
+ const [params, payload] = mock_getParamsAndPayload(args);
60
+ const { returnHttp } = module[info.name];
61
+ const url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
62
+ const app = mockAppModule.getApp();
63
+ let test = supertest(app)[info.httpMethod.toLowerCase()](url);
64
+ if (payload.query) {
65
+ test = test.query(payload.query);
66
+ }
67
+ if (payload.body) {
68
+ test = test.send(payload.body);
69
+ }
70
+ if (payload.data) {
71
+ test = test.send(payload.data);
72
+ }
73
+ if (payload.headers) {
74
+ for (const name in payload.headers) {
75
+ test = test.set(name, payload.headers[name]);
74
76
  }
75
- return test.then((value) => {
76
- try {
77
- return JSON.parse(value.text);
78
- } catch {
79
- return value.text;
80
- }
81
- });
82
77
  }
83
- };
84
- res[info.name] = module[info.name];
85
- Object.assign(res[info.name], info.handler);
86
- res.__esModule = true;
87
- return res;
88
- },
89
- {}
90
- );
78
+ if (payload.cookies) {
79
+ test = test.set("Cookie", [
80
+ payload.cookies
81
+ ]);
82
+ }
83
+ if (returnHttp) {
84
+ return test;
85
+ }
86
+ return test.then((value) => {
87
+ try {
88
+ return JSON.parse(value.text);
89
+ } catch {
90
+ return value.text;
91
+ }
92
+ });
93
+ }
94
+ };
95
+ res[info.name] = module[info.name];
96
+ Object.assign(res[info.name], info.handler);
97
+ res.__esModule = true;
98
+ return res;
99
+ }, {});
91
100
  });
92
101
  });
93
102
  };
94
- export {
95
- mockAPI_default as default
96
- };
@@ -5,39 +5,31 @@ import mockAPI from "./mockAPI";
5
5
  import { createApp, closeServer } from "./app";
6
6
  let uped = false;
7
7
  const setup = () => {
8
- var _a, _b, _c, _d;
8
+ var _bff_info_modernUserConfig, _bff_info_modernUserConfig_bff, _bff_info_modernUserConfig1, _bff_info_modernUserConfig_bff1;
9
9
  if (uped) {
10
10
  return;
11
11
  }
12
12
  uped = true;
13
13
  const bff_info = global[bff_info_key];
14
- const prefix = (_b = (_a = bff_info == null ? void 0 : bff_info.modernUserConfig) == null ? void 0 : _a.bff) == null ? void 0 : _b.prefix;
15
- const httpMethodDecider = (_d = (_c = bff_info == null ? void 0 : bff_info.modernUserConfig) == null ? void 0 : _c.bff) == null ? void 0 : _d.httpMethodDecider;
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
+ 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
16
  const apiRouter = new ApiRouter({
17
17
  apiDir: path.join(bff_info.appDir, "./api"),
18
18
  prefix,
19
19
  httpMethodDecider
20
20
  });
21
21
  const apiInfos = apiRouter.getApiHandlers();
22
- const apiInfosByFile = apiInfos.reduce(
23
- (res, apiInfo) => {
24
- if (!res[apiInfo.filename]) {
25
- res[apiInfo.filename] = [];
26
- }
27
- res[apiInfo.filename].push(apiInfo);
28
- return res;
29
- },
30
- {}
31
- );
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
+ }, {});
32
29
  let app = null;
33
30
  beforeAll(async () => {
34
31
  if (!app) {
35
- app = await createApp(
36
- bff_info.appDir,
37
- bff_info.modernUserConfig,
38
- bff_info.plugins,
39
- bff_info.routes
40
- );
32
+ app = await createApp(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
41
33
  }
42
34
  });
43
35
  afterAll(async () => {
@@ -1,21 +1,17 @@
1
1
  import path from "path";
2
2
  import { chalk } from "@modern-js/utils";
3
- const isBFFProject = (pwd) => {
3
+ export const isBFFProject = (pwd) => {
4
4
  try {
5
5
  const packageJson = require(path.join(pwd, "./package.json"));
6
6
  const { dependencies, devDependencies } = packageJson;
7
- const isBFF = Object.keys({ ...dependencies, ...devDependencies }).some(
8
- (dependency) => dependency.includes("plugin-bff")
9
- );
10
- const isMWA = Object.keys(devDependencies).some(
11
- (devDependency) => devDependency.includes("app-tools")
12
- );
7
+ const isBFF = Object.keys({
8
+ ...dependencies,
9
+ ...devDependencies
10
+ }).some((dependency) => dependency.includes("plugin-bff"));
11
+ const isMWA = Object.keys(devDependencies).some((devDependency) => devDependency.includes("app-tools"));
13
12
  return isMWA && isBFF;
14
13
  } catch (error) {
15
14
  console.log(chalk.red(error));
16
15
  return false;
17
16
  }
18
17
  };
19
- export {
20
- isBFFProject
21
- };
@@ -1,30 +1,25 @@
1
1
  import path from "path";
2
- import {
3
- isApiOnly,
4
- mergeAlias,
5
- PLUGIN_SCHEMAS,
6
- createRuntimeExportsUtils
7
- } from "@modern-js/utils";
8
- import {
9
- testingHooks,
10
- getModuleNameMapper,
11
- DEFAULT_RESOLVER_PATH
12
- } from "../base";
2
+ import { isApiOnly, mergeAlias, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from "@modern-js/utils";
3
+ import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../base";
13
4
  import { MODERNJS_CONFIG_KEY } from "../constant";
14
5
  import testingBffPlugin from "./bff";
15
6
  import test from "./test";
16
- const mergeUserJestConfig = (testUtils) => {
7
+ export const mergeUserJestConfig = (testUtils) => {
17
8
  const resolveJestConfig = testUtils.testConfig.jest;
18
9
  if (resolveJestConfig && typeof resolveJestConfig !== "function") {
19
10
  testUtils.mergeJestConfig(resolveJestConfig);
20
11
  }
21
12
  };
22
- var cli_default = () => {
13
+ export default () => {
23
14
  const bffPlugin = testingBffPlugin();
24
15
  return {
25
16
  name: "@modern-js/plugin-testing",
26
- usePlugins: [bffPlugin],
27
- post: [bffPlugin.name],
17
+ usePlugins: [
18
+ bffPlugin
19
+ ],
20
+ post: [
21
+ bffPlugin.name
22
+ ],
28
23
  registerHook: testingHooks,
29
24
  setup: (api) => {
30
25
  let testingExportsUtils;
@@ -39,10 +34,7 @@ var cli_default = () => {
39
34
  },
40
35
  config() {
41
36
  const appContext = api.useAppContext();
42
- testingExportsUtils = createRuntimeExportsUtils(
43
- appContext.internalDirectory,
44
- "testing"
45
- );
37
+ testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "testing");
46
38
  return {
47
39
  source: {
48
40
  alias: {
@@ -92,7 +84,3 @@ var cli_default = () => {
92
84
  }
93
85
  };
94
86
  };
95
- export {
96
- cli_default as default,
97
- mergeUserJestConfig
98
- };
@@ -2,40 +2,31 @@ import path from "path";
2
2
  import { compiler } from "@modern-js/babel-compiler";
3
3
  import { runTest } from "../base";
4
4
  const test = async (api) => {
5
- var _a, _b;
5
+ var _userConfig_tools, _userConfig_tools1;
6
6
  const userConfig = api.useResolvedConfigContext();
7
7
  const appContext = api.useAppContext();
8
8
  userConfig.testing = userConfig.testing || {};
9
- const jest = userConfig.testing.jest || ((_a = userConfig == null ? void 0 : userConfig.tools) == null ? void 0 : _a.jest);
9
+ const jest = userConfig.testing.jest || (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_tools = userConfig.tools) === null || _userConfig_tools === void 0 ? void 0 : _userConfig_tools.jest);
10
10
  if (Array.isArray(jest)) {
11
11
  userConfig.testing.jest = jest[0];
12
12
  }
13
- userConfig.testing.jest = userConfig.testing.jest || ((_b = userConfig == null ? void 0 : userConfig.tools) == null ? void 0 : _b.jest);
14
- const runtimeExportsPath = path.join(
15
- appContext.internalDirectory,
16
- ".runtime-exports"
17
- );
18
- await compiler(
19
- {
20
- sourceDir: runtimeExportsPath,
21
- rootDir: runtimeExportsPath,
22
- distDir: runtimeExportsPath,
23
- quiet: true
24
- },
25
- {
26
- presets: [
27
- [
28
- require.resolve("@babel/preset-env"),
29
- {
30
- modules: "cjs"
31
- }
32
- ]
13
+ userConfig.testing.jest = userConfig.testing.jest || (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_tools1 = userConfig.tools) === null || _userConfig_tools1 === void 0 ? void 0 : _userConfig_tools1.jest);
14
+ const runtimeExportsPath = path.join(appContext.internalDirectory, ".runtime-exports");
15
+ await compiler({
16
+ sourceDir: runtimeExportsPath,
17
+ rootDir: runtimeExportsPath,
18
+ distDir: runtimeExportsPath,
19
+ quiet: true
20
+ }, {
21
+ presets: [
22
+ [
23
+ require.resolve("@babel/preset-env"),
24
+ {
25
+ modules: "cjs"
26
+ }
33
27
  ]
34
- }
35
- );
28
+ ]
29
+ });
36
30
  await runTest(api, userConfig.testing);
37
31
  };
38
- var test_default = test;
39
- export {
40
- test_default as default
41
- };
32
+ export default test;
@@ -1,4 +1 @@
1
- const MODERNJS_CONFIG_KEY = "__modernjs_config__";
2
- export {
3
- MODERNJS_CONFIG_KEY
4
- };
1
+ export const MODERNJS_CONFIG_KEY = "__modernjs_config__";
@@ -1,21 +1,32 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
1
14
  import { createApp } from "@modern-js/runtime";
2
15
  import { MODERNJS_CONFIG_KEY } from "../constant";
3
16
  import resolvePlugins from "./resolvePlugins";
4
17
  class ModernRuntime {
5
- constructor(options) {
6
- this.options = options;
7
- }
8
18
  init(options) {
9
19
  this.options = options;
10
20
  }
11
21
  createApp(props) {
12
- var _a, _b;
22
+ var _this_options;
13
23
  const { entry, children } = props || {};
14
- let runtimeFeatures = (_a = this.options) == null ? void 0 : _a.runtime;
24
+ let runtimeFeatures = (_this_options = this.options) === null || _this_options === void 0 ? void 0 : _this_options.runtime;
15
25
  if (entry) {
26
+ var _this_options_runtimeByEntries;
16
27
  runtimeFeatures = {
17
28
  ...runtimeFeatures || {},
18
- ...(_b = this.options.runtimeByEntries) == null ? void 0 : _b[entry]
29
+ ...(_this_options_runtimeByEntries = this.options.runtimeByEntries) === null || _this_options_runtimeByEntries === void 0 ? void 0 : _this_options_runtimeByEntries[entry]
19
30
  };
20
31
  }
21
32
  const Component = () => {
@@ -28,8 +39,9 @@ class ModernRuntime {
28
39
  plugins: resolvePlugins(runtimeFeatures || {})
29
40
  })(Component);
30
41
  }
42
+ constructor(options) {
43
+ _define_property(this, "options", void 0);
44
+ this.options = options;
45
+ }
31
46
  }
32
- var app_default = new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
33
- export {
34
- app_default as default
35
- };
47
+ export default new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
@@ -1,7 +1,3 @@
1
- import { default as default2 } from "./customRender";
1
+ export { default as renderApp } from "./customRender";
2
2
  export * from "@testing-library/react";
3
- import { request } from "./request";
4
- export {
5
- default2 as renderApp,
6
- request as testBff
7
- };
3
+ export { request as testBff } from "./request";
@@ -2,8 +2,8 @@ import React from "react";
2
2
  import { render } from "@testing-library/react";
3
3
  import app from "./app";
4
4
  const WrapModernProviders = (props) => React.createElement(app.createApp(props));
5
- const customRender = (ui, options) => render(ui, { wrapper: WrapModernProviders, ...options });
6
- var customRender_default = customRender;
7
- export {
8
- customRender_default as default
9
- };
5
+ const customRender = (ui, options) => render(ui, {
6
+ wrapper: WrapModernProviders,
7
+ ...options
8
+ });
9
+ export default customRender;