@modern-js/plugin-testing 2.0.0-beta.3 → 2.0.0-beta.6
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 +159 -0
- package/dist/js/modern/base/config/index.js +29 -9
- package/dist/js/modern/base/config/patches/assetsModule.js +7 -7
- package/dist/js/modern/base/config/patches/filemock.js +4 -1
- package/dist/js/modern/base/config/patches/index.js +30 -7
- package/dist/js/modern/base/config/patches/transformer.js +13 -18
- package/dist/js/modern/base/config/resolver.js +20 -11
- package/dist/js/modern/base/config/testConfigOperator.js +29 -23
- package/dist/js/modern/base/config/transformer/babelTransformer.js +16 -8
- package/dist/js/modern/base/hook.js +10 -5
- package/dist/js/modern/base/index.js +14 -6
- package/dist/js/modern/base/runJest.js +73 -62
- package/dist/js/modern/base/utils.js +40 -23
- package/dist/js/modern/cli/bff/app.js +37 -12
- package/dist/js/modern/cli/bff/constant.js +4 -1
- package/dist/js/modern/cli/bff/index.js +95 -52
- package/dist/js/modern/cli/bff/mockAPI.js +79 -64
- package/dist/js/modern/cli/bff/setup.js +71 -34
- package/dist/js/modern/cli/bff/utils/index.js +31 -15
- package/dist/js/modern/cli/index.js +65 -30
- package/dist/js/modern/cli/test.js +53 -18
- package/dist/js/modern/constant.js +4 -1
- package/dist/js/modern/index.js +3 -3
- package/dist/js/modern/modern-app.env.d.js +0 -0
- package/dist/js/modern/runtime-testing/app.js +25 -14
- package/dist/js/modern/runtime-testing/base.js +7 -3
- package/dist/js/modern/runtime-testing/customRender.js +24 -10
- package/dist/js/modern/runtime-testing/index.js +1 -1
- package/dist/js/modern/runtime-testing/reduck.js +41 -19
- package/dist/js/modern/runtime-testing/request.js +4 -4
- package/dist/js/modern/runtime-testing/resolvePlugins.js +24 -8
- package/dist/js/node/base/config/index.js +62 -18
- package/dist/js/node/base/config/patches/assetsModule.js +34 -12
- package/dist/js/node/base/config/patches/filemock.js +24 -7
- package/dist/js/node/base/config/patches/index.js +54 -15
- package/dist/js/node/base/config/patches/transformer.js +42 -25
- package/dist/js/node/base/config/resolver.js +25 -10
- package/dist/js/node/base/config/testConfigOperator.js +51 -30
- package/dist/js/node/base/config/transformer/babelTransformer.js +42 -15
- package/dist/js/node/base/hook.js +34 -13
- package/dist/js/node/base/index.js +39 -62
- package/dist/js/node/base/runJest.js +104 -71
- package/dist/js/node/base/types/index.js +15 -0
- package/dist/js/node/base/utils.js +70 -34
- package/dist/js/node/cli/bff/app.js +64 -22
- package/dist/js/node/cli/bff/constant.js +26 -7
- package/dist/js/node/cli/bff/index.js +123 -65
- package/dist/js/node/cli/bff/mockAPI.js +103 -71
- package/dist/js/node/cli/bff/setup.js +71 -28
- package/dist/js/node/cli/bff/utils/index.js +57 -22
- package/dist/js/node/cli/index.js +92 -46
- package/dist/js/node/cli/test.js +81 -27
- package/dist/js/node/constant.js +26 -7
- package/dist/js/node/index.js +19 -18
- package/dist/js/node/modern-app.env.d.js +0 -0
- package/dist/js/node/runtime-testing/app.js +53 -25
- package/dist/js/node/runtime-testing/base.js +34 -32
- package/dist/js/node/runtime-testing/customRender.js +49 -18
- package/dist/js/node/runtime-testing/index.js +18 -27
- package/dist/js/node/runtime-testing/reduck.js +72 -31
- package/dist/js/node/runtime-testing/request.js +36 -13
- package/dist/js/node/runtime-testing/resolvePlugins.js +41 -12
- package/dist/js/treeshaking/base/config/index.js +150 -31
- package/dist/js/treeshaking/base/config/patches/assetsModule.js +9 -11
- package/dist/js/treeshaking/base/config/patches/filemock.js +2 -1
- package/dist/js/treeshaking/base/config/patches/index.js +221 -64
- package/dist/js/treeshaking/base/config/patches/transformer.js +34 -37
- package/dist/js/treeshaking/base/config/resolver.js +36 -13
- package/dist/js/treeshaking/base/config/testConfigOperator.js +120 -69
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +16 -10
- package/dist/js/treeshaking/base/hook.js +8 -7
- package/dist/js/treeshaking/base/index.js +7 -6
- package/dist/js/treeshaking/base/runJest.js +281 -164
- package/dist/js/treeshaking/base/types/index.js +1 -0
- package/dist/js/treeshaking/base/utils.js +72 -48
- package/dist/js/treeshaking/cli/bff/app.js +192 -68
- package/dist/js/treeshaking/cli/bff/constant.js +2 -1
- package/dist/js/treeshaking/cli/bff/index.js +291 -130
- package/dist/js/treeshaking/cli/bff/mockAPI.js +181 -91
- package/dist/js/treeshaking/cli/bff/setup.js +185 -59
- package/dist/js/treeshaking/cli/bff/utils/index.js +47 -21
- package/dist/js/treeshaking/cli/index.js +249 -108
- package/dist/js/treeshaking/cli/test.js +177 -44
- package/dist/js/treeshaking/constant.js +2 -1
- package/dist/js/treeshaking/index.js +3 -3
- package/dist/js/treeshaking/modern-app.env.d.js +1 -0
- package/dist/js/treeshaking/runtime-testing/app.js +85 -39
- package/dist/js/treeshaking/runtime-testing/base.js +4 -3
- package/dist/js/treeshaking/runtime-testing/customRender.js +38 -10
- package/dist/js/treeshaking/runtime-testing/index.js +1 -1
- package/dist/js/treeshaking/runtime-testing/reduck.js +85 -33
- package/dist/js/treeshaking/runtime-testing/request.js +49 -19
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +45 -14
- package/dist/types/base/config/index.d.ts +1 -0
- package/dist/types/base/config/patches/assetsModule.d.ts +1 -0
- package/dist/types/base/config/patches/filemock.d.ts +1 -0
- package/dist/types/base/config/patches/transformer.d.ts +1 -0
- package/dist/types/base/config/testConfigOperator.d.ts +2 -0
- package/dist/types/base/runJest.d.ts +2 -0
- package/dist/types/base/utils.d.ts +1 -0
- package/dist/types/cli/bff/index.d.ts +2 -0
- package/dist/types/cli/bff/mockAPI.d.ts +1 -0
- package/dist/types/cli/index.d.ts +2 -0
- package/dist/types/runtime-testing/app.d.ts +3 -0
- package/dist/types/runtime-testing/customRender.d.ts +2 -0
- package/package.json +21 -25
|
@@ -1,39 +1,36 @@
|
|
|
1
1
|
import { readCompilerOptions } from "../../utils";
|
|
2
|
-
var resolveTsCompilerOptions = function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
var resolveTsCompilerOptions = function() {
|
|
3
|
+
var tsCompilerOptions = readCompilerOptions() || {};
|
|
4
|
+
var jsx = tsCompilerOptions.jsx;
|
|
5
|
+
if (!jsx) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
tsCompilerOptions.jsx = "react-jsx";
|
|
9
|
+
return tsCompilerOptions;
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
11
|
+
var patchTransformer = function(testOperator) {
|
|
12
|
+
var transformer = testOperator.testConfig.transformer;
|
|
13
|
+
if (transformer === "babel-jest") {
|
|
14
|
+
testOperator.mergeJestConfig({
|
|
15
|
+
transform: {
|
|
16
|
+
"\\.[jt]sx?$": require.resolve("../transformer/babelTransformer")
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
if (transformer === "ts-jest") {
|
|
21
|
+
testOperator.mergeJestConfig({
|
|
22
|
+
transform: {
|
|
23
|
+
"\\.[jt]sx?$": require.resolve("ts-jest")
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
var compilerOptions = resolveTsCompilerOptions();
|
|
27
|
+
compilerOptions && testOperator.mergeJestConfig({
|
|
28
|
+
globals: {
|
|
29
|
+
"ts-jest": {
|
|
30
|
+
tsconfig: compilerOptions
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export { patchTransformer };
|
|
@@ -1,14 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __commonJS = function(cb, mod) {
|
|
3
|
+
return function __require() {
|
|
4
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
|
|
5
|
+
exports: {}
|
|
6
|
+
}).exports, mod), mod.exports;
|
|
7
|
+
};
|
|
8
8
|
};
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
import enhanceResolve from "enhanced-resolve";
|
|
10
|
+
var require_resolver = __commonJS({
|
|
11
|
+
"src/base/config/resolver.ts": function(exports, module) {
|
|
12
|
+
var resolver = enhanceResolve.create.sync({
|
|
13
|
+
conditionNames: [
|
|
14
|
+
"require",
|
|
15
|
+
"node",
|
|
16
|
+
"default"
|
|
17
|
+
],
|
|
18
|
+
extensions: [
|
|
19
|
+
".js",
|
|
20
|
+
".json",
|
|
21
|
+
".node",
|
|
22
|
+
".ts",
|
|
23
|
+
".tsx"
|
|
24
|
+
]
|
|
25
|
+
});
|
|
26
|
+
var shouldResolveByEnhance = function(url) {
|
|
27
|
+
return /^@[^/]+\/[^/]+\/.*/.test(url);
|
|
28
|
+
};
|
|
29
|
+
module.exports = function(request, options) {
|
|
30
|
+
if (shouldResolveByEnhance(request)) {
|
|
31
|
+
return resolver(options.basedir, request);
|
|
32
|
+
}
|
|
33
|
+
return options.defaultResolver(request, options);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
export default require_resolver();
|
|
@@ -1,76 +1,127 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
|
-
import { merge } from '@modern-js/utils/lodash';
|
|
7
|
-
var TestConfigOperator = /*#__PURE__*/function () {
|
|
8
|
-
function TestConfigOperator(testConfig) {
|
|
9
|
-
_classCallCheck(this, TestConfigOperator);
|
|
10
|
-
_defineProperty(this, "_testConfig", void 0);
|
|
11
|
-
_defineProperty(this, "_jestConfig", void 0);
|
|
12
|
-
_defineProperty(this, "userJestConfig", void 0);
|
|
13
|
-
_defineProperty(this, "defaultTestConfig", {
|
|
14
|
-
transformer: 'babel-jest'
|
|
15
|
-
});
|
|
16
|
-
this._testConfig = testConfig;
|
|
17
|
-
this._jestConfig = {};
|
|
18
|
-
this.userJestConfig = testConfig.jest;
|
|
19
|
-
this.initial();
|
|
20
|
-
}
|
|
21
|
-
_createClass(TestConfigOperator, [{
|
|
22
|
-
key: "initial",
|
|
23
|
-
value: function initial() {
|
|
24
|
-
this._testConfig = merge({}, this.defaultTestConfig, this.testConfig);
|
|
1
|
+
function _classCallCheck(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
25
4
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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);
|
|
30
13
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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;
|
|
35
30
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
this.setJestConfig(userJestConfig);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}, {
|
|
50
|
-
key: "setJestConfig",
|
|
51
|
-
value: function setJestConfig(sourceConfig, options) {
|
|
52
|
-
if (options) {
|
|
53
|
-
var force = options.force;
|
|
54
|
-
if (force) {
|
|
55
|
-
this._jestConfig = sourceConfig;
|
|
56
|
-
return;
|
|
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
|
+
}));
|
|
57
41
|
}
|
|
58
|
-
|
|
59
|
-
|
|
42
|
+
ownKeys.forEach(function(key) {
|
|
43
|
+
_defineProperty(target, key, source[key]);
|
|
44
|
+
});
|
|
60
45
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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();
|
|
72
63
|
}
|
|
73
|
-
|
|
74
|
-
|
|
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;
|
|
75
126
|
}();
|
|
76
|
-
export { TestConfigOperator };
|
|
127
|
+
export { TestConfigOperator };
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
var
|
|
2
|
-
import babelJest from
|
|
3
|
-
var babelTransformer = (
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
10
15
|
});
|
|
11
|
-
|
|
16
|
+
var babelTransformer_default = babelTransformer;
|
|
17
|
+
export { babelTransformer_default as default };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { createAsyncPipeline, createParallelWorkflow } from
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
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,6 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export * from "./types";
|
|
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 };
|