@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,139 +1,146 @@
1
1
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
2
- try {
3
- var info = gen[key](arg);
4
- var value = info.value;
5
- } catch (error) {
6
- reject(error);
7
- return;
8
- }
9
- if (info.done) {
10
- resolve(value);
11
- } else {
12
- Promise.resolve(value).then(_next, _throw);
13
- }
2
+ try {
3
+ var info = gen[key](arg);
4
+ var value = info.value;
5
+ } catch (error) {
6
+ reject(error);
7
+ return;
8
+ }
9
+ if (info.done) {
10
+ resolve(value);
11
+ } else {
12
+ Promise.resolve(value).then(_next, _throw);
13
+ }
14
14
  }
15
- function _asyncToGenerator(fn) {
16
- return function() {
17
- var self = this, args = arguments;
18
- return new Promise(function(resolve, reject) {
19
- var gen = fn.apply(self, args);
20
- function _next(value) {
21
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
- }
23
- function _throw(err) {
24
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
- }
26
- _next(undefined);
27
- });
28
- };
15
+ function _async_to_generator(fn) {
16
+ return function() {
17
+ var self = this, args = arguments;
18
+ return new Promise(function(resolve, reject) {
19
+ var gen = fn.apply(self, args);
20
+ function _next(value) {
21
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
22
+ }
23
+ function _throw(err) {
24
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
25
+ }
26
+ _next(void 0);
27
+ });
28
+ };
29
29
  }
30
- function _defineProperty(obj, key, value) {
31
- if (key in obj) {
32
- Object.defineProperty(obj, key, {
33
- value: value,
34
- enumerable: true,
35
- configurable: true,
36
- writable: true
37
- });
38
- } else {
39
- obj[key] = value;
40
- }
41
- return obj;
30
+ function _define_property(obj, key, value) {
31
+ if (key in obj) {
32
+ Object.defineProperty(obj, key, {
33
+ value,
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true
37
+ });
38
+ } else {
39
+ obj[key] = value;
40
+ }
41
+ return obj;
42
42
  }
43
- var __generator = this && this.__generator || function(thisArg, body) {
44
- var f, y, t, g, _ = {
45
- label: 0,
46
- sent: function() {
47
- if (t[0] & 1) throw t[1];
48
- return t[1];
49
- },
50
- trys: [],
51
- ops: []
43
+ var __generator = function(thisArg, body) {
44
+ var f, y, t, g, _ = {
45
+ label: 0,
46
+ sent: function() {
47
+ if (t[0] & 1)
48
+ throw t[1];
49
+ return t[1];
50
+ },
51
+ trys: [],
52
+ ops: []
53
+ };
54
+ return g = {
55
+ next: verb(0),
56
+ "throw": verb(1),
57
+ "return": verb(2)
58
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
59
+ return this;
60
+ }), g;
61
+ function verb(n) {
62
+ return function(v) {
63
+ return step([
64
+ n,
65
+ v
66
+ ]);
52
67
  };
53
- return(g = {
54
- next: verb(0),
55
- "throw": verb(1),
56
- "return": verb(2)
57
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
58
- return this;
59
- }), g);
60
- function verb(n) {
61
- return function(v) {
62
- return step([
63
- n,
64
- v
65
- ]);
66
- };
67
- }
68
- function step(op) {
69
- if (f) throw new TypeError("Generator is already executing.");
70
- while(_)try {
71
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
72
- if (y = 0, t) op = [
73
- op[0] & 2,
74
- t.value
75
- ];
76
- switch(op[0]){
77
- case 0:
78
- case 1:
79
- t = op;
80
- break;
81
- case 4:
82
- _.label++;
83
- return {
84
- value: op[1],
85
- done: false
86
- };
87
- case 5:
88
- _.label++;
89
- y = op[1];
90
- op = [
91
- 0
92
- ];
93
- continue;
94
- case 7:
95
- op = _.ops.pop();
96
- _.trys.pop();
97
- continue;
98
- default:
99
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
100
- _ = 0;
101
- continue;
102
- }
103
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
104
- _.label = op[1];
105
- break;
106
- }
107
- if (op[0] === 6 && _.label < t[1]) {
108
- _.label = t[1];
109
- t = op;
110
- break;
111
- }
112
- if (t && _.label < t[2]) {
113
- _.label = t[2];
114
- _.ops.push(op);
115
- break;
116
- }
117
- if (t[2]) _.ops.pop();
118
- _.trys.pop();
119
- continue;
120
- }
121
- op = body.call(thisArg, _);
122
- } catch (e) {
68
+ }
69
+ function step(op) {
70
+ if (f)
71
+ throw new TypeError("Generator is already executing.");
72
+ while (_)
73
+ try {
74
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done)
75
+ return t;
76
+ if (y = 0, t)
77
+ op = [
78
+ op[0] & 2,
79
+ t.value
80
+ ];
81
+ switch (op[0]) {
82
+ case 0:
83
+ case 1:
84
+ t = op;
85
+ break;
86
+ case 4:
87
+ _.label++;
88
+ return {
89
+ value: op[1],
90
+ done: false
91
+ };
92
+ case 5:
93
+ _.label++;
94
+ y = op[1];
123
95
  op = [
124
- 6,
125
- e
96
+ 0
126
97
  ];
127
- y = 0;
128
- } finally{
129
- f = t = 0;
98
+ continue;
99
+ case 7:
100
+ op = _.ops.pop();
101
+ _.trys.pop();
102
+ continue;
103
+ default:
104
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
105
+ _ = 0;
106
+ continue;
107
+ }
108
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
109
+ _.label = op[1];
110
+ break;
111
+ }
112
+ if (op[0] === 6 && _.label < t[1]) {
113
+ _.label = t[1];
114
+ t = op;
115
+ break;
116
+ }
117
+ if (t && _.label < t[2]) {
118
+ _.label = t[2];
119
+ _.ops.push(op);
120
+ break;
121
+ }
122
+ if (t[2])
123
+ _.ops.pop();
124
+ _.trys.pop();
125
+ continue;
130
126
  }
131
- if (op[0] & 5) throw op[1];
132
- return {
133
- value: op[0] ? op[1] : void 0,
134
- done: true
135
- };
136
- }
127
+ op = body.call(thisArg, _);
128
+ } catch (e) {
129
+ op = [
130
+ 6,
131
+ e
132
+ ];
133
+ y = 0;
134
+ } finally {
135
+ f = t = 0;
136
+ }
137
+ if (op[0] & 5)
138
+ throw op[1];
139
+ return {
140
+ value: op[0] ? op[1] : void 0,
141
+ done: true
142
+ };
143
+ }
137
144
  };
138
145
  import path from "path";
139
146
  import { isApiOnly, mergeAlias, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from "@modern-js/utils";
@@ -141,118 +148,118 @@ import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../bas
141
148
  import { MODERNJS_CONFIG_KEY } from "../constant";
142
149
  import testingBffPlugin from "./bff";
143
150
  import test from "./test";
144
- var mergeUserJestConfig = function(testUtils) {
145
- var resolveJestConfig = testUtils.testConfig.jest;
146
- if (resolveJestConfig && typeof resolveJestConfig !== "function") {
147
- testUtils.mergeJestConfig(resolveJestConfig);
148
- }
151
+ export var mergeUserJestConfig = function(testUtils) {
152
+ var resolveJestConfig = testUtils.testConfig.jest;
153
+ if (resolveJestConfig && typeof resolveJestConfig !== "function") {
154
+ testUtils.mergeJestConfig(resolveJestConfig);
155
+ }
149
156
  };
150
- var cli_default = function() {
151
- var bffPlugin = testingBffPlugin();
152
- return {
153
- name: "@modern-js/plugin-testing",
154
- usePlugins: [
155
- bffPlugin
156
- ],
157
- post: [
158
- bffPlugin.name
159
- ],
160
- registerHook: testingHooks,
161
- setup: function(api) {
162
- var testingExportsUtils;
163
- return {
164
- commands: function(param) {
165
- var program = param.program;
166
- program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(/*#__PURE__*/ _asyncToGenerator(function() {
167
- return __generator(this, function(_state) {
168
- switch(_state.label){
169
- case 0:
170
- return [
171
- 4,
172
- test(api)
173
- ];
174
- case 1:
175
- _state.sent();
176
- return [
177
- 2
178
- ];
179
- }
180
- });
181
- }));
182
- },
183
- validateSchema: function validateSchema() {
184
- return PLUGIN_SCHEMAS["@modern-js/plugin-testing"];
185
- },
186
- config: function config() {
187
- var appContext = api.useAppContext();
188
- testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "testing");
189
- return {
190
- source: {
191
- alias: {
192
- // The module-tools alias configuration is different and more specific than app-tools.
193
- // So for the time being, the @ alias is configured here.
194
- "@": path.join(appContext.appDirectory, "src"),
195
- "@modern-js/runtime/testing": testingExportsUtils.getPath()
196
- }
197
- }
198
- };
199
- },
200
- addRuntimeExports: function addRuntimeExports() {
201
- var testingPath = path.resolve(__dirname, "../");
202
- testingExportsUtils.addExport("export * from '".concat(testingPath, "'"));
203
- },
204
- jestConfig: function() {
205
- var _ref = _asyncToGenerator(function(utils, next) {
206
- var appContext, userConfig, apiOnly, alias;
207
- return __generator(this, function(_state) {
208
- switch(_state.label){
209
- case 0:
210
- appContext = api.useAppContext();
211
- userConfig = api.useResolvedConfigContext();
212
- return [
213
- 4,
214
- isApiOnly(appContext.appDirectory)
215
- ];
216
- case 1:
217
- apiOnly = _state.sent();
218
- if (apiOnly) {
219
- return [
220
- 2,
221
- next(utils)
222
- ];
223
- }
224
- alias = mergeAlias(userConfig.source.alias);
225
- if (testingExportsUtils) {
226
- alias["@modern-js/runtime/testing"] = [
227
- testingExportsUtils.getPath()
228
- ];
229
- }
230
- utils.mergeJestConfig({
231
- globals: _defineProperty({}, MODERNJS_CONFIG_KEY, userConfig),
232
- moduleNameMapper: getModuleNameMapper(alias),
233
- testEnvironment: "jsdom",
234
- resolver: DEFAULT_RESOLVER_PATH,
235
- rootDir: appContext.appDirectory || process.cwd(),
236
- // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
237
- testMatch: [
238
- "<rootDir>/src/**/*.test.[jt]s?(x)",
239
- "<rootDir>/tests/**/*.test.[jt]s?(x)"
240
- ]
241
- });
242
- mergeUserJestConfig(utils);
243
- return [
244
- 2,
245
- next(utils)
246
- ];
247
- }
248
- });
249
- });
250
- return function(utils, next) {
251
- return _ref.apply(this, arguments);
252
- };
253
- }()
254
- };
255
- }
256
- };
257
- };
258
- export { cli_default as default, mergeUserJestConfig };
157
+ export default function() {
158
+ var bffPlugin = testingBffPlugin();
159
+ return {
160
+ name: "@modern-js/plugin-testing",
161
+ usePlugins: [
162
+ bffPlugin
163
+ ],
164
+ post: [
165
+ bffPlugin.name
166
+ ],
167
+ registerHook: testingHooks,
168
+ setup: function(api) {
169
+ var testingExportsUtils;
170
+ return {
171
+ commands: function(param) {
172
+ var program = param.program;
173
+ program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(/* @__PURE__ */ _async_to_generator(function() {
174
+ return __generator(this, function(_state) {
175
+ switch (_state.label) {
176
+ case 0:
177
+ return [
178
+ 4,
179
+ test(api)
180
+ ];
181
+ case 1:
182
+ _state.sent();
183
+ return [
184
+ 2
185
+ ];
186
+ }
187
+ });
188
+ }));
189
+ },
190
+ validateSchema: function validateSchema() {
191
+ return PLUGIN_SCHEMAS["@modern-js/plugin-testing"];
192
+ },
193
+ config: function config() {
194
+ var appContext = api.useAppContext();
195
+ testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "testing");
196
+ return {
197
+ source: {
198
+ alias: {
199
+ // The module-tools alias configuration is different and more specific than app-tools.
200
+ // So for the time being, the @ alias is configured here.
201
+ "@": path.join(appContext.appDirectory, "src"),
202
+ "@modern-js/runtime/testing": testingExportsUtils.getPath()
203
+ }
204
+ }
205
+ };
206
+ },
207
+ addRuntimeExports: function addRuntimeExports() {
208
+ var testingPath = path.resolve(__dirname, "../");
209
+ testingExportsUtils.addExport("export * from '".concat(testingPath, "'"));
210
+ },
211
+ jestConfig: function() {
212
+ var _ref = _async_to_generator(function(utils, next) {
213
+ var appContext, userConfig, apiOnly, alias;
214
+ return __generator(this, function(_state) {
215
+ switch (_state.label) {
216
+ case 0:
217
+ appContext = api.useAppContext();
218
+ userConfig = api.useResolvedConfigContext();
219
+ return [
220
+ 4,
221
+ isApiOnly(appContext.appDirectory)
222
+ ];
223
+ case 1:
224
+ apiOnly = _state.sent();
225
+ if (apiOnly) {
226
+ return [
227
+ 2,
228
+ next(utils)
229
+ ];
230
+ }
231
+ alias = mergeAlias(userConfig.source.alias);
232
+ if (testingExportsUtils) {
233
+ alias["@modern-js/runtime/testing"] = [
234
+ testingExportsUtils.getPath()
235
+ ];
236
+ }
237
+ utils.mergeJestConfig({
238
+ globals: _define_property({}, MODERNJS_CONFIG_KEY, userConfig),
239
+ moduleNameMapper: getModuleNameMapper(alias),
240
+ testEnvironment: "jsdom",
241
+ resolver: DEFAULT_RESOLVER_PATH,
242
+ rootDir: appContext.appDirectory || process.cwd(),
243
+ // testMatch bug on windows, issue: https://github.com/facebook/jest/issues/7914
244
+ testMatch: [
245
+ "<rootDir>/src/**/*.test.[jt]s?(x)",
246
+ "<rootDir>/tests/**/*.test.[jt]s?(x)"
247
+ ]
248
+ });
249
+ mergeUserJestConfig(utils);
250
+ return [
251
+ 2,
252
+ next(utils)
253
+ ];
254
+ }
255
+ });
256
+ });
257
+ return function(utils, next) {
258
+ return _ref.apply(this, arguments);
259
+ };
260
+ }()
261
+ };
262
+ }
263
+ };
264
+ }
265
+ ;