@modern-js/plugin-testing 2.14.0 → 2.16.0

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 (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,47 +1,65 @@
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
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var mockAPI_exports = {};
29
- __export(mockAPI_exports, {
30
- default: () => mockAPI_default
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: () => _default
31
8
  });
32
- module.exports = __toCommonJS(mockAPI_exports);
33
- var ptr = __toESM(require("path-to-regexp"));
34
- var mockAppModule = __toESM(require("./app"));
9
+ const _pathtoregexp = /* @__PURE__ */ _interop_require_wildcard(require("path-to-regexp"));
10
+ const _app = /* @__PURE__ */ _interop_require_wildcard(require("./app"));
11
+ function _getRequireWildcardCache(nodeInterop) {
12
+ if (typeof WeakMap !== "function")
13
+ return null;
14
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
15
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
16
+ return (_getRequireWildcardCache = function(nodeInterop2) {
17
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
18
+ })(nodeInterop);
19
+ }
20
+ function _interop_require_wildcard(obj, nodeInterop) {
21
+ if (!nodeInterop && obj && obj.__esModule) {
22
+ return obj;
23
+ }
24
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
25
+ return {
26
+ default: obj
27
+ };
28
+ }
29
+ var cache = _getRequireWildcardCache(nodeInterop);
30
+ if (cache && cache.has(obj)) {
31
+ return cache.get(obj);
32
+ }
33
+ var newObj = {};
34
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
35
+ for (var key in obj) {
36
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
37
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
38
+ if (desc && (desc.get || desc.set)) {
39
+ Object.defineProperty(newObj, key, desc);
40
+ } else {
41
+ newObj[key] = obj[key];
42
+ }
43
+ }
44
+ }
45
+ newObj.default = obj;
46
+ if (cache) {
47
+ cache.set(obj, newObj);
48
+ }
49
+ return newObj;
50
+ }
35
51
  const mock_replaceUrlWithParams = (url, paramValues, payload) => {
36
52
  const keys = [];
37
- ptr.pathToRegexp(url, keys);
53
+ _pathtoregexp.pathToRegexp(url, keys);
38
54
  const params = keys.reduce((cur, key, index) => {
39
55
  if (paramValues[index]) {
40
56
  cur[key.name] = paramValues[index];
41
57
  }
42
58
  return cur;
43
59
  }, {});
44
- const getFinalPath = ptr.compile(url, { encode: encodeURIComponent });
60
+ const getFinalPath = _pathtoregexp.compile(url, {
61
+ encode: encodeURIComponent
62
+ });
45
63
  return getFinalPath({
46
64
  ...params,
47
65
  ...payload
@@ -49,79 +67,84 @@ const mock_replaceUrlWithParams = (url, paramValues, payload) => {
49
67
  };
50
68
  const mock_getParamsAndPayload = (args) => {
51
69
  if (args.length === 0) {
52
- return [[], {}];
70
+ return [
71
+ [],
72
+ {}
73
+ ];
53
74
  }
54
75
  const head = args[0];
55
76
  if (typeof head === "object") {
56
- return [[], head];
77
+ return [
78
+ [],
79
+ head
80
+ ];
57
81
  } else {
58
82
  const latest = args[args.length - 1];
59
83
  if (typeof latest === "object") {
60
- return [args.slice(0, args.length - 1), latest];
84
+ return [
85
+ args.slice(0, args.length - 1),
86
+ latest
87
+ ];
61
88
  } else {
62
- return [args, {}];
89
+ return [
90
+ args,
91
+ {}
92
+ ];
63
93
  }
64
94
  }
65
95
  };
66
- var mockAPI_default = (mockApiInfosByFile) => {
96
+ const _default = (mockApiInfosByFile) => {
67
97
  const files = Object.keys(mockApiInfosByFile);
68
98
  files.forEach((mockedFile) => {
69
99
  jest.mock(mockedFile, () => {
70
100
  const supertest = require("supertest");
71
- return mockApiInfosByFile[mockedFile].reduce(
72
- (res, info) => {
73
- const module2 = {
74
- [info.name]: (...args) => {
75
- if (mockAppModule.isInHandler()) {
76
- return info.handler(...args);
77
- }
78
- const [params, payload] = mock_getParamsAndPayload(args);
79
- const { returnHttp } = module2[info.name];
80
- const url = mock_replaceUrlWithParams(
81
- info.routePath,
82
- params,
83
- payload.params
84
- );
85
- const app = mockAppModule.getApp();
86
- let test = supertest(app)[info.httpMethod.toLowerCase()](url);
87
- if (payload.query) {
88
- test = test.query(payload.query);
89
- }
90
- if (payload.body) {
91
- test = test.send(payload.body);
92
- }
93
- if (payload.data) {
94
- test = test.send(payload.data);
95
- }
96
- if (payload.headers) {
97
- for (const name in payload.headers) {
98
- test = test.set(name, payload.headers[name]);
99
- }
100
- }
101
- if (payload.cookies) {
102
- test = test.set("Cookie", [payload.cookies]);
103
- }
104
- if (returnHttp) {
105
- return test;
101
+ return mockApiInfosByFile[mockedFile].reduce((res, info) => {
102
+ const module = {
103
+ [info.name]: (...args) => {
104
+ if (_app.isInHandler()) {
105
+ return info.handler(...args);
106
+ }
107
+ const [params, payload] = mock_getParamsAndPayload(args);
108
+ const { returnHttp } = module[info.name];
109
+ const url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
110
+ const app = _app.getApp();
111
+ let test = supertest(app)[info.httpMethod.toLowerCase()](url);
112
+ if (payload.query) {
113
+ test = test.query(payload.query);
114
+ }
115
+ if (payload.body) {
116
+ test = test.send(payload.body);
117
+ }
118
+ if (payload.data) {
119
+ test = test.send(payload.data);
120
+ }
121
+ if (payload.headers) {
122
+ for (const name in payload.headers) {
123
+ test = test.set(name, payload.headers[name]);
106
124
  }
107
- return test.then((value) => {
108
- try {
109
- return JSON.parse(value.text);
110
- } catch {
111
- return value.text;
112
- }
113
- });
114
125
  }
115
- };
116
- res[info.name] = module2[info.name];
117
- Object.assign(res[info.name], info.handler);
118
- res.__esModule = true;
119
- return res;
120
- },
121
- {}
122
- );
126
+ if (payload.cookies) {
127
+ test = test.set("Cookie", [
128
+ payload.cookies
129
+ ]);
130
+ }
131
+ if (returnHttp) {
132
+ return test;
133
+ }
134
+ return test.then((value) => {
135
+ try {
136
+ return JSON.parse(value.text);
137
+ } catch {
138
+ return value.text;
139
+ }
140
+ });
141
+ }
142
+ };
143
+ res[info.name] = module[info.name];
144
+ Object.assign(res[info.name], info.handler);
145
+ res.__esModule = true;
146
+ return res;
147
+ }, {});
123
148
  });
124
149
  });
125
150
  };
126
- // Annotate the CommonJS export names for ESM import in node:
127
- 0 && (module.exports = {});
@@ -1,70 +1,49 @@
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 __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from === "object" || typeof from === "function") {
9
- for (let key of __getOwnPropNames(from))
10
- if (!__hasOwnProp.call(to, key) && key !== except)
11
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- }
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
23
- var import_path = __toESM(require("path"));
24
- var import_bff_core = require("@modern-js/bff-core");
25
- var import_constant = require("./constant");
26
- var import_mockAPI = __toESM(require("./mockAPI"));
27
- var import_app = require("./app");
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
6
+ const _bffcore = require("@modern-js/bff-core");
7
+ const _constant = require("./constant");
8
+ const _mockAPI = /* @__PURE__ */ _interop_require_default(require("./mockAPI"));
9
+ const _app = require("./app");
10
+ function _interop_require_default(obj) {
11
+ return obj && obj.__esModule ? obj : {
12
+ default: obj
13
+ };
14
+ }
28
15
  let uped = false;
29
16
  const setup = () => {
30
- var _a, _b, _c, _d;
17
+ var _bff_info_modernUserConfig, _bff_info_modernUserConfig_bff, _bff_info_modernUserConfig1, _bff_info_modernUserConfig_bff1;
31
18
  if (uped) {
32
19
  return;
33
20
  }
34
21
  uped = true;
35
- const bff_info = global[import_constant.bff_info_key];
36
- const prefix = (_b = (_a = bff_info == null ? void 0 : bff_info.modernUserConfig) == null ? void 0 : _a.bff) == null ? void 0 : _b.prefix;
37
- const httpMethodDecider = (_d = (_c = bff_info == null ? void 0 : bff_info.modernUserConfig) == null ? void 0 : _c.bff) == null ? void 0 : _d.httpMethodDecider;
38
- const apiRouter = new import_bff_core.ApiRouter({
39
- apiDir: import_path.default.join(bff_info.appDir, "./api"),
22
+ const bff_info = global[_constant.bff_info_key];
23
+ 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;
24
+ 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;
25
+ const apiRouter = new _bffcore.ApiRouter({
26
+ apiDir: _path.default.join(bff_info.appDir, "./api"),
40
27
  prefix,
41
28
  httpMethodDecider
42
29
  });
43
30
  const apiInfos = apiRouter.getApiHandlers();
44
- const apiInfosByFile = apiInfos.reduce(
45
- (res, apiInfo) => {
46
- if (!res[apiInfo.filename]) {
47
- res[apiInfo.filename] = [];
48
- }
49
- res[apiInfo.filename].push(apiInfo);
50
- return res;
51
- },
52
- {}
53
- );
31
+ const apiInfosByFile = apiInfos.reduce((res, apiInfo) => {
32
+ if (!res[apiInfo.filename]) {
33
+ res[apiInfo.filename] = [];
34
+ }
35
+ res[apiInfo.filename].push(apiInfo);
36
+ return res;
37
+ }, {});
54
38
  let app = null;
55
39
  beforeAll(async () => {
56
40
  if (!app) {
57
- app = await (0, import_app.createApp)(
58
- bff_info.appDir,
59
- bff_info.modernUserConfig,
60
- bff_info.plugins,
61
- bff_info.routes
62
- );
41
+ app = await (0, _app.createApp)(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
63
42
  }
64
43
  });
65
44
  afterAll(async () => {
66
- await (0, import_app.closeServer)();
45
+ await (0, _app.closeServer)();
67
46
  });
68
- (0, import_mockAPI.default)(apiInfosByFile);
47
+ (0, _mockAPI.default)(apiInfosByFile);
69
48
  };
70
49
  setup();
@@ -1,54 +1,30 @@
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
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var utils_exports = {};
29
- __export(utils_exports, {
30
- isBFFProject: () => isBFFProject
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
31
4
  });
32
- module.exports = __toCommonJS(utils_exports);
33
- var import_path = __toESM(require("path"));
34
- var import_utils = require("@modern-js/utils");
5
+ Object.defineProperty(exports, "isBFFProject", {
6
+ enumerable: true,
7
+ get: () => isBFFProject
8
+ });
9
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
10
+ const _utils = require("@modern-js/utils");
11
+ function _interop_require_default(obj) {
12
+ return obj && obj.__esModule ? obj : {
13
+ default: obj
14
+ };
15
+ }
35
16
  const isBFFProject = (pwd) => {
36
17
  try {
37
- const packageJson = require(import_path.default.join(pwd, "./package.json"));
18
+ const packageJson = require(_path.default.join(pwd, "./package.json"));
38
19
  const { dependencies, devDependencies } = packageJson;
39
- const isBFF = Object.keys({ ...dependencies, ...devDependencies }).some(
40
- (dependency) => dependency.includes("plugin-bff")
41
- );
42
- const isMWA = Object.keys(devDependencies).some(
43
- (devDependency) => devDependency.includes("app-tools")
44
- );
20
+ const isBFF = Object.keys({
21
+ ...dependencies,
22
+ ...devDependencies
23
+ }).some((dependency) => dependency.includes("plugin-bff"));
24
+ const isMWA = Object.keys(devDependencies).some((devDependency) => devDependency.includes("app-tools"));
45
25
  return isMWA && isBFF;
46
26
  } catch (error) {
47
- console.log(import_utils.chalk.red(error));
27
+ console.log(_utils.chalk.red(error));
48
28
  return false;
49
29
  }
50
30
  };
51
- // Annotate the CommonJS export names for ESM import in node:
52
- 0 && (module.exports = {
53
- isBFFProject
54
- });
@@ -1,95 +1,83 @@
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) => {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
8
6
  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
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
- var cli_exports = {};
29
- __export(cli_exports, {
30
- default: () => cli_default,
31
- mergeUserJestConfig: () => mergeUserJestConfig
7
+ Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ mergeUserJestConfig: () => mergeUserJestConfig,
14
+ default: () => _default
32
15
  });
33
- module.exports = __toCommonJS(cli_exports);
34
- var import_path = __toESM(require("path"));
35
- var import_utils = require("@modern-js/utils");
36
- var import_base = require("../base");
37
- var import_constant = require("../constant");
38
- var import_bff = __toESM(require("./bff"));
39
- var import_test = __toESM(require("./test"));
16
+ const _path = /* @__PURE__ */ _interop_require_default(require("path"));
17
+ const _utils = require("@modern-js/utils");
18
+ const _base = require("../base");
19
+ const _constant = require("../constant");
20
+ const _bff = /* @__PURE__ */ _interop_require_default(require("./bff"));
21
+ const _test = /* @__PURE__ */ _interop_require_default(require("./test"));
22
+ function _interop_require_default(obj) {
23
+ return obj && obj.__esModule ? obj : {
24
+ default: obj
25
+ };
26
+ }
40
27
  const mergeUserJestConfig = (testUtils) => {
41
28
  const resolveJestConfig = testUtils.testConfig.jest;
42
29
  if (resolveJestConfig && typeof resolveJestConfig !== "function") {
43
30
  testUtils.mergeJestConfig(resolveJestConfig);
44
31
  }
45
32
  };
46
- var cli_default = () => {
47
- const bffPlugin = (0, import_bff.default)();
33
+ const _default = () => {
34
+ const bffPlugin = (0, _bff.default)();
48
35
  return {
49
36
  name: "@modern-js/plugin-testing",
50
- usePlugins: [bffPlugin],
51
- post: [bffPlugin.name],
52
- registerHook: import_base.testingHooks,
37
+ usePlugins: [
38
+ bffPlugin
39
+ ],
40
+ post: [
41
+ bffPlugin.name
42
+ ],
43
+ registerHook: _base.testingHooks,
53
44
  setup: (api) => {
54
45
  let testingExportsUtils;
55
46
  return {
56
47
  commands: ({ program }) => {
57
48
  program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(async () => {
58
- await (0, import_test.default)(api);
49
+ await (0, _test.default)(api);
59
50
  });
60
51
  },
61
52
  validateSchema() {
62
- return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-testing"];
53
+ return _utils.PLUGIN_SCHEMAS["@modern-js/plugin-testing"];
63
54
  },
64
55
  config() {
65
56
  const appContext = api.useAppContext();
66
- testingExportsUtils = (0, import_utils.createRuntimeExportsUtils)(
67
- appContext.internalDirectory,
68
- "testing"
69
- );
57
+ testingExportsUtils = (0, _utils.createRuntimeExportsUtils)(appContext.internalDirectory, "testing");
70
58
  return {
71
59
  source: {
72
60
  alias: {
73
61
  // The module-tools alias configuration is different and more specific than app-tools.
74
62
  // So for the time being, the @ alias is configured here.
75
- "@": import_path.default.join(appContext.appDirectory, "src"),
63
+ "@": _path.default.join(appContext.appDirectory, "src"),
76
64
  "@modern-js/runtime/testing": testingExportsUtils.getPath()
77
65
  }
78
66
  }
79
67
  };
80
68
  },
81
69
  addRuntimeExports() {
82
- const testingPath = import_path.default.resolve(__dirname, "../");
70
+ const testingPath = _path.default.resolve(__dirname, "../");
83
71
  testingExportsUtils.addExport(`export * from '${testingPath}'`);
84
72
  },
85
73
  jestConfig: async (utils, next) => {
86
74
  const appContext = api.useAppContext();
87
75
  const userConfig = api.useResolvedConfigContext();
88
- const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory);
76
+ const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory);
89
77
  if (apiOnly) {
90
78
  return next(utils);
91
79
  }
92
- const alias = (0, import_utils.mergeAlias)(userConfig.source.alias);
80
+ const alias = (0, _utils.mergeAlias)(userConfig.source.alias);
93
81
  if (testingExportsUtils) {
94
82
  alias["@modern-js/runtime/testing"] = [
95
83
  testingExportsUtils.getPath()
@@ -97,11 +85,11 @@ var cli_default = () => {
97
85
  }
98
86
  utils.mergeJestConfig({
99
87
  globals: {
100
- [import_constant.MODERNJS_CONFIG_KEY]: userConfig
88
+ [_constant.MODERNJS_CONFIG_KEY]: userConfig
101
89
  },
102
- moduleNameMapper: (0, import_base.getModuleNameMapper)(alias),
90
+ moduleNameMapper: (0, _base.getModuleNameMapper)(alias),
103
91
  testEnvironment: "jsdom",
104
- resolver: import_base.DEFAULT_RESOLVER_PATH,
92
+ resolver: _base.DEFAULT_RESOLVER_PATH,
105
93
  rootDir: appContext.appDirectory || process.cwd(),
106
94
  // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
107
95
  testMatch: [
@@ -116,7 +104,3 @@ var cli_default = () => {
116
104
  }
117
105
  };
118
106
  };
119
- // Annotate the CommonJS export names for ESM import in node:
120
- 0 && (module.exports = {
121
- mergeUserJestConfig
122
- });