@modern-js/plugin-testing 2.15.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.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/base/config/index.js +15 -39
- package/dist/cjs/base/config/patches/assetsModule.js +7 -35
- package/dist/cjs/base/config/patches/filemock.js +8 -24
- package/dist/cjs/base/config/patches/index.js +13 -28
- package/dist/cjs/base/config/patches/transformer.js +13 -38
- package/dist/cjs/base/config/resolver.js +23 -26
- package/dist/cjs/base/config/testConfigOperator.js +39 -38
- package/dist/cjs/base/config/transformer/babelTransformer.js +16 -37
- package/dist/cjs/base/hook.js +17 -31
- package/dist/cjs/base/index.js +36 -41
- package/dist/cjs/base/runJest.js +31 -57
- package/dist/cjs/base/types/index.js +4 -15
- package/dist/cjs/base/utils.js +30 -53
- package/dist/cjs/cli/bff/app.js +17 -32
- package/dist/cjs/cli/bff/constant.js +7 -25
- package/dist/cjs/cli/bff/index.js +71 -92
- package/dist/cjs/cli/bff/mockAPI.js +115 -92
- package/dist/cjs/cli/bff/setup.js +30 -51
- package/dist/cjs/cli/bff/utils/index.js +21 -45
- package/dist/cjs/cli/index.js +43 -59
- package/dist/cjs/cli/test.js +35 -62
- package/dist/cjs/constant.js +7 -25
- package/dist/cjs/index.js +20 -19
- package/dist/cjs/runtime-testing/app.js +40 -45
- package/dist/cjs/runtime-testing/base.js +34 -40
- package/dist/cjs/runtime-testing/customRender.js +21 -39
- package/dist/cjs/runtime-testing/index.js +19 -18
- package/dist/cjs/runtime-testing/reduck.js +35 -55
- package/dist/cjs/runtime-testing/request.js +16 -39
- package/dist/cjs/runtime-testing/resolvePlugins.js +12 -25
- package/dist/esm/base/config/index.js +146 -139
- package/dist/esm/base/config/patches/assetsModule.js +7 -8
- package/dist/esm/base/config/patches/filemock.js +1 -2
- package/dist/esm/base/config/patches/index.js +214 -207
- package/dist/esm/base/config/patches/transformer.js +27 -28
- package/dist/esm/base/config/resolver.js +22 -35
- package/dist/esm/base/config/testConfigOperator.js +119 -116
- package/dist/esm/base/config/transformer/babelTransformer.js +12 -13
- package/dist/esm/base/hook.js +5 -6
- package/dist/esm/base/index.js +5 -6
- package/dist/esm/base/runJest.js +270 -264
- package/dist/esm/base/types/index.js +1 -1
- package/dist/esm/base/utils.js +66 -67
- package/dist/esm/cli/bff/app.js +187 -179
- package/dist/esm/cli/bff/constant.js +1 -2
- package/dist/esm/cli/bff/index.js +285 -278
- package/dist/esm/cli/bff/mockAPI.js +177 -163
- package/dist/esm/cli/bff/setup.js +182 -174
- package/dist/esm/cli/bff/utils/index.js +40 -41
- package/dist/esm/cli/index.js +249 -242
- package/dist/esm/cli/test.js +172 -166
- package/dist/esm/constant.js +1 -2
- package/dist/esm/runtime-testing/app.js +79 -77
- package/dist/esm/runtime-testing/base.js +2 -3
- package/dist/esm/runtime-testing/customRender.js +30 -31
- package/dist/esm/runtime-testing/reduck.js +72 -73
- package/dist/esm/runtime-testing/request.js +55 -45
- package/dist/esm/runtime-testing/resolvePlugins.js +38 -39
- package/dist/esm-node/base/config/index.js +2 -6
- package/dist/esm-node/base/config/patches/assetsModule.js +1 -4
- package/dist/esm-node/base/config/patches/filemock.js +1 -4
- package/dist/esm-node/base/config/patches/index.js +5 -5
- package/dist/esm-node/base/config/patches/transformer.js +5 -5
- package/dist/esm-node/base/config/resolver.js +20 -19
- package/dist/esm-node/base/config/testConfigOperator.js +30 -13
- package/dist/esm-node/base/config/transformer/babelTransformer.js +3 -6
- package/dist/esm-node/base/hook.js +3 -8
- package/dist/esm-node/base/index.js +5 -13
- package/dist/esm-node/base/runJest.js +8 -20
- package/dist/esm-node/base/types/index.js +1 -0
- package/dist/esm-node/base/utils.js +8 -17
- package/dist/esm-node/cli/bff/app.js +2 -7
- package/dist/esm-node/cli/bff/constant.js +1 -4
- package/dist/esm-node/cli/bff/index.js +43 -54
- package/dist/esm-node/cli/bff/mockAPI.js +65 -59
- package/dist/esm-node/cli/bff/setup.js +11 -19
- package/dist/esm-node/cli/bff/utils/index.js +6 -10
- package/dist/esm-node/cli/index.js +11 -23
- package/dist/esm-node/cli/test.js +19 -28
- package/dist/esm-node/constant.js +1 -4
- package/dist/esm-node/runtime-testing/app.js +22 -10
- package/dist/esm-node/runtime-testing/base.js +2 -6
- package/dist/esm-node/runtime-testing/customRender.js +5 -5
- package/dist/esm-node/runtime-testing/reduck.js +10 -16
- package/dist/esm-node/runtime-testing/request.js +1 -3
- package/dist/esm-node/runtime-testing/resolvePlugins.js +6 -6
- package/package.json +18 -14
|
@@ -1,89 +1,88 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
ownKeys.forEach(function(key) {
|
|
24
|
-
_defineProperty(target, key, source[key]);
|
|
25
|
-
});
|
|
14
|
+
function _object_spread(target) {
|
|
15
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys2 = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys2 = ownKeys2.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
26
22
|
}
|
|
27
|
-
|
|
23
|
+
ownKeys2.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
28
|
}
|
|
29
29
|
function ownKeys(object, enumerableOnly) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
keys.push.apply(keys, symbols);
|
|
30
|
+
var keys = Object.keys(object);
|
|
31
|
+
if (Object.getOwnPropertySymbols) {
|
|
32
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
33
|
+
if (enumerableOnly) {
|
|
34
|
+
symbols = symbols.filter(function(sym) {
|
|
35
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
36
|
+
});
|
|
39
37
|
}
|
|
40
|
-
|
|
38
|
+
keys.push.apply(keys, symbols);
|
|
39
|
+
}
|
|
40
|
+
return keys;
|
|
41
41
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
function _object_spread_props(target, source) {
|
|
43
|
+
source = source != null ? source : {};
|
|
44
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
45
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
46
|
+
} else {
|
|
47
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
48
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return target;
|
|
52
52
|
}
|
|
53
53
|
import { createStore as originCreateStore } from "@modern-js-reduck/store";
|
|
54
54
|
import effectsPlugin from "@modern-js-reduck/plugin-effects";
|
|
55
55
|
import autoActionsPlugin from "@modern-js-reduck/plugin-auto-actions";
|
|
56
56
|
import immerPlugin from "@modern-js-reduck/plugin-immutable";
|
|
57
57
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
|
58
|
-
var effects = function() {
|
|
59
|
-
|
|
58
|
+
export var effects = function() {
|
|
59
|
+
return effectsPlugin;
|
|
60
60
|
};
|
|
61
|
-
var immer = function() {
|
|
62
|
-
|
|
61
|
+
export var immer = function() {
|
|
62
|
+
return immerPlugin;
|
|
63
63
|
};
|
|
64
|
-
var autoActions = function() {
|
|
65
|
-
|
|
64
|
+
export var autoActions = function() {
|
|
65
|
+
return autoActionsPlugin;
|
|
66
66
|
};
|
|
67
|
-
var createStore = function(props) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
67
|
+
export var createStore = function(props) {
|
|
68
|
+
var createStatePlugins = function() {
|
|
69
|
+
var _modernConfig_runtime;
|
|
70
|
+
var modernConfig = global[MODERNJS_CONFIG_KEY];
|
|
71
|
+
var stateConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig_runtime = modernConfig.runtime) === null || _modernConfig_runtime === void 0 ? void 0 : _modernConfig_runtime.state;
|
|
72
|
+
var plugins = [];
|
|
73
|
+
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.effects) !== false) {
|
|
74
|
+
plugins.push(effects());
|
|
75
|
+
}
|
|
76
|
+
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.autoActions) !== false) {
|
|
77
|
+
plugins.push(autoActions());
|
|
78
|
+
}
|
|
79
|
+
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.immer) !== false) {
|
|
80
|
+
plugins.push(immer());
|
|
81
|
+
}
|
|
82
|
+
return ((props === null || props === void 0 ? void 0 : props.plugins) || []).concat(plugins);
|
|
83
|
+
};
|
|
84
|
+
var config = _object_spread_props(_object_spread({}, props || {}), {
|
|
85
|
+
plugins: createStatePlugins()
|
|
86
|
+
});
|
|
87
|
+
return originCreateStore(config);
|
|
88
88
|
};
|
|
89
|
-
export { autoActions, createStore, effects, immer };
|
|
@@ -1,51 +1,61 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
1
|
+
function _array_like_to_array(arr, len) {
|
|
2
|
+
if (len == null || len > arr.length)
|
|
3
|
+
len = arr.length;
|
|
4
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++)
|
|
5
|
+
arr2[i] = arr[i];
|
|
6
|
+
return arr2;
|
|
7
|
+
}
|
|
8
|
+
function _array_with_holes(arr) {
|
|
9
|
+
if (Array.isArray(arr))
|
|
10
|
+
return arr;
|
|
11
|
+
}
|
|
12
|
+
function _array_without_holes(arr) {
|
|
13
|
+
if (Array.isArray(arr))
|
|
14
|
+
return _array_like_to_array(arr);
|
|
15
|
+
}
|
|
16
|
+
function _iterable_to_array(iter) {
|
|
17
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
18
|
+
return Array.from(iter);
|
|
19
|
+
}
|
|
20
|
+
function _non_iterable_rest() {
|
|
21
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
22
|
+
}
|
|
23
|
+
function _non_iterable_spread() {
|
|
24
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
25
|
+
}
|
|
26
|
+
function _to_array(arr) {
|
|
27
|
+
return _array_with_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_rest();
|
|
28
|
+
}
|
|
29
|
+
function _to_consumable_array(arr) {
|
|
30
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
31
|
+
}
|
|
32
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
33
|
+
if (!o)
|
|
34
|
+
return;
|
|
35
|
+
if (typeof o === "string")
|
|
36
|
+
return _array_like_to_array(o, minLen);
|
|
37
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
38
|
+
if (n === "Object" && o.constructor)
|
|
39
|
+
n = o.constructor.name;
|
|
40
|
+
if (n === "Map" || n === "Set")
|
|
41
|
+
return Array.from(n);
|
|
42
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
|
|
43
|
+
return _array_like_to_array(o, minLen);
|
|
34
44
|
}
|
|
35
45
|
import supertest from "supertest";
|
|
36
46
|
import { getApp } from "../cli/bff/app";
|
|
37
47
|
function request() {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
49
|
+
args[_key] = arguments[_key];
|
|
50
|
+
}
|
|
51
|
+
var _args = _to_array(args), fn = _args[0], extraArgs = _args.slice(1);
|
|
52
|
+
var app = getApp();
|
|
53
|
+
if (!fn) {
|
|
54
|
+
return supertest(app);
|
|
55
|
+
}
|
|
56
|
+
fn.returnHttp = true;
|
|
57
|
+
var res = fn.apply(void 0, _to_consumable_array(extraArgs));
|
|
58
|
+
fn.returnHttp = false;
|
|
59
|
+
return res;
|
|
50
60
|
}
|
|
51
61
|
export { request };
|
|
@@ -1,46 +1,45 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
ownKeys.forEach(function(key) {
|
|
24
|
-
_defineProperty(target, key, source[key]);
|
|
25
|
-
});
|
|
14
|
+
function _object_spread(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
|
+
}));
|
|
26
22
|
}
|
|
27
|
-
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_define_property(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
28
|
}
|
|
29
29
|
var allowedFeatures = [
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
"router",
|
|
31
|
+
"state"
|
|
32
32
|
];
|
|
33
|
-
function resolvePlugins(features) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return plugins;
|
|
37
|
-
}
|
|
38
|
-
Object.keys(features).forEach(function(feature) {
|
|
39
|
-
if (allowedFeatures.includes(feature)) {
|
|
40
|
-
var curPluginRes = require("@modern-js/runtime/plugins")[feature](_objectSpread({}, features[feature]));
|
|
41
|
-
plugins.push(curPluginRes);
|
|
42
|
-
}
|
|
43
|
-
});
|
|
33
|
+
export default function resolvePlugins(features) {
|
|
34
|
+
var plugins = [];
|
|
35
|
+
if (!features) {
|
|
44
36
|
return plugins;
|
|
37
|
+
}
|
|
38
|
+
Object.keys(features).forEach(function(feature) {
|
|
39
|
+
if (allowedFeatures.includes(feature)) {
|
|
40
|
+
var curPluginRes = require("@modern-js/runtime/plugins")[feature](_object_spread({}, features[feature]));
|
|
41
|
+
plugins.push(curPluginRes);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
return plugins;
|
|
45
45
|
}
|
|
46
|
-
export { resolvePlugins as default };
|
|
@@ -8,9 +8,5 @@ const patchConfig = async (testOperator) => {
|
|
|
8
8
|
await applyPatches(testOperator);
|
|
9
9
|
return testOperator.jestConfig;
|
|
10
10
|
};
|
|
11
|
-
const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
|
12
|
-
export {
|
|
13
|
-
DEFAULT_RESOLVER_PATH,
|
|
14
|
-
getJestUtils,
|
|
15
|
-
patchConfig
|
|
16
|
-
};
|
|
11
|
+
export const DEFAULT_RESOLVER_PATH = require.resolve("./resolver");
|
|
12
|
+
export { getJestUtils, patchConfig };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const patchAssetsModule = (testOperator) => {
|
|
1
|
+
export const patchAssetsModule = (testOperator) => {
|
|
2
2
|
testOperator.mergeJestConfig({
|
|
3
3
|
moduleNameMapper: {
|
|
4
4
|
"\\.(css|less|scss|sass)$": require.resolve("identity-obj-proxy"),
|
|
@@ -6,6 +6,3 @@ const patchAssetsModule = (testOperator) => {
|
|
|
6
6
|
}
|
|
7
7
|
});
|
|
8
8
|
};
|
|
9
|
-
export {
|
|
10
|
-
patchAssetsModule
|
|
11
|
-
};
|
|
@@ -5,10 +5,10 @@ const _applyPatches = async (patches2, testOperator) => {
|
|
|
5
5
|
await patch(testOperator);
|
|
6
6
|
}
|
|
7
7
|
};
|
|
8
|
-
const patches = [
|
|
9
|
-
|
|
8
|
+
const patches = [
|
|
9
|
+
patchTransformer,
|
|
10
|
+
patchAssetsModule
|
|
11
|
+
];
|
|
12
|
+
export const applyPatches = async (testConfig) => {
|
|
10
13
|
await _applyPatches(patches, testConfig);
|
|
11
14
|
};
|
|
12
|
-
export {
|
|
13
|
-
applyPatches
|
|
14
|
-
};
|
|
@@ -8,7 +8,7 @@ const resolveTsCompilerOptions = () => {
|
|
|
8
8
|
tsCompilerOptions.jsx = "react-jsx";
|
|
9
9
|
return tsCompilerOptions;
|
|
10
10
|
};
|
|
11
|
-
const patchTransformer = (testOperator) => {
|
|
11
|
+
export const patchTransformer = (testOperator) => {
|
|
12
12
|
const { transformer } = testOperator.testConfig;
|
|
13
13
|
if (transformer === "babel-jest") {
|
|
14
14
|
testOperator.mergeJestConfig({
|
|
@@ -21,11 +21,11 @@ const patchTransformer = (testOperator) => {
|
|
|
21
21
|
const compilerOptions = resolveTsCompilerOptions();
|
|
22
22
|
testOperator.mergeJestConfig({
|
|
23
23
|
transform: {
|
|
24
|
-
"\\.[jt]sx?$": [
|
|
24
|
+
"\\.[jt]sx?$": [
|
|
25
|
+
require.resolve("ts-jest"),
|
|
26
|
+
compilerOptions || {}
|
|
27
|
+
]
|
|
25
28
|
}
|
|
26
29
|
});
|
|
27
30
|
}
|
|
28
31
|
};
|
|
29
|
-
export {
|
|
30
|
-
patchTransformer
|
|
31
|
-
};
|
|
@@ -1,21 +1,22 @@
|
|
|
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
1
|
import enhanceResolve from "enhanced-resolve";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
2
|
+
const resolver = enhanceResolve.create.sync({
|
|
3
|
+
conditionNames: [
|
|
4
|
+
"require",
|
|
5
|
+
"node",
|
|
6
|
+
"default"
|
|
7
|
+
],
|
|
8
|
+
extensions: [
|
|
9
|
+
".js",
|
|
10
|
+
".json",
|
|
11
|
+
".node",
|
|
12
|
+
".ts",
|
|
13
|
+
".tsx"
|
|
14
|
+
]
|
|
20
15
|
});
|
|
21
|
-
|
|
16
|
+
const shouldResolveByEnhance = (url) => /^@[^/]+\/[^/]+\/.*/.test(url);
|
|
17
|
+
module.exports = function(request, options) {
|
|
18
|
+
if (shouldResolveByEnhance(request)) {
|
|
19
|
+
return resolver(options.basedir, request);
|
|
20
|
+
}
|
|
21
|
+
return options.defaultResolver(request, options);
|
|
22
|
+
};
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
+
function _define_property(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
1
14
|
import { merge } from "@modern-js/utils/lodash";
|
|
2
15
|
class TestConfigOperator {
|
|
3
|
-
constructor(testConfig) {
|
|
4
|
-
this.defaultTestConfig = {
|
|
5
|
-
transformer: "babel-jest"
|
|
6
|
-
};
|
|
7
|
-
this._testConfig = testConfig;
|
|
8
|
-
this._jestConfig = {};
|
|
9
|
-
this.userJestConfig = testConfig.jest;
|
|
10
|
-
this.initial();
|
|
11
|
-
}
|
|
12
16
|
initial() {
|
|
13
17
|
this._testConfig = merge({}, this.defaultTestConfig, this.testConfig);
|
|
14
18
|
}
|
|
@@ -35,7 +39,10 @@ class TestConfigOperator {
|
|
|
35
39
|
return;
|
|
36
40
|
}
|
|
37
41
|
}
|
|
38
|
-
this._jestConfig = {
|
|
42
|
+
this._jestConfig = {
|
|
43
|
+
...this._jestConfig,
|
|
44
|
+
...sourceConfig
|
|
45
|
+
};
|
|
39
46
|
}
|
|
40
47
|
getFinalConfig() {
|
|
41
48
|
const { userJestConfig } = this;
|
|
@@ -47,7 +54,17 @@ class TestConfigOperator {
|
|
|
47
54
|
}
|
|
48
55
|
return this.jestConfig;
|
|
49
56
|
}
|
|
57
|
+
constructor(testConfig) {
|
|
58
|
+
_define_property(this, "_testConfig", void 0);
|
|
59
|
+
_define_property(this, "_jestConfig", void 0);
|
|
60
|
+
_define_property(this, "userJestConfig", void 0);
|
|
61
|
+
_define_property(this, "defaultTestConfig", {
|
|
62
|
+
transformer: "babel-jest"
|
|
63
|
+
});
|
|
64
|
+
this._testConfig = testConfig;
|
|
65
|
+
this._jestConfig = {};
|
|
66
|
+
this.userJestConfig = testConfig.jest;
|
|
67
|
+
this.initial();
|
|
68
|
+
}
|
|
50
69
|
}
|
|
51
|
-
export {
|
|
52
|
-
TestConfigOperator
|
|
53
|
-
};
|
|
70
|
+
export { TestConfigOperator };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
1
|
+
var _babelJest_createTransformer;
|
|
2
2
|
import babelJest from "babel-jest";
|
|
3
|
-
const babelTransformer = (
|
|
3
|
+
const babelTransformer = (_babelJest_createTransformer = babelJest.createTransformer) === null || _babelJest_createTransformer === void 0 ? void 0 : _babelJest_createTransformer.call(babelJest, {
|
|
4
4
|
presets: [
|
|
5
5
|
[
|
|
6
6
|
require.resolve("@modern-js/babel-preset-app"),
|
|
@@ -13,7 +13,4 @@ const babelTransformer = (_b = (_a = babelJest).createTransformer) == null ? voi
|
|
|
13
13
|
configFile: false,
|
|
14
14
|
babelrc: false
|
|
15
15
|
});
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
babelTransformer_default as default
|
|
19
|
-
};
|
|
16
|
+
export default babelTransformer;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { createAsyncPipeline, createParallelWorkflow } from "@modern-js/plugin";
|
|
2
|
-
const jestConfigHook = createAsyncPipeline();
|
|
3
|
-
const afterTestHook = createParallelWorkflow();
|
|
4
|
-
const testingHooks = {
|
|
2
|
+
export const jestConfigHook = createAsyncPipeline();
|
|
3
|
+
export const afterTestHook = createParallelWorkflow();
|
|
4
|
+
export const testingHooks = {
|
|
5
5
|
jestConfig: createAsyncPipeline(),
|
|
6
6
|
afterTest: createParallelWorkflow()
|
|
7
7
|
};
|
|
8
|
-
export {
|
|
9
|
-
afterTestHook,
|
|
10
|
-
jestConfigHook,
|
|
11
|
-
testingHooks
|
|
12
|
-
};
|
|
@@ -1,14 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
export { runTest, runJest } from "./runJest";
|
|
2
|
+
export { getModuleNameMapper } from "./utils";
|
|
3
|
+
export { DEFAULT_RESOLVER_PATH } from "./config";
|
|
4
|
+
export { TestConfigOperator } from "./config/testConfigOperator";
|
|
5
|
+
export { testingHooks } from "./hook";
|
|
6
6
|
export * from "./types";
|
|
7
|
-
export {
|
|
8
|
-
DEFAULT_RESOLVER_PATH,
|
|
9
|
-
TestConfigOperator,
|
|
10
|
-
getModuleNameMapper,
|
|
11
|
-
runJest,
|
|
12
|
-
runTest,
|
|
13
|
-
testingHooks
|
|
14
|
-
};
|
|
@@ -29,36 +29,28 @@ const readResultsAndExit = (result, globalConfig) => {
|
|
|
29
29
|
});
|
|
30
30
|
if (globalConfig.forceExit) {
|
|
31
31
|
if (!globalConfig.detectOpenHandles) {
|
|
32
|
-
console.warn(
|
|
33
|
-
`${chalk.bold(
|
|
34
|
-
"Force exiting Jest: "
|
|
35
|
-
)}Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?`
|
|
36
|
-
);
|
|
32
|
+
console.warn(`${chalk.bold("Force exiting Jest: ")}Have you considered using \`--detectOpenHandles\` to detect async operations that kept running after all tests finished?`);
|
|
37
33
|
}
|
|
38
34
|
process.exit(code);
|
|
39
35
|
} else if (!globalConfig.detectOpenHandles) {
|
|
40
36
|
setTimeout(() => {
|
|
41
|
-
console.warn(
|
|
42
|
-
chalk.yellow.bold(
|
|
43
|
-
"Jest did not exit one second after the test run has completed.\n\n"
|
|
44
|
-
) + chalk.yellow(
|
|
45
|
-
"This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue."
|
|
46
|
-
)
|
|
47
|
-
);
|
|
37
|
+
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."));
|
|
48
38
|
}, 1e3).unref();
|
|
49
39
|
}
|
|
50
40
|
};
|
|
51
|
-
async function runJest(config, pwd = process.cwd()) {
|
|
41
|
+
export async function runJest(config, pwd = process.cwd()) {
|
|
52
42
|
try {
|
|
53
43
|
const argvConfig = await buildArgv(process.argv.slice(2), config);
|
|
54
|
-
const { results, globalConfig } = await runCLI(argvConfig, [
|
|
44
|
+
const { results, globalConfig } = await runCLI(argvConfig, [
|
|
45
|
+
pwd
|
|
46
|
+
]);
|
|
55
47
|
readResultsAndExit(results, globalConfig);
|
|
56
48
|
} catch (e) {
|
|
57
|
-
console.error(chalk.red((e
|
|
49
|
+
console.error(chalk.red((e === null || e === void 0 ? void 0 : e.stack) || e));
|
|
58
50
|
process.exit(1);
|
|
59
51
|
}
|
|
60
52
|
}
|
|
61
|
-
async function runTest(api, config, pwd = process.cwd()) {
|
|
53
|
+
export async function runTest(api, config, pwd = process.cwd()) {
|
|
62
54
|
process.env.NODE_ENV = "test";
|
|
63
55
|
const jestUtils = getJestUtils(config);
|
|
64
56
|
await patchConfig(jestUtils);
|
|
@@ -72,7 +64,3 @@ async function runTest(api, config, pwd = process.cwd()) {
|
|
|
72
64
|
await runJest(finalConfig, pwd);
|
|
73
65
|
await hookRunners.afterTest();
|
|
74
66
|
}
|
|
75
|
-
export {
|
|
76
|
-
runJest,
|
|
77
|
-
runTest
|
|
78
|
-
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|