@modern-js/plugin-testing 2.20.1-alpha.0 → 2.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/package.json +17 -17
  3. package/dist/js/modern/base/config/index.js +0 -36
  4. package/dist/js/modern/base/config/patches/assetsModule.js +0 -11
  5. package/dist/js/modern/base/config/patches/filemock.js +0 -4
  6. package/dist/js/modern/base/config/patches/index.js +0 -34
  7. package/dist/js/modern/base/config/patches/transformer.js +0 -38
  8. package/dist/js/modern/base/config/resolver.js +0 -21
  9. package/dist/js/modern/base/config/testConfigOperator.js +0 -69
  10. package/dist/js/modern/base/config/transformer/babelTransformer.js +0 -19
  11. package/dist/js/modern/base/hook.js +0 -12
  12. package/dist/js/modern/base/index.js +0 -14
  13. package/dist/js/modern/base/runJest.js +0 -102
  14. package/dist/js/modern/base/types/index.js +0 -0
  15. package/dist/js/modern/base/utils.js +0 -66
  16. package/dist/js/modern/cli/bff/app.js +0 -58
  17. package/dist/js/modern/cli/bff/constant.js +0 -4
  18. package/dist/js/modern/cli/bff/index.js +0 -149
  19. package/dist/js/modern/cli/bff/mockAPI.js +0 -109
  20. package/dist/js/modern/cli/bff/setup.js +0 -75
  21. package/dist/js/modern/cli/bff/utils/index.js +0 -37
  22. package/dist/js/modern/cli/index.js +0 -115
  23. package/dist/js/modern/cli/test.js +0 -61
  24. package/dist/js/modern/constant.js +0 -4
  25. package/dist/js/modern/index.js +0 -3
  26. package/dist/js/modern/runtime-testing/app.js +0 -48
  27. package/dist/js/modern/runtime-testing/base.js +0 -7
  28. package/dist/js/modern/runtime-testing/customRender.js +0 -25
  29. package/dist/js/modern/runtime-testing/index.js +0 -2
  30. package/dist/js/modern/runtime-testing/reduck.js +0 -55
  31. package/dist/js/modern/runtime-testing/request.js +0 -16
  32. package/dist/js/modern/runtime-testing/resolvePlugins.js +0 -33
  33. package/dist/js/node/base/config/index.js +0 -67
  34. package/dist/js/node/base/config/patches/assetsModule.js +0 -40
  35. package/dist/js/node/base/config/patches/filemock.js +0 -25
  36. package/dist/js/node/base/config/patches/index.js +0 -57
  37. package/dist/js/node/base/config/patches/transformer.js +0 -67
  38. package/dist/js/node/base/config/resolver.js +0 -30
  39. package/dist/js/node/base/config/testConfigOperator.js +0 -90
  40. package/dist/js/node/base/config/transformer/babelTransformer.js +0 -46
  41. package/dist/js/node/base/hook.js +0 -37
  42. package/dist/js/node/base/index.js +0 -43
  43. package/dist/js/node/base/runJest.js +0 -132
  44. package/dist/js/node/base/types/index.js +0 -15
  45. package/dist/js/node/base/utils.js +0 -95
  46. package/dist/js/node/cli/bff/app.js +0 -84
  47. package/dist/js/node/cli/bff/constant.js +0 -27
  48. package/dist/js/node/cli/bff/index.js +0 -173
  49. package/dist/js/node/cli/bff/mockAPI.js +0 -134
  50. package/dist/js/node/cli/bff/setup.js +0 -84
  51. package/dist/js/node/cli/bff/utils/index.js +0 -64
  52. package/dist/js/node/cli/index.js +0 -135
  53. package/dist/js/node/cli/test.js +0 -88
  54. package/dist/js/node/constant.js +0 -27
  55. package/dist/js/node/index.js +0 -19
  56. package/dist/js/node/runtime-testing/app.js +0 -73
  57. package/dist/js/node/runtime-testing/base.js +0 -38
  58. package/dist/js/node/runtime-testing/customRender.js +0 -50
  59. package/dist/js/node/runtime-testing/index.js +0 -18
  60. package/dist/js/node/runtime-testing/reduck.js +0 -85
  61. package/dist/js/node/runtime-testing/request.js +0 -45
  62. package/dist/js/node/runtime-testing/resolvePlugins.js +0 -52
  63. package/dist/js/treeshaking/base/config/index.js +0 -154
  64. package/dist/js/treeshaking/base/config/patches/assetsModule.js +0 -9
  65. package/dist/js/treeshaking/base/config/patches/filemock.js +0 -2
  66. package/dist/js/treeshaking/base/config/patches/index.js +0 -225
  67. package/dist/js/treeshaking/base/config/patches/transformer.js +0 -36
  68. package/dist/js/treeshaking/base/config/resolver.js +0 -37
  69. package/dist/js/treeshaking/base/config/testConfigOperator.js +0 -127
  70. package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +0 -17
  71. package/dist/js/treeshaking/base/hook.js +0 -8
  72. package/dist/js/treeshaking/base/index.js +0 -7
  73. package/dist/js/treeshaking/base/runJest.js +0 -292
  74. package/dist/js/treeshaking/base/types/index.js +0 -1
  75. package/dist/js/treeshaking/base/utils.js +0 -76
  76. package/dist/js/treeshaking/cli/bff/app.js +0 -200
  77. package/dist/js/treeshaking/cli/bff/constant.js +0 -2
  78. package/dist/js/treeshaking/cli/bff/index.js +0 -297
  79. package/dist/js/treeshaking/cli/bff/mockAPI.js +0 -188
  80. package/dist/js/treeshaking/cli/bff/setup.js +0 -192
  81. package/dist/js/treeshaking/cli/bff/utils/index.js +0 -47
  82. package/dist/js/treeshaking/cli/index.js +0 -255
  83. package/dist/js/treeshaking/cli/test.js +0 -180
  84. package/dist/js/treeshaking/constant.js +0 -2
  85. package/dist/js/treeshaking/index.js +0 -3
  86. package/dist/js/treeshaking/runtime-testing/app.js +0 -90
  87. package/dist/js/treeshaking/runtime-testing/base.js +0 -4
  88. package/dist/js/treeshaking/runtime-testing/customRender.js +0 -41
  89. package/dist/js/treeshaking/runtime-testing/index.js +0 -2
  90. package/dist/js/treeshaking/runtime-testing/reduck.js +0 -89
  91. package/dist/js/treeshaking/runtime-testing/request.js +0 -51
  92. package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +0 -46
@@ -1,127 +0,0 @@
1
- function _classCallCheck(instance, Constructor) {
2
- if (!(instance instanceof Constructor)) {
3
- throw new TypeError("Cannot call a class as a function");
4
- }
5
- }
6
- function _defineProperties(target, props) {
7
- for(var i = 0; i < props.length; i++){
8
- var descriptor = props[i];
9
- descriptor.enumerable = descriptor.enumerable || false;
10
- descriptor.configurable = true;
11
- if ("value" in descriptor) descriptor.writable = true;
12
- Object.defineProperty(target, descriptor.key, descriptor);
13
- }
14
- }
15
- function _createClass(Constructor, protoProps, staticProps) {
16
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
17
- if (staticProps) _defineProperties(Constructor, staticProps);
18
- return Constructor;
19
- }
20
- function _defineProperty(obj, key, value) {
21
- if (key in obj) {
22
- Object.defineProperty(obj, key, {
23
- value: value,
24
- enumerable: true,
25
- configurable: true,
26
- writable: true
27
- });
28
- } else {
29
- obj[key] = value;
30
- }
31
- return obj;
32
- }
33
- function _objectSpread(target) {
34
- for(var i = 1; i < arguments.length; i++){
35
- var source = arguments[i] != null ? arguments[i] : {};
36
- var ownKeys = Object.keys(source);
37
- if (typeof Object.getOwnPropertySymbols === "function") {
38
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
39
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
40
- }));
41
- }
42
- ownKeys.forEach(function(key) {
43
- _defineProperty(target, key, source[key]);
44
- });
45
- }
46
- return target;
47
- }
48
- import { merge } from "@modern-js/utils/lodash";
49
- var TestConfigOperator = /*#__PURE__*/ function() {
50
- "use strict";
51
- function TestConfigOperator(testConfig) {
52
- _classCallCheck(this, TestConfigOperator);
53
- _defineProperty(this, "_testConfig", void 0);
54
- _defineProperty(this, "_jestConfig", void 0);
55
- _defineProperty(this, "userJestConfig", void 0);
56
- _defineProperty(this, "defaultTestConfig", {
57
- transformer: "babel-jest"
58
- });
59
- this._testConfig = testConfig;
60
- this._jestConfig = {};
61
- this.userJestConfig = testConfig.jest;
62
- this.initial();
63
- }
64
- _createClass(TestConfigOperator, [
65
- {
66
- key: "initial",
67
- value: function initial() {
68
- this._testConfig = merge({}, this.defaultTestConfig, this.testConfig);
69
- }
70
- },
71
- {
72
- key: "jestConfig",
73
- get: function get() {
74
- return this._jestConfig;
75
- }
76
- },
77
- {
78
- key: "testConfig",
79
- get: function get() {
80
- return this._testConfig;
81
- }
82
- },
83
- {
84
- key: "mergeJestConfig",
85
- value: function mergeJestConfig(sourceConfig) {
86
- this._jestConfig = merge({}, this._jestConfig, sourceConfig);
87
- }
88
- },
89
- {
90
- key: "setJestUserConfig",
91
- value: function setJestUserConfig() {
92
- var userJestConfig = this.userJestConfig;
93
- if (typeof userJestConfig === "object") {
94
- this.setJestConfig(userJestConfig);
95
- }
96
- }
97
- },
98
- {
99
- key: "setJestConfig",
100
- value: function setJestConfig(sourceConfig, options) {
101
- if (options) {
102
- var force = options.force;
103
- if (force) {
104
- this._jestConfig = sourceConfig;
105
- return;
106
- }
107
- }
108
- this._jestConfig = _objectSpread({}, this._jestConfig, sourceConfig);
109
- }
110
- },
111
- {
112
- key: "getFinalConfig",
113
- value: function getFinalConfig() {
114
- var userJestConfig = this.userJestConfig;
115
- if (!userJestConfig) {
116
- return this._jestConfig;
117
- }
118
- if (typeof userJestConfig === "function") {
119
- return userJestConfig(this._jestConfig);
120
- }
121
- return this.jestConfig;
122
- }
123
- }
124
- ]);
125
- return TestConfigOperator;
126
- }();
127
- export { TestConfigOperator };
@@ -1,17 +0,0 @@
1
- var ref;
2
- import babelJest from "babel-jest";
3
- var babelTransformer = (ref = babelJest.createTransformer) === null || ref === void 0 ? void 0 : ref.call(babelJest, {
4
- presets: [
5
- [
6
- require.resolve("@modern-js/babel-preset-app"),
7
- {
8
- appDirectory: process.cwd(),
9
- modules: "cjs"
10
- }
11
- ]
12
- ],
13
- configFile: false,
14
- babelrc: false
15
- });
16
- var babelTransformer_default = babelTransformer;
17
- export { babelTransformer_default as default };
@@ -1,8 +0,0 @@
1
- import { createAsyncPipeline, createParallelWorkflow } from "@modern-js/plugin";
2
- var jestConfigHook = createAsyncPipeline();
3
- var afterTestHook = createParallelWorkflow();
4
- var testingHooks = {
5
- jestConfig: createAsyncPipeline(),
6
- afterTest: createParallelWorkflow()
7
- };
8
- export { afterTestHook, jestConfigHook, testingHooks };
@@ -1,7 +0,0 @@
1
- import { runTest, runJest } from "./runJest";
2
- import { getModuleNameMapper } from "./utils";
3
- import { DEFAULT_RESOLVER_PATH } from "./config";
4
- import { TestConfigOperator } from "./config/testConfigOperator";
5
- import { testingHooks } from "./hook";
6
- export * from "./types";
7
- export { DEFAULT_RESOLVER_PATH, TestConfigOperator, getModuleNameMapper, runJest, runTest, testingHooks };
@@ -1,292 +0,0 @@
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
- }
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
- };
29
- }
30
- var __generator = this && this.__generator || function(thisArg, body) {
31
- var f, y, t, g, _ = {
32
- label: 0,
33
- sent: function() {
34
- if (t[0] & 1) throw t[1];
35
- return t[1];
36
- },
37
- trys: [],
38
- ops: []
39
- };
40
- return(g = {
41
- next: verb(0),
42
- "throw": verb(1),
43
- "return": verb(2)
44
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
45
- return this;
46
- }), g);
47
- function verb(n) {
48
- return function(v) {
49
- return step([
50
- n,
51
- v
52
- ]);
53
- };
54
- }
55
- function step(op) {
56
- if (f) throw new TypeError("Generator is already executing.");
57
- while(_)try {
58
- 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;
59
- if (y = 0, t) op = [
60
- op[0] & 2,
61
- t.value
62
- ];
63
- switch(op[0]){
64
- case 0:
65
- case 1:
66
- t = op;
67
- break;
68
- case 4:
69
- _.label++;
70
- return {
71
- value: op[1],
72
- done: false
73
- };
74
- case 5:
75
- _.label++;
76
- y = op[1];
77
- op = [
78
- 0
79
- ];
80
- continue;
81
- case 7:
82
- op = _.ops.pop();
83
- _.trys.pop();
84
- continue;
85
- default:
86
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
87
- _ = 0;
88
- continue;
89
- }
90
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
91
- _.label = op[1];
92
- break;
93
- }
94
- if (op[0] === 6 && _.label < t[1]) {
95
- _.label = t[1];
96
- t = op;
97
- break;
98
- }
99
- if (t && _.label < t[2]) {
100
- _.label = t[2];
101
- _.ops.push(op);
102
- break;
103
- }
104
- if (t[2]) _.ops.pop();
105
- _.trys.pop();
106
- continue;
107
- }
108
- op = body.call(thisArg, _);
109
- } catch (e) {
110
- op = [
111
- 6,
112
- e
113
- ];
114
- y = 0;
115
- } finally{
116
- f = t = 0;
117
- }
118
- if (op[0] & 5) throw op[1];
119
- return {
120
- value: op[0] ? op[1] : void 0,
121
- done: true
122
- };
123
- }
124
- };
125
- import yargs from "yargs/yargs";
126
- import { runCLI } from "jest";
127
- import { chalk } from "@modern-js/utils";
128
- import { getJestUtils, patchConfig } from "./config";
129
- import { debug } from "./utils";
130
- var buildArgv = function() {
131
- var _ref = _asyncToGenerator(function(rawArgv, config) {
132
- var argv, result;
133
- return __generator(this, function(_state) {
134
- switch(_state.label){
135
- case 0:
136
- return [
137
- 4,
138
- yargs(rawArgv).argv
139
- ];
140
- case 1:
141
- argv = _state.sent();
142
- result = {
143
- $0: argv.$0,
144
- _: argv._.slice(1)
145
- };
146
- Object.keys(argv).forEach(function(key) {
147
- if (key.includes("-") || key === "_") {
148
- return;
149
- }
150
- result[key] = argv[key];
151
- });
152
- if (config) {
153
- result.config = JSON.stringify(config);
154
- }
155
- return [
156
- 2,
157
- result
158
- ];
159
- }
160
- });
161
- });
162
- return function buildArgv(rawArgv, config) {
163
- return _ref.apply(this, arguments);
164
- };
165
- }();
166
- var readResultsAndExit = function(result, globalConfig) {
167
- var code = !result || result.success ? 0 : globalConfig.testFailureExitCode;
168
- process.on("exit", function() {
169
- if (typeof code === "number" && code !== 0) {
170
- process.exitCode = code;
171
- }
172
- });
173
- if (globalConfig.forceExit) {
174
- if (!globalConfig.detectOpenHandles) {
175
- console.warn("".concat(chalk.bold("Force exiting Jest: "), "Have you considered using `--detectOpenHandles` to detect async operations that kept running after all tests finished?"));
176
- }
177
- process.exit(code);
178
- } else if (!globalConfig.detectOpenHandles) {
179
- setTimeout(function() {
180
- console.warn(chalk.yellow.bold("Jest did not exit one second after the test run has completed.\n\n") + chalk.yellow("This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue."));
181
- }, 1e3).unref();
182
- }
183
- };
184
- function runJest(config) {
185
- return _runJest.apply(this, arguments);
186
- }
187
- function _runJest() {
188
- _runJest = _asyncToGenerator(function(config) {
189
- var pwd, argvConfig, ref, results, globalConfig, e;
190
- var _arguments = arguments;
191
- return __generator(this, function(_state) {
192
- switch(_state.label){
193
- case 0:
194
- pwd = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : process.cwd();
195
- _state.label = 1;
196
- case 1:
197
- _state.trys.push([
198
- 1,
199
- 4,
200
- ,
201
- 5
202
- ]);
203
- return [
204
- 4,
205
- buildArgv(process.argv.slice(2), config)
206
- ];
207
- case 2:
208
- argvConfig = _state.sent();
209
- return [
210
- 4,
211
- runCLI(argvConfig, [
212
- pwd
213
- ])
214
- ];
215
- case 3:
216
- ref = _state.sent(), results = ref.results, globalConfig = ref.globalConfig;
217
- readResultsAndExit(results, globalConfig);
218
- return [
219
- 3,
220
- 5
221
- ];
222
- case 4:
223
- e = _state.sent();
224
- console.error(chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
225
- process.exit(1);
226
- return [
227
- 3,
228
- 5
229
- ];
230
- case 5:
231
- return [
232
- 2
233
- ];
234
- }
235
- });
236
- });
237
- return _runJest.apply(this, arguments);
238
- }
239
- function runTest(api, config) {
240
- return _runTest.apply(this, arguments);
241
- }
242
- function _runTest() {
243
- _runTest = _asyncToGenerator(function(api, config) {
244
- var pwd, jestUtils, hookRunners, testConfigOperator, finalConfig;
245
- var _arguments = arguments;
246
- return __generator(this, function(_state) {
247
- switch(_state.label){
248
- case 0:
249
- pwd = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : process.cwd();
250
- process.env.NODE_ENV = "test";
251
- jestUtils = getJestUtils(config);
252
- return [
253
- 4,
254
- patchConfig(jestUtils)
255
- ];
256
- case 1:
257
- _state.sent();
258
- jestUtils.setJestUserConfig();
259
- hookRunners = api.useHookRunners();
260
- return [
261
- 4,
262
- hookRunners.jestConfig(jestUtils, {
263
- onLast: function(input) {
264
- return input;
265
- }
266
- })
267
- ];
268
- case 2:
269
- testConfigOperator = _state.sent();
270
- finalConfig = testConfigOperator.getFinalConfig();
271
- debug("Jest config:", finalConfig);
272
- return [
273
- 4,
274
- runJest(finalConfig, pwd)
275
- ];
276
- case 3:
277
- _state.sent();
278
- return [
279
- 4,
280
- hookRunners.afterTest()
281
- ];
282
- case 4:
283
- _state.sent();
284
- return [
285
- 2
286
- ];
287
- }
288
- });
289
- });
290
- return _runTest.apply(this, arguments);
291
- }
292
- export { runJest, runTest };
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,76 +0,0 @@
1
- function _defineProperty(obj, key, value) {
2
- if (key in obj) {
3
- Object.defineProperty(obj, key, {
4
- value: value,
5
- enumerable: true,
6
- configurable: true,
7
- writable: true
8
- });
9
- } else {
10
- obj[key] = value;
11
- }
12
- return obj;
13
- }
14
- function _objectSpread(target) {
15
- for(var i = 1; i < arguments.length; i++){
16
- var source = arguments[i] != null ? arguments[i] : {};
17
- var ownKeys = Object.keys(source);
18
- if (typeof Object.getOwnPropertySymbols === "function") {
19
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
- }));
22
- }
23
- ownKeys.forEach(function(key) {
24
- _defineProperty(target, key, source[key]);
25
- });
26
- }
27
- return target;
28
- }
29
- import fs from "fs";
30
- import path from "path";
31
- import { createDebugger } from "@modern-js/utils";
32
- var debug = createDebugger("test");
33
- var readCompilerOptions = function() {
34
- var pwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : process.cwd(), filename = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "tsconfig.json";
35
- var tsConfig = {};
36
- var extendedCompilerOptions = {};
37
- var tsconfigFile = "";
38
- try {
39
- var maybeTsconfigFile = path.join(pwd, filename);
40
- if (fs.existsSync(maybeTsconfigFile)) {
41
- tsconfigFile = maybeTsconfigFile;
42
- } else {
43
- tsconfigFile = require.resolve(filename);
44
- }
45
- var ref;
46
- ref = require("typescript").parseConfigFileTextToJson(tsconfigFile, fs.readFileSync(tsconfigFile, "utf8")), tsConfig = ref.config, ref;
47
- } catch (e) {
48
- return {};
49
- }
50
- if (tsConfig.extends) {
51
- extendedCompilerOptions = readCompilerOptions(path.dirname(tsconfigFile), tsConfig.extends);
52
- }
53
- return _objectSpread({}, extendedCompilerOptions, tsConfig.compilerOptions);
54
- };
55
- var getModuleNameMapper = function(alias) {
56
- return Object.keys(alias).reduce(function(memo, cur) {
57
- var aliasValue = Array.isArray(alias[cur]) ? alias[cur] : [
58
- alias[cur]
59
- ];
60
- var isFile = aliasValue.some(function(s) {
61
- return s.endsWith(".js");
62
- });
63
- if (cur === "@modern-js/runtime$") {
64
- memo[".+".concat(cur)] = aliasValue[0];
65
- return memo;
66
- }
67
- if (isFile) {
68
- memo[cur] = aliasValue[0];
69
- }
70
- var key = "^".concat(cur, "/(.*)$");
71
- var value = path.normalize("".concat(aliasValue, "/$1"));
72
- memo[key] = value;
73
- return memo;
74
- }, {});
75
- };
76
- export { debug, getModuleNameMapper, readCompilerOptions };