@modern-js/plugin-testing 2.0.0-beta.0 → 2.0.0-beta.2
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 +109 -0
- package/dist/js/modern/base/config/index.js +1 -3
- package/dist/js/modern/base/config/patches/index.js +0 -2
- package/dist/js/modern/base/config/patches/transformer.js +1 -7
- package/dist/js/modern/base/config/resolver.js +0 -3
- package/dist/js/modern/base/config/testConfigOperator.js +0 -23
- package/dist/js/modern/base/config/transformer/babelTransformer.js +0 -1
- package/dist/js/modern/base/runJest.js +11 -14
- package/dist/js/modern/base/utils.js +2 -12
- package/dist/js/modern/cli/bff/app.js +0 -7
- package/dist/js/modern/cli/bff/index.js +4 -15
- package/dist/js/modern/cli/bff/mockAPI.js +4 -20
- package/dist/js/modern/cli/bff/setup.js +0 -5
- package/dist/js/modern/cli/bff/utils/index.js +0 -4
- package/dist/js/modern/cli/index.js +2 -9
- package/dist/js/modern/cli/test.js +0 -4
- package/dist/js/modern/runtime-testing/app.js +0 -15
- package/dist/js/modern/runtime-testing/customRender.js +0 -6
- package/dist/js/modern/runtime-testing/reduck.js +0 -10
- package/dist/js/modern/runtime-testing/request.js +1 -4
- package/dist/js/modern/runtime-testing/resolvePlugins.js +0 -6
- package/dist/js/node/base/config/index.js +0 -8
- package/dist/js/node/base/config/patches/assetsModule.js +0 -2
- package/dist/js/node/base/config/patches/index.js +0 -6
- package/dist/js/node/base/config/patches/transformer.js +1 -9
- package/dist/js/node/base/config/resolver.js +0 -5
- package/dist/js/node/base/config/testConfigOperator.js +0 -24
- package/dist/js/node/base/config/transformer/babelTransformer.js +0 -4
- package/dist/js/node/base/hook.js +0 -2
- package/dist/js/node/base/index.js +0 -7
- package/dist/js/node/base/runJest.js +11 -21
- package/dist/js/node/base/utils.js +2 -22
- package/dist/js/node/cli/bff/app.js +0 -14
- package/dist/js/node/cli/bff/index.js +4 -25
- package/dist/js/node/cli/bff/mockAPI.js +2 -25
- package/dist/js/node/cli/bff/setup.js +0 -11
- package/dist/js/node/cli/bff/utils/index.js +0 -9
- package/dist/js/node/cli/index.js +2 -21
- package/dist/js/node/cli/test.js +0 -10
- package/dist/js/node/index.js +0 -4
- package/dist/js/node/runtime-testing/app.js +0 -20
- package/dist/js/node/runtime-testing/base.js +0 -5
- package/dist/js/node/runtime-testing/customRender.js +0 -10
- package/dist/js/node/runtime-testing/index.js +0 -4
- package/dist/js/node/runtime-testing/reduck.js +0 -24
- package/dist/js/node/runtime-testing/request.js +1 -6
- package/dist/js/node/runtime-testing/resolvePlugins.js +0 -8
- package/dist/js/treeshaking/base/config/index.js +1 -6
- package/dist/js/treeshaking/base/config/patches/index.js +0 -17
- package/dist/js/treeshaking/base/config/patches/transformer.js +1 -7
- package/dist/js/treeshaking/base/config/resolver.js +0 -3
- package/dist/js/treeshaking/base/config/testConfigOperator.js +0 -15
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +0 -1
- package/dist/js/treeshaking/base/runJest.js +19 -38
- package/dist/js/treeshaking/base/utils.js +2 -10
- package/dist/js/treeshaking/cli/bff/app.js +0 -13
- package/dist/js/treeshaking/cli/bff/index.js +0 -16
- package/dist/js/treeshaking/cli/bff/mockAPI.js +8 -24
- package/dist/js/treeshaking/cli/bff/setup.js +0 -9
- package/dist/js/treeshaking/cli/bff/utils/index.js +1 -2
- package/dist/js/treeshaking/cli/index.js +2 -11
- package/dist/js/treeshaking/cli/test.js +0 -7
- package/dist/js/treeshaking/runtime-testing/app.js +2 -15
- package/dist/js/treeshaking/runtime-testing/customRender.js +0 -3
- package/dist/js/treeshaking/runtime-testing/reduck.js +0 -7
- package/dist/js/treeshaking/runtime-testing/request.js +2 -7
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +0 -3
- package/dist/types/base/config/index.d.ts +10 -1
- package/dist/types/base/config/patches/assetsModule.d.ts +0 -1
- package/dist/types/base/config/patches/filemock.d.ts +0 -1
- package/dist/types/base/config/patches/transformer.d.ts +0 -1
- package/dist/types/base/config/testConfigOperator.d.ts +1 -117
- package/dist/types/base/hook.d.ts +4 -6
- package/dist/types/base/runJest.d.ts +7 -3
- package/dist/types/base/utils.d.ts +0 -1
- package/dist/types/cli/bff/index.d.ts +7 -3
- package/dist/types/cli/bff/mockAPI.d.ts +0 -1
- package/dist/types/cli/index.d.ts +7 -3
- package/dist/types/cli/test.d.ts +7 -1
- package/dist/types/runtime-testing/app.d.ts +12 -5
- package/dist/types/runtime-testing/customRender.d.ts +0 -2
- package/dist/types/runtime-testing/resolvePlugins.d.ts +5 -1
- package/package.json +18 -18
|
@@ -10,7 +10,6 @@ import { isBFFProject } from "./utils";
|
|
|
10
10
|
export var setJestConfigForBFF = /*#__PURE__*/function () {
|
|
11
11
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
12
12
|
var _userConfig$source;
|
|
13
|
-
|
|
14
13
|
var pwd, userConfig, plugins, routes, utils, bffConfig, jestConfig, alias, aliasMapper, moduleNameMapper, transform, apiOnly, mergedModuleNameMapper, resolver, configFields, commonConfig;
|
|
15
14
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
16
15
|
while (1) {
|
|
@@ -39,27 +38,22 @@ export var setJestConfigForBFF = /*#__PURE__*/function () {
|
|
|
39
38
|
alias = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.alias) || {};
|
|
40
39
|
aliasMapper = getModuleNameMapper(alias);
|
|
41
40
|
moduleNameMapper = jestConfig.moduleNameMapper; // 服务端统一使用 ts-jest
|
|
42
|
-
|
|
43
41
|
transform = {
|
|
44
42
|
'\\.[jt]sx?$': require.resolve('ts-jest')
|
|
45
43
|
};
|
|
46
44
|
_context.next = 9;
|
|
47
45
|
return isApiOnly(pwd);
|
|
48
|
-
|
|
49
46
|
case 9:
|
|
50
47
|
apiOnly = _context.sent;
|
|
51
48
|
mergedModuleNameMapper = _objectSpread(_objectSpread({}, moduleNameMapper), aliasMapper);
|
|
52
49
|
resolver = jestConfig.resolver || DEFAULT_RESOLVER_PATH; // 这三个配置不能设置在 projects 中,需要设置在外层(https://github.com/facebook/jest/issues/9696)
|
|
53
|
-
|
|
54
50
|
configFields = ['coverage', 'collectCoverage', 'testTimeout'];
|
|
55
51
|
commonConfig = configFields.reduce(function (obj, field) {
|
|
56
52
|
if (jestConfig.hasOwnProperty(field)) {
|
|
57
53
|
obj[field] = jestConfig[field];
|
|
58
54
|
}
|
|
59
|
-
|
|
60
55
|
return obj;
|
|
61
56
|
}, {});
|
|
62
|
-
|
|
63
57
|
if (!apiOnly) {
|
|
64
58
|
utils.setJestConfig({
|
|
65
59
|
projects: [_objectSpread({}, jestConfig), _objectSpread({
|
|
@@ -81,9 +75,7 @@ export var setJestConfigForBFF = /*#__PURE__*/function () {
|
|
|
81
75
|
force: true
|
|
82
76
|
});
|
|
83
77
|
}
|
|
84
|
-
|
|
85
78
|
utils.setJestConfig(commonConfig);
|
|
86
|
-
|
|
87
79
|
case 16:
|
|
88
80
|
case "end":
|
|
89
81
|
return _context.stop();
|
|
@@ -91,7 +83,6 @@ export var setJestConfigForBFF = /*#__PURE__*/function () {
|
|
|
91
83
|
}
|
|
92
84
|
}, _callee);
|
|
93
85
|
}));
|
|
94
|
-
|
|
95
86
|
return function setJestConfigForBFF(_x) {
|
|
96
87
|
return _ref2.apply(this, arguments);
|
|
97
88
|
};
|
|
@@ -110,14 +101,11 @@ export default (function () {
|
|
|
110
101
|
case 0:
|
|
111
102
|
appContext = api.useAppContext();
|
|
112
103
|
pwd = appContext.appDirectory;
|
|
113
|
-
|
|
114
104
|
if (isBFFProject(pwd)) {
|
|
115
105
|
_context2.next = 4;
|
|
116
106
|
break;
|
|
117
107
|
}
|
|
118
|
-
|
|
119
108
|
return _context2.abrupt("return", next(utils));
|
|
120
|
-
|
|
121
109
|
case 4:
|
|
122
110
|
userConfig = api.useResolvedConfigContext();
|
|
123
111
|
_context2.next = 7;
|
|
@@ -128,10 +116,8 @@ export default (function () {
|
|
|
128
116
|
plugins: appContext.serverInternalPlugins,
|
|
129
117
|
utils: utils
|
|
130
118
|
});
|
|
131
|
-
|
|
132
119
|
case 7:
|
|
133
120
|
return _context2.abrupt("return", next(utils));
|
|
134
|
-
|
|
135
121
|
case 8:
|
|
136
122
|
case "end":
|
|
137
123
|
return _context2.stop();
|
|
@@ -139,11 +125,9 @@ export default (function () {
|
|
|
139
125
|
}
|
|
140
126
|
}, _callee2);
|
|
141
127
|
}));
|
|
142
|
-
|
|
143
128
|
function jestConfig(_x2, _x3) {
|
|
144
129
|
return _jestConfig.apply(this, arguments);
|
|
145
130
|
}
|
|
146
|
-
|
|
147
131
|
return jestConfig;
|
|
148
132
|
}()
|
|
149
133
|
};
|
|
@@ -3,8 +3,9 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
3
3
|
import _typeof from "@babel/runtime/helpers/esm/typeof";
|
|
4
4
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
5
5
|
import * as ptr from 'path-to-regexp';
|
|
6
|
-
import * as mockAppModule from "./app";
|
|
6
|
+
import * as mockAppModule from "./app";
|
|
7
7
|
|
|
8
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
9
|
var mock_replaceUrlWithParams = function mock_replaceUrlWithParams(url, paramValues, payload) {
|
|
9
10
|
var keys = [];
|
|
10
11
|
ptr.pathToRegexp(url, keys);
|
|
@@ -12,28 +13,24 @@ var mock_replaceUrlWithParams = function mock_replaceUrlWithParams(url, paramVal
|
|
|
12
13
|
if (paramValues[index]) {
|
|
13
14
|
cur[key.name] = paramValues[index];
|
|
14
15
|
}
|
|
15
|
-
|
|
16
16
|
return cur;
|
|
17
17
|
}, {});
|
|
18
18
|
var getFinalPath = ptr.compile(url, {
|
|
19
19
|
encode: encodeURIComponent
|
|
20
20
|
});
|
|
21
21
|
return getFinalPath(_objectSpread(_objectSpread({}, params), payload));
|
|
22
|
-
};
|
|
23
|
-
|
|
22
|
+
};
|
|
24
23
|
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
25
25
|
var mock_getParamsAndPayload = function mock_getParamsAndPayload(args) {
|
|
26
26
|
if (args.length === 0) {
|
|
27
27
|
return [[], {}];
|
|
28
28
|
}
|
|
29
|
-
|
|
30
29
|
var head = args[0];
|
|
31
|
-
|
|
32
30
|
if (_typeof(head) === 'object') {
|
|
33
31
|
return [[], head];
|
|
34
32
|
} else {
|
|
35
33
|
var latest = args[args.length - 1];
|
|
36
|
-
|
|
37
34
|
if (_typeof(latest) === 'object') {
|
|
38
35
|
return [args.slice(0, args.length - 1), latest];
|
|
39
36
|
} else {
|
|
@@ -41,60 +38,48 @@ var mock_getParamsAndPayload = function mock_getParamsAndPayload(args) {
|
|
|
41
38
|
}
|
|
42
39
|
}
|
|
43
40
|
};
|
|
44
|
-
|
|
45
41
|
export default (function (mockApiInfosByFile) {
|
|
46
42
|
var files = Object.keys(mockApiInfosByFile);
|
|
47
43
|
files.forEach(function (mockedFile) {
|
|
48
44
|
jest.mock(mockedFile, function () {
|
|
49
45
|
var supertest = require('supertest');
|
|
50
|
-
|
|
51
46
|
return mockApiInfosByFile[mockedFile].reduce(function (res, info) {
|
|
52
47
|
var module = _defineProperty({}, info.name, function () {
|
|
53
48
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
54
49
|
args[_key] = arguments[_key];
|
|
55
50
|
}
|
|
56
|
-
|
|
57
51
|
if (mockAppModule.isInHandler()) {
|
|
58
52
|
return info.handler.apply(info, args);
|
|
59
53
|
}
|
|
60
|
-
|
|
61
54
|
var _mock_getParamsAndPay = mock_getParamsAndPayload(args),
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
55
|
+
_mock_getParamsAndPay2 = _slicedToArray(_mock_getParamsAndPay, 2),
|
|
56
|
+
params = _mock_getParamsAndPay2[0],
|
|
57
|
+
payload = _mock_getParamsAndPay2[1];
|
|
66
58
|
var _ref = module[info.name],
|
|
67
|
-
|
|
59
|
+
returnHttp = _ref.returnHttp;
|
|
68
60
|
var url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
|
|
69
61
|
var app = mockAppModule.getApp();
|
|
70
62
|
var test = supertest(app)[info.httpMethod.toLowerCase()](url);
|
|
71
|
-
|
|
72
63
|
if (payload.query) {
|
|
73
64
|
test = test.query(payload.query);
|
|
74
65
|
}
|
|
75
|
-
|
|
76
66
|
if (payload.body) {
|
|
77
67
|
test = test.send(payload.body);
|
|
78
68
|
}
|
|
79
|
-
|
|
80
69
|
if (payload.data) {
|
|
81
70
|
test = test.send(payload.data);
|
|
82
71
|
}
|
|
83
|
-
|
|
84
72
|
if (payload.headers) {
|
|
85
73
|
for (var name in payload.headers) {
|
|
86
74
|
test = test.set(name, payload.headers[name]);
|
|
87
75
|
}
|
|
88
76
|
}
|
|
89
|
-
|
|
90
77
|
if (payload.cookies) {
|
|
91
78
|
test = test.set('Cookie', [payload.cookies]);
|
|
92
79
|
}
|
|
93
|
-
|
|
94
80
|
if (returnHttp) {
|
|
95
81
|
return test;
|
|
96
82
|
}
|
|
97
|
-
|
|
98
83
|
return test.then(function (value) {
|
|
99
84
|
try {
|
|
100
85
|
return JSON.parse(value.text);
|
|
@@ -103,7 +88,6 @@ export default (function (mockApiInfosByFile) {
|
|
|
103
88
|
}
|
|
104
89
|
});
|
|
105
90
|
});
|
|
106
|
-
|
|
107
91
|
res[info.name] = module[info.name];
|
|
108
92
|
Object.assign(res[info.name], info.handler);
|
|
109
93
|
res.__esModule = true;
|
|
@@ -6,14 +6,11 @@ import { bff_info_key } from "./constant";
|
|
|
6
6
|
import mockAPI from "./mockAPI";
|
|
7
7
|
import { createApp, closeServer } from "./app";
|
|
8
8
|
var uped = false;
|
|
9
|
-
|
|
10
9
|
var setup = function setup() {
|
|
11
10
|
var _bff_info$modernUserC, _bff_info$modernUserC2;
|
|
12
|
-
|
|
13
11
|
if (uped) {
|
|
14
12
|
return;
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
uped = true;
|
|
18
15
|
var bff_info = global[bff_info_key];
|
|
19
16
|
var prefix = bff_info === null || bff_info === void 0 ? void 0 : (_bff_info$modernUserC = bff_info.modernUserConfig) === null || _bff_info$modernUserC === void 0 ? void 0 : (_bff_info$modernUserC2 = _bff_info$modernUserC.bff) === null || _bff_info$modernUserC2 === void 0 ? void 0 : _bff_info$modernUserC2.prefix;
|
|
@@ -26,7 +23,6 @@ var setup = function setup() {
|
|
|
26
23
|
if (!res[apiInfo.filename]) {
|
|
27
24
|
res[apiInfo.filename] = [];
|
|
28
25
|
}
|
|
29
|
-
|
|
30
26
|
res[apiInfo.filename].push(apiInfo);
|
|
31
27
|
return res;
|
|
32
28
|
}, {});
|
|
@@ -40,13 +36,10 @@ var setup = function setup() {
|
|
|
40
36
|
_context.next = 4;
|
|
41
37
|
break;
|
|
42
38
|
}
|
|
43
|
-
|
|
44
39
|
_context.next = 3;
|
|
45
40
|
return createApp(bff_info.appDir, bff_info.modernUserConfig, bff_info.plugins, bff_info.routes);
|
|
46
|
-
|
|
47
41
|
case 3:
|
|
48
42
|
app = _context.sent;
|
|
49
|
-
|
|
50
43
|
case 4:
|
|
51
44
|
case "end":
|
|
52
45
|
return _context.stop();
|
|
@@ -61,7 +54,6 @@ var setup = function setup() {
|
|
|
61
54
|
case 0:
|
|
62
55
|
_context2.next = 2;
|
|
63
56
|
return closeServer();
|
|
64
|
-
|
|
65
57
|
case 2:
|
|
66
58
|
case "end":
|
|
67
59
|
return _context2.stop();
|
|
@@ -71,5 +63,4 @@ var setup = function setup() {
|
|
|
71
63
|
})));
|
|
72
64
|
mockAPI(apiInfosByFile);
|
|
73
65
|
};
|
|
74
|
-
|
|
75
66
|
setup();
|
|
@@ -4,9 +4,8 @@ import { chalk } from '@modern-js/utils';
|
|
|
4
4
|
export var isBFFProject = function isBFFProject(pwd) {
|
|
5
5
|
try {
|
|
6
6
|
var packageJson = require(path.join(pwd, './package.json'));
|
|
7
|
-
|
|
8
7
|
var dependencies = packageJson.dependencies,
|
|
9
|
-
|
|
8
|
+
devDependencies = packageJson.devDependencies;
|
|
10
9
|
var isBFF = Object.keys(_objectSpread(_objectSpread({}, dependencies), devDependencies)).some(function (dependency) {
|
|
11
10
|
return dependency.includes('plugin-bff');
|
|
12
11
|
});
|
|
@@ -8,8 +8,9 @@ import { MODERNJS_CONFIG_KEY } from "../constant";
|
|
|
8
8
|
import TestingBffPlugin from "./bff";
|
|
9
9
|
import test from "./test";
|
|
10
10
|
export var mergeUserJestConfig = function mergeUserJestConfig(testUtils) {
|
|
11
|
-
var resolveJestConfig = testUtils.testConfig.jest;
|
|
11
|
+
var resolveJestConfig = testUtils.testConfig.jest;
|
|
12
12
|
|
|
13
|
+
// resolveJestConfig 如果是函数类型,在所有测试插件 jestConfig 都执行后,再执行生成最终配置
|
|
13
14
|
if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
|
|
14
15
|
testUtils.mergeJestConfig(resolveJestConfig);
|
|
15
16
|
}
|
|
@@ -33,7 +34,6 @@ export default (function () {
|
|
|
33
34
|
case 0:
|
|
34
35
|
_context.next = 2;
|
|
35
36
|
return test(api);
|
|
36
|
-
|
|
37
37
|
case 2:
|
|
38
38
|
case "end":
|
|
39
39
|
return _context.stop();
|
|
@@ -71,24 +71,18 @@ export default (function () {
|
|
|
71
71
|
userConfig = api.useResolvedConfigContext();
|
|
72
72
|
_context2.next = 4;
|
|
73
73
|
return isApiOnly(appContext.appDirectory);
|
|
74
|
-
|
|
75
74
|
case 4:
|
|
76
75
|
apiOnly = _context2.sent;
|
|
77
|
-
|
|
78
76
|
if (!apiOnly) {
|
|
79
77
|
_context2.next = 7;
|
|
80
78
|
break;
|
|
81
79
|
}
|
|
82
|
-
|
|
83
80
|
return _context2.abrupt("return", next(utils));
|
|
84
|
-
|
|
85
81
|
case 7:
|
|
86
82
|
alias = mergeAlias(userConfig.source.alias);
|
|
87
|
-
|
|
88
83
|
if (testingExportsUtils) {
|
|
89
84
|
alias['@modern-js/runtime/testing'] = [testingExportsUtils.getPath()];
|
|
90
85
|
}
|
|
91
|
-
|
|
92
86
|
utils.mergeJestConfig({
|
|
93
87
|
globals: _defineProperty({}, MODERNJS_CONFIG_KEY, userConfig),
|
|
94
88
|
moduleNameMapper: getModuleNameMapper(alias),
|
|
@@ -102,7 +96,6 @@ export default (function () {
|
|
|
102
96
|
});
|
|
103
97
|
mergeUserJestConfig(utils);
|
|
104
98
|
return _context2.abrupt("return", next(utils));
|
|
105
|
-
|
|
106
99
|
case 12:
|
|
107
100
|
case "end":
|
|
108
101
|
return _context2.stop();
|
|
@@ -110,11 +103,9 @@ export default (function () {
|
|
|
110
103
|
}
|
|
111
104
|
}, _callee2);
|
|
112
105
|
}));
|
|
113
|
-
|
|
114
106
|
function jestConfig(_x, _x2) {
|
|
115
107
|
return _jestConfig.apply(this, arguments);
|
|
116
108
|
}
|
|
117
|
-
|
|
118
109
|
return jestConfig;
|
|
119
110
|
}()
|
|
120
111
|
};
|
|
@@ -3,7 +3,6 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
|
3
3
|
import path from 'path';
|
|
4
4
|
import { compiler } from '@modern-js/babel-compiler';
|
|
5
5
|
import { runTest } from "../base";
|
|
6
|
-
|
|
7
6
|
var test = /*#__PURE__*/function () {
|
|
8
7
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api) {
|
|
9
8
|
var userConfig, appContext, jest, runtimeExportsPath;
|
|
@@ -15,11 +14,9 @@ var test = /*#__PURE__*/function () {
|
|
|
15
14
|
appContext = api.useAppContext();
|
|
16
15
|
userConfig.testing = userConfig.testing || {};
|
|
17
16
|
jest = userConfig.testing.jest || userConfig.tools.jest;
|
|
18
|
-
|
|
19
17
|
if (Array.isArray(jest)) {
|
|
20
18
|
userConfig.testing.jest = jest[0];
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
userConfig.testing.jest = userConfig.testing.jest || userConfig.tools.jest;
|
|
24
21
|
runtimeExportsPath = path.join(appContext.internalDirectory, '.runtime-exports');
|
|
25
22
|
_context.next = 9;
|
|
@@ -33,11 +30,9 @@ var test = /*#__PURE__*/function () {
|
|
|
33
30
|
modules: 'cjs'
|
|
34
31
|
}]]
|
|
35
32
|
});
|
|
36
|
-
|
|
37
33
|
case 9:
|
|
38
34
|
_context.next = 11;
|
|
39
35
|
return runTest(api, userConfig.testing);
|
|
40
|
-
|
|
41
36
|
case 11:
|
|
42
37
|
case "end":
|
|
43
38
|
return _context.stop();
|
|
@@ -45,10 +40,8 @@ var test = /*#__PURE__*/function () {
|
|
|
45
40
|
}
|
|
46
41
|
}, _callee);
|
|
47
42
|
}));
|
|
48
|
-
|
|
49
43
|
return function test(_x) {
|
|
50
44
|
return _ref.apply(this, arguments);
|
|
51
45
|
};
|
|
52
46
|
}();
|
|
53
|
-
|
|
54
47
|
export default test;
|
|
@@ -5,16 +5,12 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
5
5
|
import { createApp as _createApp } from '@modern-js/runtime';
|
|
6
6
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
|
7
7
|
import resolvePlugins from "./resolvePlugins";
|
|
8
|
-
|
|
9
8
|
var ModernRuntime = /*#__PURE__*/function () {
|
|
10
9
|
function ModernRuntime(options) {
|
|
11
10
|
_classCallCheck(this, ModernRuntime);
|
|
12
|
-
|
|
13
11
|
_defineProperty(this, "options", void 0);
|
|
14
|
-
|
|
15
12
|
this.options = options;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
_createClass(ModernRuntime, [{
|
|
19
15
|
key: "init",
|
|
20
16
|
value: function init(options) {
|
|
@@ -24,34 +20,25 @@ var ModernRuntime = /*#__PURE__*/function () {
|
|
|
24
20
|
key: "createApp",
|
|
25
21
|
value: function createApp(props) {
|
|
26
22
|
var _this$options;
|
|
27
|
-
|
|
28
23
|
var _ref = props || {},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
entry = _ref.entry,
|
|
25
|
+
children = _ref.children;
|
|
32
26
|
var runtimeFeatures = (_this$options = this.options) === null || _this$options === void 0 ? void 0 : _this$options.runtime;
|
|
33
|
-
|
|
34
27
|
if (entry) {
|
|
35
28
|
var _this$options$runtime;
|
|
36
|
-
|
|
37
29
|
runtimeFeatures = _objectSpread(_objectSpread({}, runtimeFeatures || {}), (_this$options$runtime = this.options.runtimeByEntries) === null || _this$options$runtime === void 0 ? void 0 : _this$options$runtime[entry]);
|
|
38
30
|
}
|
|
39
|
-
|
|
40
31
|
var Component = function Component() {
|
|
41
32
|
if (!children) {
|
|
42
33
|
return null;
|
|
43
34
|
}
|
|
44
|
-
|
|
45
35
|
return children;
|
|
46
36
|
};
|
|
47
|
-
|
|
48
37
|
return _createApp({
|
|
49
38
|
plugins: resolvePlugins(runtimeFeatures || {})
|
|
50
39
|
})(Component);
|
|
51
40
|
}
|
|
52
41
|
}]);
|
|
53
|
-
|
|
54
42
|
return ModernRuntime;
|
|
55
43
|
}();
|
|
56
|
-
|
|
57
44
|
export default new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
|
|
@@ -2,15 +2,12 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { render } from '@testing-library/react';
|
|
4
4
|
import app from "./app";
|
|
5
|
-
|
|
6
5
|
var WrapModernProviders = function WrapModernProviders(props) {
|
|
7
6
|
return /*#__PURE__*/React.createElement(app.createApp(props));
|
|
8
7
|
};
|
|
9
|
-
|
|
10
8
|
var customRender = function customRender(ui, options) {
|
|
11
9
|
return render(ui, _objectSpread({
|
|
12
10
|
wrapper: WrapModernProviders
|
|
13
11
|
}, options));
|
|
14
12
|
};
|
|
15
|
-
|
|
16
13
|
export default customRender;
|
|
@@ -16,29 +16,22 @@ export var autoActions = function autoActions() {
|
|
|
16
16
|
export var createStore = function createStore(props) {
|
|
17
17
|
var createStatePlugins = function createStatePlugins() {
|
|
18
18
|
var _modernConfig$runtime;
|
|
19
|
-
|
|
20
19
|
var modernConfig = global[MODERNJS_CONFIG_KEY];
|
|
21
20
|
var stateConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (_modernConfig$runtime = modernConfig.runtime) === null || _modernConfig$runtime === void 0 ? void 0 : _modernConfig$runtime.state;
|
|
22
21
|
var plugins = [];
|
|
23
|
-
|
|
24
22
|
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.effects) !== false) {
|
|
25
23
|
plugins.push(effects());
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.autoActions) !== false) {
|
|
29
26
|
plugins.push(autoActions());
|
|
30
27
|
}
|
|
31
|
-
|
|
32
28
|
if ((stateConfig === null || stateConfig === void 0 ? void 0 : stateConfig.immer) !== false) {
|
|
33
29
|
plugins.push(immer());
|
|
34
30
|
}
|
|
35
|
-
|
|
36
31
|
return ((props === null || props === void 0 ? void 0 : props.plugins) || []).concat(plugins);
|
|
37
32
|
};
|
|
38
|
-
|
|
39
33
|
var config = _objectSpread(_objectSpread({}, props || {}), {}, {
|
|
40
34
|
plugins: createStatePlugins()
|
|
41
35
|
});
|
|
42
|
-
|
|
43
36
|
return originCreateStore(config);
|
|
44
37
|
};
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
|
-
|
|
3
2
|
/* eslint-disable eslint-comments/disable-enable-pair */
|
|
3
|
+
|
|
4
4
|
import supertest from 'supertest';
|
|
5
5
|
import { getApp } from "../cli/bff/app";
|
|
6
|
-
|
|
7
6
|
function request() {
|
|
8
7
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
9
8
|
args[_key] = arguments[_key];
|
|
10
9
|
}
|
|
11
|
-
|
|
12
10
|
var fn = args[0],
|
|
13
|
-
|
|
11
|
+
extraArgs = args.slice(1);
|
|
14
12
|
var app = getApp();
|
|
15
|
-
|
|
16
13
|
if (!fn) {
|
|
17
14
|
return supertest(app);
|
|
18
15
|
}
|
|
19
|
-
|
|
20
16
|
fn.returnHttp = true;
|
|
21
17
|
var res = fn.apply(void 0, _toConsumableArray(extraArgs));
|
|
22
18
|
fn.returnHttp = false;
|
|
23
19
|
return res;
|
|
24
20
|
}
|
|
25
|
-
|
|
26
21
|
export { request };
|
|
@@ -2,15 +2,12 @@ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
|
2
2
|
var allowedFeatures = ['router', 'state'];
|
|
3
3
|
export default function resolvePlugins(features) {
|
|
4
4
|
var plugins = [];
|
|
5
|
-
|
|
6
5
|
if (!features) {
|
|
7
6
|
return plugins;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
Object.keys(features).forEach(function (feature) {
|
|
11
9
|
if (allowedFeatures.includes(feature)) {
|
|
12
10
|
var curPluginRes = require("@modern-js/runtime/plugins")[feature](_objectSpread({}, features[feature]));
|
|
13
|
-
|
|
14
11
|
plugins.push(curPluginRes);
|
|
15
12
|
}
|
|
16
13
|
});
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { AliasOption } from '@modern-js/utils';
|
|
2
|
+
import { JestConfig } from '@modern-js/core';
|
|
1
3
|
import { TestConfig } from '../types';
|
|
2
4
|
import { TestConfigOperator } from './testConfigOperator';
|
|
3
5
|
/**
|
|
4
6
|
* Parse jest config
|
|
5
7
|
*/
|
|
6
|
-
|
|
7
8
|
declare const getJestUtils: (testConfig: TestConfig) => TestConfigOperator;
|
|
8
9
|
declare const patchConfig: (testOperator: TestConfigOperator) => Promise<Partial<{
|
|
9
10
|
automock: boolean;
|
|
@@ -121,4 +122,12 @@ declare const patchConfig: (testOperator: TestConfigOperator) => Promise<Partial
|
|
|
121
122
|
watchPlugins: (string | [string, Record<string, unknown>])[];
|
|
122
123
|
}>>;
|
|
123
124
|
export declare const DEFAULT_RESOLVER_PATH: string;
|
|
125
|
+
export declare type UserConfig = {
|
|
126
|
+
source?: {
|
|
127
|
+
alias?: AliasOption;
|
|
128
|
+
};
|
|
129
|
+
tools?: {
|
|
130
|
+
jest: JestConfig | ((config: JestConfig) => JestConfig);
|
|
131
|
+
};
|
|
132
|
+
};
|
|
124
133
|
export { getJestUtils, patchConfig };
|