@modern-js/plugin-testing 2.15.0 → 2.17.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/dist/cjs/base/config/index.js +15 -39
  3. package/dist/cjs/base/config/patches/assetsModule.js +7 -35
  4. package/dist/cjs/base/config/patches/filemock.js +8 -24
  5. package/dist/cjs/base/config/patches/index.js +13 -28
  6. package/dist/cjs/base/config/patches/transformer.js +13 -38
  7. package/dist/cjs/base/config/resolver.js +23 -26
  8. package/dist/cjs/base/config/testConfigOperator.js +39 -38
  9. package/dist/cjs/base/config/transformer/babelTransformer.js +16 -37
  10. package/dist/cjs/base/hook.js +17 -31
  11. package/dist/cjs/base/index.js +36 -41
  12. package/dist/cjs/base/runJest.js +31 -57
  13. package/dist/cjs/base/types/index.js +4 -15
  14. package/dist/cjs/base/utils.js +30 -53
  15. package/dist/cjs/cli/bff/app.js +17 -32
  16. package/dist/cjs/cli/bff/constant.js +7 -25
  17. package/dist/cjs/cli/bff/index.js +71 -92
  18. package/dist/cjs/cli/bff/mockAPI.js +115 -92
  19. package/dist/cjs/cli/bff/setup.js +30 -51
  20. package/dist/cjs/cli/bff/utils/index.js +21 -45
  21. package/dist/cjs/cli/index.js +43 -59
  22. package/dist/cjs/cli/test.js +35 -62
  23. package/dist/cjs/constant.js +7 -25
  24. package/dist/cjs/index.js +20 -19
  25. package/dist/cjs/runtime-testing/app.js +40 -45
  26. package/dist/cjs/runtime-testing/base.js +34 -40
  27. package/dist/cjs/runtime-testing/customRender.js +21 -39
  28. package/dist/cjs/runtime-testing/index.js +19 -18
  29. package/dist/cjs/runtime-testing/reduck.js +35 -55
  30. package/dist/cjs/runtime-testing/request.js +16 -39
  31. package/dist/cjs/runtime-testing/resolvePlugins.js +12 -25
  32. package/dist/esm/base/config/index.js +146 -139
  33. package/dist/esm/base/config/patches/assetsModule.js +7 -8
  34. package/dist/esm/base/config/patches/filemock.js +1 -2
  35. package/dist/esm/base/config/patches/index.js +214 -207
  36. package/dist/esm/base/config/patches/transformer.js +27 -28
  37. package/dist/esm/base/config/resolver.js +22 -35
  38. package/dist/esm/base/config/testConfigOperator.js +119 -116
  39. package/dist/esm/base/config/transformer/babelTransformer.js +12 -13
  40. package/dist/esm/base/hook.js +5 -6
  41. package/dist/esm/base/index.js +5 -6
  42. package/dist/esm/base/runJest.js +270 -264
  43. package/dist/esm/base/types/index.js +1 -1
  44. package/dist/esm/base/utils.js +66 -67
  45. package/dist/esm/cli/bff/app.js +187 -179
  46. package/dist/esm/cli/bff/constant.js +1 -2
  47. package/dist/esm/cli/bff/index.js +285 -278
  48. package/dist/esm/cli/bff/mockAPI.js +177 -163
  49. package/dist/esm/cli/bff/setup.js +182 -174
  50. package/dist/esm/cli/bff/utils/index.js +40 -41
  51. package/dist/esm/cli/index.js +249 -242
  52. package/dist/esm/cli/test.js +172 -166
  53. package/dist/esm/constant.js +1 -2
  54. package/dist/esm/runtime-testing/app.js +79 -77
  55. package/dist/esm/runtime-testing/base.js +2 -3
  56. package/dist/esm/runtime-testing/customRender.js +30 -31
  57. package/dist/esm/runtime-testing/reduck.js +72 -73
  58. package/dist/esm/runtime-testing/request.js +55 -45
  59. package/dist/esm/runtime-testing/resolvePlugins.js +38 -39
  60. package/dist/esm-node/base/config/index.js +2 -6
  61. package/dist/esm-node/base/config/patches/assetsModule.js +1 -4
  62. package/dist/esm-node/base/config/patches/filemock.js +1 -4
  63. package/dist/esm-node/base/config/patches/index.js +5 -5
  64. package/dist/esm-node/base/config/patches/transformer.js +5 -5
  65. package/dist/esm-node/base/config/resolver.js +20 -19
  66. package/dist/esm-node/base/config/testConfigOperator.js +30 -13
  67. package/dist/esm-node/base/config/transformer/babelTransformer.js +3 -6
  68. package/dist/esm-node/base/hook.js +3 -8
  69. package/dist/esm-node/base/index.js +5 -13
  70. package/dist/esm-node/base/runJest.js +8 -20
  71. package/dist/esm-node/base/types/index.js +1 -0
  72. package/dist/esm-node/base/utils.js +8 -17
  73. package/dist/esm-node/cli/bff/app.js +2 -7
  74. package/dist/esm-node/cli/bff/constant.js +1 -4
  75. package/dist/esm-node/cli/bff/index.js +43 -54
  76. package/dist/esm-node/cli/bff/mockAPI.js +65 -59
  77. package/dist/esm-node/cli/bff/setup.js +11 -19
  78. package/dist/esm-node/cli/bff/utils/index.js +6 -10
  79. package/dist/esm-node/cli/index.js +11 -23
  80. package/dist/esm-node/cli/test.js +19 -28
  81. package/dist/esm-node/constant.js +1 -4
  82. package/dist/esm-node/runtime-testing/app.js +22 -10
  83. package/dist/esm-node/runtime-testing/base.js +2 -6
  84. package/dist/esm-node/runtime-testing/customRender.js +5 -5
  85. package/dist/esm-node/runtime-testing/reduck.js +10 -16
  86. package/dist/esm-node/runtime-testing/request.js +1 -3
  87. package/dist/esm-node/runtime-testing/resolvePlugins.js +6 -6
  88. package/package.json +18 -14
@@ -1,298 +1,305 @@
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
- function _objectSpread(target) {
44
- for(var i = 1; i < arguments.length; i++){
45
- var source = arguments[i] != null ? arguments[i] : {};
46
- var ownKeys = Object.keys(source);
47
- if (typeof Object.getOwnPropertySymbols === "function") {
48
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
- }));
51
- }
52
- ownKeys.forEach(function(key) {
53
- _defineProperty(target, key, source[key]);
54
- });
43
+ function _object_spread(target) {
44
+ for (var i = 1; i < arguments.length; i++) {
45
+ var source = arguments[i] != null ? arguments[i] : {};
46
+ var ownKeys = Object.keys(source);
47
+ if (typeof Object.getOwnPropertySymbols === "function") {
48
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
49
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
50
+ }));
55
51
  }
56
- return target;
52
+ ownKeys.forEach(function(key) {
53
+ _define_property(target, key, source[key]);
54
+ });
55
+ }
56
+ return target;
57
57
  }
58
- var __generator = this && this.__generator || function(thisArg, body) {
59
- var f, y, t, g, _ = {
60
- label: 0,
61
- sent: function() {
62
- if (t[0] & 1) throw t[1];
63
- return t[1];
64
- },
65
- trys: [],
66
- ops: []
58
+ var __generator = function(thisArg, body) {
59
+ var f, y, t, g, _ = {
60
+ label: 0,
61
+ sent: function() {
62
+ if (t[0] & 1)
63
+ throw t[1];
64
+ return t[1];
65
+ },
66
+ trys: [],
67
+ ops: []
68
+ };
69
+ return g = {
70
+ next: verb(0),
71
+ "throw": verb(1),
72
+ "return": verb(2)
73
+ }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
74
+ return this;
75
+ }), g;
76
+ function verb(n) {
77
+ return function(v) {
78
+ return step([
79
+ n,
80
+ v
81
+ ]);
67
82
  };
68
- return(g = {
69
- next: verb(0),
70
- "throw": verb(1),
71
- "return": verb(2)
72
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
73
- return this;
74
- }), g);
75
- function verb(n) {
76
- return function(v) {
77
- return step([
78
- n,
79
- v
80
- ]);
81
- };
82
- }
83
- function step(op) {
84
- if (f) throw new TypeError("Generator is already executing.");
85
- while(_)try {
86
- 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;
87
- if (y = 0, t) op = [
88
- op[0] & 2,
89
- t.value
90
- ];
91
- switch(op[0]){
92
- case 0:
93
- case 1:
94
- t = op;
95
- break;
96
- case 4:
97
- _.label++;
98
- return {
99
- value: op[1],
100
- done: false
101
- };
102
- case 5:
103
- _.label++;
104
- y = op[1];
105
- op = [
106
- 0
107
- ];
108
- continue;
109
- case 7:
110
- op = _.ops.pop();
111
- _.trys.pop();
112
- continue;
113
- default:
114
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
115
- _ = 0;
116
- continue;
117
- }
118
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
119
- _.label = op[1];
120
- break;
121
- }
122
- if (op[0] === 6 && _.label < t[1]) {
123
- _.label = t[1];
124
- t = op;
125
- break;
126
- }
127
- if (t && _.label < t[2]) {
128
- _.label = t[2];
129
- _.ops.push(op);
130
- break;
131
- }
132
- if (t[2]) _.ops.pop();
133
- _.trys.pop();
134
- continue;
135
- }
136
- op = body.call(thisArg, _);
137
- } catch (e) {
83
+ }
84
+ function step(op) {
85
+ if (f)
86
+ throw new TypeError("Generator is already executing.");
87
+ while (_)
88
+ try {
89
+ 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)
90
+ return t;
91
+ if (y = 0, t)
92
+ op = [
93
+ op[0] & 2,
94
+ t.value
95
+ ];
96
+ switch (op[0]) {
97
+ case 0:
98
+ case 1:
99
+ t = op;
100
+ break;
101
+ case 4:
102
+ _.label++;
103
+ return {
104
+ value: op[1],
105
+ done: false
106
+ };
107
+ case 5:
108
+ _.label++;
109
+ y = op[1];
138
110
  op = [
139
- 6,
140
- e
111
+ 0
141
112
  ];
142
- y = 0;
143
- } finally{
144
- f = t = 0;
113
+ continue;
114
+ case 7:
115
+ op = _.ops.pop();
116
+ _.trys.pop();
117
+ continue;
118
+ default:
119
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
120
+ _ = 0;
121
+ continue;
122
+ }
123
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
124
+ _.label = op[1];
125
+ break;
126
+ }
127
+ if (op[0] === 6 && _.label < t[1]) {
128
+ _.label = t[1];
129
+ t = op;
130
+ break;
131
+ }
132
+ if (t && _.label < t[2]) {
133
+ _.label = t[2];
134
+ _.ops.push(op);
135
+ break;
136
+ }
137
+ if (t[2])
138
+ _.ops.pop();
139
+ _.trys.pop();
140
+ continue;
145
141
  }
146
- if (op[0] & 5) throw op[1];
147
- return {
148
- value: op[0] ? op[1] : void 0,
149
- done: true
150
- };
151
- }
142
+ op = body.call(thisArg, _);
143
+ } catch (e) {
144
+ op = [
145
+ 6,
146
+ e
147
+ ];
148
+ y = 0;
149
+ } finally {
150
+ f = t = 0;
151
+ }
152
+ if (op[0] & 5)
153
+ throw op[1];
154
+ return {
155
+ value: op[0] ? op[1] : void 0,
156
+ done: true
157
+ };
158
+ }
152
159
  };
153
160
  import path from "path";
154
161
  import { isApiOnly } from "@modern-js/utils";
155
162
  import { getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../../base";
156
163
  import { bff_info_key } from "./constant";
157
164
  import { isBFFProject } from "./utils";
158
- var setJestConfigForBFF = function() {
159
- var _ref = _asyncToGenerator(function(param) {
160
- var pwd, userConfig, plugins, routes, utils, _userConfig_source, bffConfig, jestConfig, alias, aliasMapper, moduleNameMapper, transform, apiOnly, mergedModuleNameMapper, resolver, configFields, commonConfig;
161
- return __generator(this, function(_state) {
162
- switch(_state.label){
165
+ export var setJestConfigForBFF = function() {
166
+ var _ref = _async_to_generator(function(param) {
167
+ var pwd, userConfig, plugins, routes, utils, _userConfig_source, bffConfig, jestConfig, alias, aliasMapper, moduleNameMapper, transform, apiOnly, mergedModuleNameMapper, resolver, configFields, commonConfig;
168
+ return __generator(this, function(_state) {
169
+ switch (_state.label) {
170
+ case 0:
171
+ pwd = param.pwd, userConfig = param.userConfig, plugins = param.plugins, routes = param.routes, utils = param.utils;
172
+ bffConfig = {
173
+ rootDir: path.join(pwd, "./api"),
174
+ setupFilesAfterEnv: [
175
+ require.resolve("./setup")
176
+ ],
177
+ testEnvironment: "node",
178
+ testMatch: [
179
+ "**/api/**/*.test.[jt]s"
180
+ ],
181
+ globals: _define_property({}, bff_info_key, {
182
+ appDir: pwd,
183
+ modernUserConfig: userConfig,
184
+ plugins,
185
+ routes
186
+ })
187
+ };
188
+ jestConfig = utils.jestConfig;
189
+ alias = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.alias) || {};
190
+ aliasMapper = getModuleNameMapper(alias);
191
+ moduleNameMapper = jestConfig.moduleNameMapper;
192
+ transform = {
193
+ "\\.[jt]sx?$": [
194
+ require.resolve("ts-jest"),
195
+ {
196
+ diagnostics: {
197
+ warnOnly: true
198
+ }
199
+ }
200
+ ]
201
+ };
202
+ return [
203
+ 4,
204
+ isApiOnly(pwd)
205
+ ];
206
+ case 1:
207
+ apiOnly = _state.sent();
208
+ mergedModuleNameMapper = _object_spread({}, moduleNameMapper, aliasMapper);
209
+ resolver = jestConfig.resolver || DEFAULT_RESOLVER_PATH;
210
+ configFields = [
211
+ "coverage",
212
+ "collectCoverage",
213
+ "testTimeout"
214
+ ];
215
+ commonConfig = configFields.reduce(function(obj, field) {
216
+ if (jestConfig.hasOwnProperty(field)) {
217
+ obj[field] = jestConfig[field];
218
+ }
219
+ return obj;
220
+ }, {});
221
+ if (!apiOnly) {
222
+ utils.setJestConfig({
223
+ projects: [
224
+ _object_spread({}, jestConfig),
225
+ _object_spread({
226
+ transform,
227
+ moduleNameMapper: mergedModuleNameMapper,
228
+ resolver
229
+ }, bffConfig)
230
+ ]
231
+ }, {
232
+ force: true
233
+ });
234
+ } else {
235
+ utils.setJestConfig({
236
+ projects: [
237
+ _object_spread({
238
+ transform,
239
+ moduleNameMapper: mergedModuleNameMapper,
240
+ resolver
241
+ }, bffConfig)
242
+ ]
243
+ }, {
244
+ force: true
245
+ });
246
+ }
247
+ utils.setJestConfig(commonConfig);
248
+ return [
249
+ 2
250
+ ];
251
+ }
252
+ });
253
+ });
254
+ return function setJestConfigForBFF2(_) {
255
+ return _ref.apply(this, arguments);
256
+ };
257
+ }();
258
+ export default function() {
259
+ return {
260
+ name: "@modern-js/testing-plugin-bff",
261
+ setup: function setup(api) {
262
+ return {
263
+ jestConfig: function() {
264
+ var _ref = _async_to_generator(function(utils, next) {
265
+ var appContext, pwd, userConfig;
266
+ return __generator(this, function(_state) {
267
+ switch (_state.label) {
163
268
  case 0:
164
- pwd = param.pwd, userConfig = param.userConfig, plugins = param.plugins, routes = param.routes, utils = param.utils;
165
- bffConfig = {
166
- rootDir: path.join(pwd, "./api"),
167
- setupFilesAfterEnv: [
168
- require.resolve("./setup")
169
- ],
170
- testEnvironment: "node",
171
- testMatch: [
172
- "**/api/**/*.test.[jt]s"
173
- ],
174
- globals: _defineProperty({}, bff_info_key, {
175
- appDir: pwd,
176
- modernUserConfig: userConfig,
177
- plugins: plugins,
178
- routes: routes
179
- })
180
- };
181
- jestConfig = utils.jestConfig;
182
- alias = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.alias) || {};
183
- aliasMapper = getModuleNameMapper(alias);
184
- moduleNameMapper = jestConfig.moduleNameMapper;
185
- transform = {
186
- "\\.[jt]sx?$": [
187
- require.resolve("ts-jest"),
188
- {
189
- diagnostics: {
190
- warnOnly: true
191
- }
192
- }
193
- ]
194
- };
269
+ appContext = api.useAppContext();
270
+ pwd = appContext.appDirectory;
271
+ if (!isBFFProject(pwd)) {
195
272
  return [
196
- 4,
197
- isApiOnly(pwd)
273
+ 2,
274
+ next(utils)
198
275
  ];
276
+ }
277
+ userConfig = api.useResolvedConfigContext();
278
+ return [
279
+ 4,
280
+ setJestConfigForBFF({
281
+ pwd,
282
+ userConfig,
283
+ routes: appContext.serverRoutes,
284
+ plugins: appContext.serverInternalPlugins,
285
+ utils
286
+ })
287
+ ];
199
288
  case 1:
200
- apiOnly = _state.sent();
201
- mergedModuleNameMapper = _objectSpread({}, moduleNameMapper, aliasMapper);
202
- resolver = jestConfig.resolver || DEFAULT_RESOLVER_PATH;
203
- configFields = [
204
- "coverage",
205
- "collectCoverage",
206
- "testTimeout"
207
- ];
208
- commonConfig = configFields.reduce(function(obj, field) {
209
- if (jestConfig.hasOwnProperty(field)) {
210
- obj[field] = jestConfig[field];
211
- }
212
- return obj;
213
- }, {});
214
- if (!apiOnly) {
215
- utils.setJestConfig({
216
- projects: [
217
- _objectSpread({}, jestConfig),
218
- _objectSpread({
219
- transform: transform,
220
- moduleNameMapper: mergedModuleNameMapper,
221
- resolver: resolver
222
- }, bffConfig)
223
- ]
224
- }, {
225
- force: true
226
- });
227
- } else {
228
- utils.setJestConfig({
229
- projects: [
230
- _objectSpread({
231
- transform: transform,
232
- moduleNameMapper: mergedModuleNameMapper,
233
- resolver: resolver
234
- }, bffConfig)
235
- ]
236
- }, {
237
- force: true
238
- });
239
- }
240
- utils.setJestConfig(commonConfig);
241
- return [
242
- 2
243
- ];
244
- }
245
- });
246
- });
247
- return function setJestConfigForBFF(_) {
248
- return _ref.apply(this, arguments);
249
- };
250
- }();
251
- var bff_default = function() {
252
- return {
253
- name: "@modern-js/testing-plugin-bff",
254
- setup: function setup(api) {
255
- return {
256
- jestConfig: function() {
257
- var _ref = _asyncToGenerator(function(utils, next) {
258
- var appContext, pwd, userConfig;
259
- return __generator(this, function(_state) {
260
- switch(_state.label){
261
- case 0:
262
- appContext = api.useAppContext();
263
- pwd = appContext.appDirectory;
264
- if (!isBFFProject(pwd)) {
265
- return [
266
- 2,
267
- next(utils)
268
- ];
269
- }
270
- userConfig = api.useResolvedConfigContext();
271
- return [
272
- 4,
273
- setJestConfigForBFF({
274
- pwd: pwd,
275
- userConfig: userConfig,
276
- routes: appContext.serverRoutes,
277
- plugins: appContext.serverInternalPlugins,
278
- utils: utils
279
- })
280
- ];
281
- case 1:
282
- _state.sent();
283
- return [
284
- 2,
285
- next(utils)
286
- ];
287
- }
288
- });
289
- });
290
- return function(utils, next) {
291
- return _ref.apply(this, arguments);
292
- };
293
- }()
294
- };
295
- }
296
- };
297
- };
298
- export { bff_default as default, setJestConfigForBFF };
289
+ _state.sent();
290
+ return [
291
+ 2,
292
+ next(utils)
293
+ ];
294
+ }
295
+ });
296
+ });
297
+ return function(utils, next) {
298
+ return _ref.apply(this, arguments);
299
+ };
300
+ }()
301
+ };
302
+ }
303
+ };
304
+ }
305
+ ;