@modern-js/plugin-testing 2.0.0-beta.3 → 2.0.0-beta.6

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 (106) hide show
  1. package/CHANGELOG.md +159 -0
  2. package/dist/js/modern/base/config/index.js +29 -9
  3. package/dist/js/modern/base/config/patches/assetsModule.js +7 -7
  4. package/dist/js/modern/base/config/patches/filemock.js +4 -1
  5. package/dist/js/modern/base/config/patches/index.js +30 -7
  6. package/dist/js/modern/base/config/patches/transformer.js +13 -18
  7. package/dist/js/modern/base/config/resolver.js +20 -11
  8. package/dist/js/modern/base/config/testConfigOperator.js +29 -23
  9. package/dist/js/modern/base/config/transformer/babelTransformer.js +16 -8
  10. package/dist/js/modern/base/hook.js +10 -5
  11. package/dist/js/modern/base/index.js +14 -6
  12. package/dist/js/modern/base/runJest.js +73 -62
  13. package/dist/js/modern/base/utils.js +40 -23
  14. package/dist/js/modern/cli/bff/app.js +37 -12
  15. package/dist/js/modern/cli/bff/constant.js +4 -1
  16. package/dist/js/modern/cli/bff/index.js +95 -52
  17. package/dist/js/modern/cli/bff/mockAPI.js +79 -64
  18. package/dist/js/modern/cli/bff/setup.js +71 -34
  19. package/dist/js/modern/cli/bff/utils/index.js +31 -15
  20. package/dist/js/modern/cli/index.js +65 -30
  21. package/dist/js/modern/cli/test.js +53 -18
  22. package/dist/js/modern/constant.js +4 -1
  23. package/dist/js/modern/index.js +3 -3
  24. package/dist/js/modern/modern-app.env.d.js +0 -0
  25. package/dist/js/modern/runtime-testing/app.js +25 -14
  26. package/dist/js/modern/runtime-testing/base.js +7 -3
  27. package/dist/js/modern/runtime-testing/customRender.js +24 -10
  28. package/dist/js/modern/runtime-testing/index.js +1 -1
  29. package/dist/js/modern/runtime-testing/reduck.js +41 -19
  30. package/dist/js/modern/runtime-testing/request.js +4 -4
  31. package/dist/js/modern/runtime-testing/resolvePlugins.js +24 -8
  32. package/dist/js/node/base/config/index.js +62 -18
  33. package/dist/js/node/base/config/patches/assetsModule.js +34 -12
  34. package/dist/js/node/base/config/patches/filemock.js +24 -7
  35. package/dist/js/node/base/config/patches/index.js +54 -15
  36. package/dist/js/node/base/config/patches/transformer.js +42 -25
  37. package/dist/js/node/base/config/resolver.js +25 -10
  38. package/dist/js/node/base/config/testConfigOperator.js +51 -30
  39. package/dist/js/node/base/config/transformer/babelTransformer.js +42 -15
  40. package/dist/js/node/base/hook.js +34 -13
  41. package/dist/js/node/base/index.js +39 -62
  42. package/dist/js/node/base/runJest.js +104 -71
  43. package/dist/js/node/base/types/index.js +15 -0
  44. package/dist/js/node/base/utils.js +70 -34
  45. package/dist/js/node/cli/bff/app.js +64 -22
  46. package/dist/js/node/cli/bff/constant.js +26 -7
  47. package/dist/js/node/cli/bff/index.js +123 -65
  48. package/dist/js/node/cli/bff/mockAPI.js +103 -71
  49. package/dist/js/node/cli/bff/setup.js +71 -28
  50. package/dist/js/node/cli/bff/utils/index.js +57 -22
  51. package/dist/js/node/cli/index.js +92 -46
  52. package/dist/js/node/cli/test.js +81 -27
  53. package/dist/js/node/constant.js +26 -7
  54. package/dist/js/node/index.js +19 -18
  55. package/dist/js/node/modern-app.env.d.js +0 -0
  56. package/dist/js/node/runtime-testing/app.js +53 -25
  57. package/dist/js/node/runtime-testing/base.js +34 -32
  58. package/dist/js/node/runtime-testing/customRender.js +49 -18
  59. package/dist/js/node/runtime-testing/index.js +18 -27
  60. package/dist/js/node/runtime-testing/reduck.js +72 -31
  61. package/dist/js/node/runtime-testing/request.js +36 -13
  62. package/dist/js/node/runtime-testing/resolvePlugins.js +41 -12
  63. package/dist/js/treeshaking/base/config/index.js +150 -31
  64. package/dist/js/treeshaking/base/config/patches/assetsModule.js +9 -11
  65. package/dist/js/treeshaking/base/config/patches/filemock.js +2 -1
  66. package/dist/js/treeshaking/base/config/patches/index.js +221 -64
  67. package/dist/js/treeshaking/base/config/patches/transformer.js +34 -37
  68. package/dist/js/treeshaking/base/config/resolver.js +36 -13
  69. package/dist/js/treeshaking/base/config/testConfigOperator.js +120 -69
  70. package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +16 -10
  71. package/dist/js/treeshaking/base/hook.js +8 -7
  72. package/dist/js/treeshaking/base/index.js +7 -6
  73. package/dist/js/treeshaking/base/runJest.js +281 -164
  74. package/dist/js/treeshaking/base/types/index.js +1 -0
  75. package/dist/js/treeshaking/base/utils.js +72 -48
  76. package/dist/js/treeshaking/cli/bff/app.js +192 -68
  77. package/dist/js/treeshaking/cli/bff/constant.js +2 -1
  78. package/dist/js/treeshaking/cli/bff/index.js +291 -130
  79. package/dist/js/treeshaking/cli/bff/mockAPI.js +181 -91
  80. package/dist/js/treeshaking/cli/bff/setup.js +185 -59
  81. package/dist/js/treeshaking/cli/bff/utils/index.js +47 -21
  82. package/dist/js/treeshaking/cli/index.js +249 -108
  83. package/dist/js/treeshaking/cli/test.js +177 -44
  84. package/dist/js/treeshaking/constant.js +2 -1
  85. package/dist/js/treeshaking/index.js +3 -3
  86. package/dist/js/treeshaking/modern-app.env.d.js +1 -0
  87. package/dist/js/treeshaking/runtime-testing/app.js +85 -39
  88. package/dist/js/treeshaking/runtime-testing/base.js +4 -3
  89. package/dist/js/treeshaking/runtime-testing/customRender.js +38 -10
  90. package/dist/js/treeshaking/runtime-testing/index.js +1 -1
  91. package/dist/js/treeshaking/runtime-testing/reduck.js +85 -33
  92. package/dist/js/treeshaking/runtime-testing/request.js +49 -19
  93. package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +45 -14
  94. package/dist/types/base/config/index.d.ts +1 -0
  95. package/dist/types/base/config/patches/assetsModule.d.ts +1 -0
  96. package/dist/types/base/config/patches/filemock.d.ts +1 -0
  97. package/dist/types/base/config/patches/transformer.d.ts +1 -0
  98. package/dist/types/base/config/testConfigOperator.d.ts +2 -0
  99. package/dist/types/base/runJest.d.ts +2 -0
  100. package/dist/types/base/utils.d.ts +1 -0
  101. package/dist/types/cli/bff/index.d.ts +2 -0
  102. package/dist/types/cli/bff/mockAPI.d.ts +1 -0
  103. package/dist/types/cli/index.d.ts +2 -0
  104. package/dist/types/runtime-testing/app.d.ts +3 -0
  105. package/dist/types/runtime-testing/customRender.d.ts +2 -0
  106. package/package.json +21 -25
@@ -1,10 +1,21 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- import * as ptr from 'path-to-regexp';
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";
5
18
  import * as mockAppModule from "./app";
6
-
7
- // eslint-disable-next-line @typescript-eslint/naming-convention
8
19
  const mock_replaceUrlWithParams = (url, paramValues, payload) => {
9
20
  const keys = [];
10
21
  ptr.pathToRegexp(url, keys);
@@ -14,81 +25,85 @@ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
14
25
  }
15
26
  return cur;
16
27
  }, {});
17
- const getFinalPath = ptr.compile(url, {
18
- encode: encodeURIComponent
19
- });
20
- return getFinalPath(_objectSpread(_objectSpread({}, params), payload));
28
+ const getFinalPath = ptr.compile(url, { encode: encodeURIComponent });
29
+ return getFinalPath(__spreadValues(__spreadValues({}, params), payload));
21
30
  };
22
-
23
- // eslint-disable-next-line @typescript-eslint/naming-convention
24
- const mock_getParamsAndPayload = args => {
31
+ const mock_getParamsAndPayload = (args) => {
25
32
  if (args.length === 0) {
26
33
  return [[], {}];
27
34
  }
28
35
  const head = args[0];
29
- if (typeof head === 'object') {
36
+ if (typeof head === "object") {
30
37
  return [[], head];
31
38
  } else {
32
39
  const latest = args[args.length - 1];
33
- if (typeof latest === 'object') {
40
+ if (typeof latest === "object") {
34
41
  return [args.slice(0, args.length - 1), latest];
35
42
  } else {
36
43
  return [args, {}];
37
44
  }
38
45
  }
39
46
  };
40
- export default (mockApiInfosByFile => {
47
+ var mockAPI_default = (mockApiInfosByFile) => {
41
48
  const files = Object.keys(mockApiInfosByFile);
42
- files.forEach(mockedFile => {
49
+ files.forEach((mockedFile) => {
43
50
  jest.mock(mockedFile, () => {
44
- const supertest = require('supertest');
45
- return mockApiInfosByFile[mockedFile].reduce((res, info) => {
46
- const module = {
47
- [info.name]: (...args) => {
48
- if (mockAppModule.isInHandler()) {
49
- return info.handler(...args);
50
- }
51
- const [params, payload] = mock_getParamsAndPayload(args);
52
- const {
53
- returnHttp
54
- } = module[info.name];
55
- const url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
56
- const app = mockAppModule.getApp();
57
- let test = supertest(app)[info.httpMethod.toLowerCase()](url);
58
- if (payload.query) {
59
- test = test.query(payload.query);
60
- }
61
- if (payload.body) {
62
- test = test.send(payload.body);
63
- }
64
- if (payload.data) {
65
- test = test.send(payload.data);
66
- }
67
- if (payload.headers) {
68
- for (const name in payload.headers) {
69
- test = test.set(name, payload.headers[name]);
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);
70
58
  }
71
- }
72
- if (payload.cookies) {
73
- test = test.set('Cookie', [payload.cookies]);
74
- }
75
- if (returnHttp) {
76
- return test;
77
- }
78
- return test.then(value => {
79
- try {
80
- return JSON.parse(value.text);
81
- } catch (_unused) {
82
- return value.text;
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]);
83
84
  }
84
- });
85
- }
86
- };
87
- res[info.name] = module[info.name];
88
- Object.assign(res[info.name], info.handler);
89
- res.__esModule = true;
90
- return res;
91
- }, {});
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
+ );
92
104
  });
93
105
  });
94
- });
106
+ };
107
+ export {
108
+ mockAPI_default as default
109
+ };
@@ -1,38 +1,75 @@
1
- import path from 'path';
2
- import { ApiRouter } from '@modern-js/bff-core';
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";
3
27
  import { bff_info_key } from "./constant";
4
28
  import mockAPI from "./mockAPI";
5
29
  import { createApp, closeServer } from "./app";
6
- let uped = false;
7
- const setup = () => {
8
- var _bff_info$modernUserC, _bff_info$modernUserC2;
9
- if (uped) {
10
- return;
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();
11
73
  }
12
- uped = true;
13
- const bff_info = global[bff_info_key];
14
- const prefix = bff_info === null || bff_info === void 0 ? void 0 : (_bff_info$modernUserC = bff_info.modernUserConfig) === null || _bff_info$modernUserC === void 0 ? void 0 : (_bff_info$modernUserC2 = _bff_info$modernUserC.bff) === null || _bff_info$modernUserC2 === void 0 ? void 0 : _bff_info$modernUserC2.prefix;
15
- const apiRouter = new ApiRouter({
16
- apiDir: path.join(bff_info.appDir, './api'),
17
- prefix
18
- });
19
- const apiInfos = apiRouter.getApiHandlers();
20
- const apiInfosByFile = apiInfos.reduce((res, apiInfo) => {
21
- if (!res[apiInfo.filename]) {
22
- res[apiInfo.filename] = [];
23
- }
24
- res[apiInfo.filename].push(apiInfo);
25
- return res;
26
- }, {});
27
- let app = null;
28
- beforeAll(async () => {
29
- if (!app) {
30
- app = await createApp(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
31
- }
32
- });
33
- afterAll(async () => {
34
- await closeServer();
35
- });
36
- mockAPI(apiInfosByFile);
37
- };
38
- setup();
74
+ });
75
+ export default require_setup();
@@ -1,21 +1,37 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- import path from 'path';
5
- import { chalk } from '@modern-js/utils';
6
- export const isBFFProject = pwd => {
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) => {
7
20
  try {
8
- const packageJson = require(path.join(pwd, './package.json'));
9
- const {
10
- dependencies,
11
- devDependencies
12
- } = packageJson;
13
- const isBFF = Object.keys(_objectSpread(_objectSpread({}, dependencies), devDependencies)).some(dependency => dependency.includes('plugin-bff'));
14
- const isMWA = Object.keys(devDependencies).some(devDependency => devDependency.includes('app-tools'));
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
+ );
15
29
  return isMWA && isBFF;
16
30
  } catch (error) {
17
- // eslint-disable-next-line no-console
18
31
  console.log(chalk.red(error));
19
32
  return false;
20
33
  }
21
- };
34
+ };
35
+ export {
36
+ isBFFProject
37
+ };
@@ -1,80 +1,115 @@
1
- import path from 'path';
2
- import { isApiOnly, mergeAlias, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from '@modern-js/utils';
3
- import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../base";
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";
4
33
  import { MODERNJS_CONFIG_KEY } from "../constant";
5
34
  import TestingBffPlugin from "./bff";
6
35
  import test from "./test";
7
- export const mergeUserJestConfig = testUtils => {
36
+ const mergeUserJestConfig = (testUtils) => {
8
37
  const resolveJestConfig = testUtils.testConfig.jest;
9
-
10
- // resolveJestConfig 如果是函数类型,在所有测试插件 jestConfig 都执行后,再执行生成最终配置
11
- if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
38
+ if (resolveJestConfig && typeof resolveJestConfig !== "function") {
12
39
  testUtils.mergeJestConfig(resolveJestConfig);
13
40
  }
14
41
  };
15
- export default (() => {
42
+ var cli_default = () => {
16
43
  const BffPlugin = TestingBffPlugin();
17
44
  return {
18
- name: '@modern-js/plugin-testing',
45
+ name: "@modern-js/plugin-testing",
19
46
  usePlugins: [BffPlugin],
20
47
  post: [BffPlugin.name],
21
48
  registerHook: testingHooks,
22
- setup: api => {
49
+ setup: (api) => {
23
50
  let testingExportsUtils;
24
51
  return {
25
- commands: ({
26
- program
27
- }) => {
28
- program.command('test').allowUnknownOption().usage('<regexForTestFiles> --[options]').action(async () => {
29
- await test(api);
30
- });
52
+ commands: ({ program }) => {
53
+ program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(() => __async(void 0, null, function* () {
54
+ yield test(api);
55
+ }));
31
56
  },
32
57
  validateSchema() {
33
- return PLUGIN_SCHEMAS['@modern-js/plugin-testing'];
58
+ return PLUGIN_SCHEMAS["@modern-js/plugin-testing"];
34
59
  },
35
60
  config() {
36
61
  const appContext = api.useAppContext();
37
- testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, 'testing');
62
+ testingExportsUtils = createRuntimeExportsUtils(
63
+ appContext.internalDirectory,
64
+ "testing"
65
+ );
38
66
  return {
39
67
  source: {
40
68
  alias: {
41
- '@modern-js/runtime/testing': testingExportsUtils.getPath()
69
+ "@": path.join(appContext.appDirectory, "src"),
70
+ "@modern-js/runtime/testing": testingExportsUtils.getPath()
42
71
  }
43
72
  }
44
73
  };
45
74
  },
46
75
  addRuntimeExports() {
47
- const testingPath = path.resolve(__dirname, '../');
76
+ const testingPath = path.resolve(__dirname, "../");
48
77
  testingExportsUtils.addExport(`export * from '${testingPath}'`);
49
78
  },
50
- jestConfig: async (utils, next) => {
79
+ jestConfig: (utils, next) => __async(void 0, null, function* () {
51
80
  const appContext = api.useAppContext();
52
81
  const userConfig = api.useResolvedConfigContext();
53
- const apiOnly = await isApiOnly(appContext.appDirectory);
82
+ const apiOnly = yield isApiOnly(appContext.appDirectory);
54
83
  if (apiOnly) {
55
84
  return next(utils);
56
85
  }
57
86
  const alias = mergeAlias(userConfig.source.alias);
58
87
  if (testingExportsUtils) {
59
- alias['@modern-js/runtime/testing'] = [testingExportsUtils.getPath()];
88
+ alias["@modern-js/runtime/testing"] = [
89
+ testingExportsUtils.getPath()
90
+ ];
60
91
  }
61
92
  utils.mergeJestConfig({
62
93
  globals: {
63
94
  [MODERNJS_CONFIG_KEY]: userConfig
64
95
  },
65
96
  moduleNameMapper: getModuleNameMapper(alias),
66
- testEnvironment: 'jsdom',
97
+ testEnvironment: "jsdom",
67
98
  resolver: DEFAULT_RESOLVER_PATH,
68
99
  rootDir: appContext.appDirectory || process.cwd(),
69
- // todo: diffrernt test root for diffrent solutions
70
- // testMatch: [`<rootDir>/(src|tests|electron)/**/*.test.[jt]s?(x)`],
71
- // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
72
- testMatch: [`<rootDir>/src/**/*.test.[jt]s?(x)`, `<rootDir>/tests/**/*.test.[jt]s?(x)`, `<rootDir>/electron/**/*.test.[jt]s?(x)`]
100
+ testMatch: [
101
+ `<rootDir>/src/**/*.test.[jt]s?(x)`,
102
+ `<rootDir>/tests/**/*.test.[jt]s?(x)`
103
+ ]
73
104
  });
74
105
  mergeUserJestConfig(utils);
75
106
  return next(utils);
76
- }
107
+ })
77
108
  };
78
109
  }
79
110
  };
80
- });
111
+ };
112
+ export {
113
+ cli_default as default,
114
+ mergeUserJestConfig
115
+ };
@@ -1,26 +1,61 @@
1
- import path from 'path';
2
- import { compiler } from '@modern-js/babel-compiler';
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";
3
23
  import { runTest } from "../base";
4
- const test = async api => {
24
+ const test = (api) => __async(void 0, null, function* () {
25
+ var _a, _b;
5
26
  const userConfig = api.useResolvedConfigContext();
6
27
  const appContext = api.useAppContext();
7
28
  userConfig.testing = userConfig.testing || {};
8
- const jest = userConfig.testing.jest || userConfig.tools.jest;
29
+ const jest = userConfig.testing.jest || ((_a = userConfig == null ? void 0 : userConfig.tools) == null ? void 0 : _a.jest);
9
30
  if (Array.isArray(jest)) {
10
31
  userConfig.testing.jest = jest[0];
11
32
  }
12
- userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
13
- const runtimeExportsPath = path.join(appContext.internalDirectory, '.runtime-exports');
14
- await compiler({
15
- sourceDir: runtimeExportsPath,
16
- rootDir: runtimeExportsPath,
17
- distDir: runtimeExportsPath,
18
- quiet: true
19
- }, {
20
- presets: [[require.resolve('@babel/preset-env'), {
21
- modules: 'cjs'
22
- }]]
23
- });
24
- await runTest(api, userConfig.testing);
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
25
61
  };
26
- export default test;
@@ -1 +1,4 @@
1
- export const MODERNJS_CONFIG_KEY = '__modernjs_config__';
1
+ const MODERNJS_CONFIG_KEY = "__modernjs_config__";
2
+ export {
3
+ MODERNJS_CONFIG_KEY
4
+ };
@@ -1,3 +1,3 @@
1
- import '@testing-library/jest-dom/extend-expect';
2
- import '@testing-library/jest-dom';
3
- export * from "./runtime-testing";
1
+ import "@testing-library/jest-dom/extend-expect";
2
+ import "@testing-library/jest-dom";
3
+ export * from "./runtime-testing";
File without changes
@@ -1,27 +1,35 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
- import { createApp } from '@modern-js/runtime';
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";
5
18
  import { MODERNJS_CONFIG_KEY } from "../constant";
6
19
  import resolvePlugins from "./resolvePlugins";
7
20
  class ModernRuntime {
8
21
  constructor(options) {
9
- _defineProperty(this, "options", void 0);
10
22
  this.options = options;
11
23
  }
12
24
  init(options) {
13
25
  this.options = options;
14
26
  }
15
27
  createApp(props) {
16
- var _this$options;
17
- const {
18
- entry,
19
- children
20
- } = props || {};
21
- let runtimeFeatures = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.runtime;
28
+ var _a, _b;
29
+ const { entry, children } = props || {};
30
+ let runtimeFeatures = (_a = this.options) == null ? void 0 : _a.runtime;
22
31
  if (entry) {
23
- var _this$options$runtime;
24
- runtimeFeatures = _objectSpread(_objectSpread({}, runtimeFeatures || {}), (_this$options$runtime = this.options.runtimeByEntries) === null || _this$options$runtime === void 0 ? void 0 : _this$options$runtime[entry]);
32
+ runtimeFeatures = __spreadValues(__spreadValues({}, runtimeFeatures || {}), (_b = this.options.runtimeByEntries) == null ? void 0 : _b[entry]);
25
33
  }
26
34
  const Component = () => {
27
35
  if (!children) {
@@ -34,4 +42,7 @@ class ModernRuntime {
34
42
  })(Component);
35
43
  }
36
44
  }
37
- export default new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
45
+ var app_default = new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
46
+ export {
47
+ app_default as default
48
+ };
@@ -1,3 +1,7 @@
1
- export { default as renderApp } from "./customRender";
2
- export * from '@testing-library/react';
3
- export { request as testBff } from "./request";
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
+ };