@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
@@ -0,0 +1,109 @@
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 * as ptr from "path-to-regexp";
18
+ import * as mockAppModule from "./app";
19
+ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
20
+ const keys = [];
21
+ ptr.pathToRegexp(url, keys);
22
+ const params = keys.reduce((cur, key, index) => {
23
+ if (paramValues[index]) {
24
+ cur[key.name] = paramValues[index];
25
+ }
26
+ return cur;
27
+ }, {});
28
+ const getFinalPath = ptr.compile(url, { encode: encodeURIComponent });
29
+ return getFinalPath(__spreadValues(__spreadValues({}, params), payload));
30
+ };
31
+ const mock_getParamsAndPayload = (args) => {
32
+ if (args.length === 0) {
33
+ return [[], {}];
34
+ }
35
+ const head = args[0];
36
+ if (typeof head === "object") {
37
+ return [[], head];
38
+ } else {
39
+ const latest = args[args.length - 1];
40
+ if (typeof latest === "object") {
41
+ return [args.slice(0, args.length - 1), latest];
42
+ } else {
43
+ return [args, {}];
44
+ }
45
+ }
46
+ };
47
+ var mockAPI_default = (mockApiInfosByFile) => {
48
+ const files = Object.keys(mockApiInfosByFile);
49
+ files.forEach((mockedFile) => {
50
+ jest.mock(mockedFile, () => {
51
+ const supertest = require("supertest");
52
+ return mockApiInfosByFile[mockedFile].reduce(
53
+ (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(
62
+ info.routePath,
63
+ params,
64
+ payload.params
65
+ );
66
+ const app = mockAppModule.getApp();
67
+ let test = supertest(app)[info.httpMethod.toLowerCase()](url);
68
+ if (payload.query) {
69
+ test = test.query(payload.query);
70
+ }
71
+ if (payload.body) {
72
+ test = test.send(payload.body);
73
+ }
74
+ if (payload.data) {
75
+ test = test.send(payload.data);
76
+ }
77
+ if (payload.headers) {
78
+ for (const name in payload.headers) {
79
+ test = test.set(name, payload.headers[name]);
80
+ }
81
+ }
82
+ if (payload.cookies) {
83
+ test = test.set("Cookie", [payload.cookies]);
84
+ }
85
+ if (returnHttp) {
86
+ return test;
87
+ }
88
+ return test.then((value) => {
89
+ try {
90
+ return JSON.parse(value.text);
91
+ } catch (e) {
92
+ return value.text;
93
+ }
94
+ });
95
+ }
96
+ };
97
+ res[info.name] = module[info.name];
98
+ Object.assign(res[info.name], info.handler);
99
+ res.__esModule = true;
100
+ return res;
101
+ },
102
+ {}
103
+ );
104
+ });
105
+ });
106
+ };
107
+ export {
108
+ mockAPI_default as default
109
+ };
@@ -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
+ };
@@ -0,0 +1,115 @@
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 path from "path";
22
+ import {
23
+ isApiOnly,
24
+ mergeAlias,
25
+ PLUGIN_SCHEMAS,
26
+ createRuntimeExportsUtils
27
+ } from "@modern-js/utils";
28
+ import {
29
+ testingHooks,
30
+ getModuleNameMapper,
31
+ DEFAULT_RESOLVER_PATH
32
+ } from "../base";
33
+ import { MODERNJS_CONFIG_KEY } from "../constant";
34
+ import testingBffPlugin from "./bff";
35
+ import test from "./test";
36
+ const mergeUserJestConfig = (testUtils) => {
37
+ const resolveJestConfig = testUtils.testConfig.jest;
38
+ if (resolveJestConfig && typeof resolveJestConfig !== "function") {
39
+ testUtils.mergeJestConfig(resolveJestConfig);
40
+ }
41
+ };
42
+ var cli_default = () => {
43
+ const bffPlugin = testingBffPlugin();
44
+ return {
45
+ name: "@modern-js/plugin-testing",
46
+ usePlugins: [bffPlugin],
47
+ post: [bffPlugin.name],
48
+ registerHook: testingHooks,
49
+ setup: (api) => {
50
+ let testingExportsUtils;
51
+ return {
52
+ commands: ({ program }) => {
53
+ program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(() => __async(void 0, null, function* () {
54
+ yield test(api);
55
+ }));
56
+ },
57
+ validateSchema() {
58
+ return PLUGIN_SCHEMAS["@modern-js/plugin-testing"];
59
+ },
60
+ config() {
61
+ const appContext = api.useAppContext();
62
+ testingExportsUtils = createRuntimeExportsUtils(
63
+ appContext.internalDirectory,
64
+ "testing"
65
+ );
66
+ return {
67
+ source: {
68
+ alias: {
69
+ "@": path.join(appContext.appDirectory, "src"),
70
+ "@modern-js/runtime/testing": testingExportsUtils.getPath()
71
+ }
72
+ }
73
+ };
74
+ },
75
+ addRuntimeExports() {
76
+ const testingPath = path.resolve(__dirname, "../");
77
+ testingExportsUtils.addExport(`export * from '${testingPath}'`);
78
+ },
79
+ jestConfig: (utils, next) => __async(void 0, null, function* () {
80
+ const appContext = api.useAppContext();
81
+ const userConfig = api.useResolvedConfigContext();
82
+ const apiOnly = yield isApiOnly(appContext.appDirectory);
83
+ if (apiOnly) {
84
+ return next(utils);
85
+ }
86
+ const alias = mergeAlias(userConfig.source.alias);
87
+ if (testingExportsUtils) {
88
+ alias["@modern-js/runtime/testing"] = [
89
+ testingExportsUtils.getPath()
90
+ ];
91
+ }
92
+ utils.mergeJestConfig({
93
+ globals: {
94
+ [MODERNJS_CONFIG_KEY]: userConfig
95
+ },
96
+ moduleNameMapper: getModuleNameMapper(alias),
97
+ testEnvironment: "jsdom",
98
+ resolver: DEFAULT_RESOLVER_PATH,
99
+ rootDir: appContext.appDirectory || process.cwd(),
100
+ testMatch: [
101
+ `<rootDir>/src/**/*.test.[jt]s?(x)`,
102
+ `<rootDir>/tests/**/*.test.[jt]s?(x)`
103
+ ]
104
+ });
105
+ mergeUserJestConfig(utils);
106
+ return next(utils);
107
+ })
108
+ };
109
+ }
110
+ };
111
+ };
112
+ export {
113
+ cli_default as default,
114
+ mergeUserJestConfig
115
+ };
@@ -0,0 +1,61 @@
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 path from "path";
22
+ import { compiler } from "@modern-js/babel-compiler";
23
+ import { runTest } from "../base";
24
+ const test = (api) => __async(void 0, null, function* () {
25
+ var _a, _b;
26
+ const userConfig = api.useResolvedConfigContext();
27
+ const appContext = api.useAppContext();
28
+ userConfig.testing = userConfig.testing || {};
29
+ const jest = userConfig.testing.jest || ((_a = userConfig == null ? void 0 : userConfig.tools) == null ? void 0 : _a.jest);
30
+ if (Array.isArray(jest)) {
31
+ userConfig.testing.jest = jest[0];
32
+ }
33
+ userConfig.testing.jest = userConfig.testing.jest || ((_b = userConfig == null ? void 0 : userConfig.tools) == null ? void 0 : _b.jest);
34
+ const runtimeExportsPath = path.join(
35
+ appContext.internalDirectory,
36
+ ".runtime-exports"
37
+ );
38
+ yield compiler(
39
+ {
40
+ sourceDir: runtimeExportsPath,
41
+ rootDir: runtimeExportsPath,
42
+ distDir: runtimeExportsPath,
43
+ quiet: true
44
+ },
45
+ {
46
+ presets: [
47
+ [
48
+ require.resolve("@babel/preset-env"),
49
+ {
50
+ modules: "cjs"
51
+ }
52
+ ]
53
+ ]
54
+ }
55
+ );
56
+ yield runTest(api, userConfig.testing);
57
+ });
58
+ var test_default = test;
59
+ export {
60
+ test_default as default
61
+ };
@@ -0,0 +1,4 @@
1
+ const MODERNJS_CONFIG_KEY = "__modernjs_config__";
2
+ export {
3
+ MODERNJS_CONFIG_KEY
4
+ };
@@ -0,0 +1,3 @@
1
+ import "@testing-library/jest-dom/extend-expect";
2
+ import "@testing-library/jest-dom";
3
+ export * from "./runtime-testing";
@@ -0,0 +1,48 @@
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 { createApp } from "@modern-js/runtime";
18
+ import { MODERNJS_CONFIG_KEY } from "../constant";
19
+ import resolvePlugins from "./resolvePlugins";
20
+ class ModernRuntime {
21
+ constructor(options) {
22
+ this.options = options;
23
+ }
24
+ init(options) {
25
+ this.options = options;
26
+ }
27
+ createApp(props) {
28
+ var _a, _b;
29
+ const { entry, children } = props || {};
30
+ let runtimeFeatures = (_a = this.options) == null ? void 0 : _a.runtime;
31
+ if (entry) {
32
+ runtimeFeatures = __spreadValues(__spreadValues({}, runtimeFeatures || {}), (_b = this.options.runtimeByEntries) == null ? void 0 : _b[entry]);
33
+ }
34
+ const Component = () => {
35
+ if (!children) {
36
+ return null;
37
+ }
38
+ return children;
39
+ };
40
+ return createApp({
41
+ plugins: resolvePlugins(runtimeFeatures || {})
42
+ })(Component);
43
+ }
44
+ }
45
+ var app_default = new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
46
+ export {
47
+ app_default as default
48
+ };
@@ -0,0 +1,7 @@
1
+ import { default as default2 } from "./customRender";
2
+ export * from "@testing-library/react";
3
+ import { request } from "./request";
4
+ export {
5
+ default2 as renderApp,
6
+ request as testBff
7
+ };
@@ -0,0 +1,25 @@
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 React from "react";
18
+ import { render } from "@testing-library/react";
19
+ import app from "./app";
20
+ const WrapModernProviders = (props) => React.createElement(app.createApp(props));
21
+ const customRender = (ui, options) => render(ui, __spreadValues({ wrapper: WrapModernProviders }, options));
22
+ var customRender_default = customRender;
23
+ export {
24
+ customRender_default as default
25
+ };
@@ -0,0 +1,2 @@
1
+ export * from "./base";
2
+ export * from "./reduck";
@@ -0,0 +1,55 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import { createStore as originCreateStore } from "@modern-js-reduck/store";
21
+ import effectsPlugin from "@modern-js-reduck/plugin-effects";
22
+ import autoActionsPlugin from "@modern-js-reduck/plugin-auto-actions";
23
+ import immerPlugin from "@modern-js-reduck/plugin-immutable";
24
+ import { MODERNJS_CONFIG_KEY } from "../constant";
25
+ const effects = () => effectsPlugin;
26
+ const immer = () => immerPlugin;
27
+ const autoActions = () => autoActionsPlugin;
28
+ const createStore = (props) => {
29
+ const createStatePlugins = () => {
30
+ var _a;
31
+ const modernConfig = global[MODERNJS_CONFIG_KEY];
32
+ const stateConfig = (_a = modernConfig == null ? void 0 : modernConfig.runtime) == null ? void 0 : _a.state;
33
+ const plugins = [];
34
+ if ((stateConfig == null ? void 0 : stateConfig.effects) !== false) {
35
+ plugins.push(effects());
36
+ }
37
+ if ((stateConfig == null ? void 0 : stateConfig.autoActions) !== false) {
38
+ plugins.push(autoActions());
39
+ }
40
+ if ((stateConfig == null ? void 0 : stateConfig.immer) !== false) {
41
+ plugins.push(immer());
42
+ }
43
+ return ((props == null ? void 0 : props.plugins) || []).concat(plugins);
44
+ };
45
+ const config = __spreadProps(__spreadValues({}, props || {}), {
46
+ plugins: createStatePlugins()
47
+ });
48
+ return originCreateStore(config);
49
+ };
50
+ export {
51
+ autoActions,
52
+ createStore,
53
+ effects,
54
+ immer
55
+ };
@@ -11,4 +11,6 @@ function request(...args) {
11
11
  fn.returnHttp = false;
12
12
  return res;
13
13
  }
14
- export { request };
14
+ export {
15
+ request
16
+ };
@@ -0,0 +1,33 @@
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
+ const allowedFeatures = ["router", "state"];
18
+ function resolvePlugins(features) {
19
+ const plugins = [];
20
+ if (!features) {
21
+ return plugins;
22
+ }
23
+ Object.keys(features).forEach((feature) => {
24
+ if (allowedFeatures.includes(feature)) {
25
+ const curPluginRes = require(`@modern-js/runtime/plugins`)[feature](__spreadValues({}, features[feature]));
26
+ plugins.push(curPluginRes);
27
+ }
28
+ });
29
+ return plugins;
30
+ }
31
+ export {
32
+ resolvePlugins as default
33
+ };
@@ -0,0 +1,67 @@
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 config_exports = {};
45
+ __export(config_exports, {
46
+ DEFAULT_RESOLVER_PATH: () => DEFAULT_RESOLVER_PATH,
47
+ getJestUtils: () => getJestUtils,
48
+ patchConfig: () => patchConfig
49
+ });
50
+ module.exports = __toCommonJS(config_exports);
51
+ var import_patches = require("./patches");
52
+ var import_testConfigOperator = require("./testConfigOperator");
53
+ const getJestUtils = (testConfig) => {
54
+ const testOperator = new import_testConfigOperator.TestConfigOperator(testConfig);
55
+ return testOperator;
56
+ };
57
+ const patchConfig = (testOperator) => __async(void 0, null, function* () {
58
+ yield (0, import_patches.applyPatches)(testOperator);
59
+ return testOperator.jestConfig;
60
+ });
61
+ const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
62
+ // Annotate the CommonJS export names for ESM import in node:
63
+ 0 && (module.exports = {
64
+ DEFAULT_RESOLVER_PATH,
65
+ getJestUtils,
66
+ patchConfig
67
+ });