@modern-js/plugin-testing 1.21.5 → 2.0.0-beta.1
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 +88 -29
- 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 +1 -8
- package/dist/js/modern/cli/bff/index.js +5 -17
- 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 +7 -15
- 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 +1 -15
- package/dist/js/node/cli/bff/index.js +5 -27
- 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 +6 -27
- 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 +1 -14
- package/dist/js/treeshaking/cli/bff/index.js +5 -24
- 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 +8 -15
- 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 +0 -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 +0 -2
- package/dist/types/base/runJest.d.ts +0 -2
- package/dist/types/base/utils.d.ts +0 -1
- package/dist/types/cli/bff/app.d.ts +2 -1
- package/dist/types/cli/bff/index.d.ts +2 -3
- package/dist/types/cli/bff/mockAPI.d.ts +0 -1
- package/dist/types/cli/index.d.ts +0 -2
- package/dist/types/runtime-testing/app.d.ts +0 -3
- package/dist/types/runtime-testing/customRender.d.ts +0 -2
- package/package.json +18 -41
|
@@ -7,7 +7,6 @@ export var isInHandler = function isInHandler() {
|
|
|
7
7
|
return Boolean(store.getStore());
|
|
8
8
|
};
|
|
9
9
|
var server = null;
|
|
10
|
-
|
|
11
10
|
var createApp = /*#__PURE__*/function () {
|
|
12
11
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(pwd, config, plugins, routes) {
|
|
13
12
|
var app;
|
|
@@ -19,22 +18,19 @@ var createApp = /*#__PURE__*/function () {
|
|
|
19
18
|
_context.next = 5;
|
|
20
19
|
break;
|
|
21
20
|
}
|
|
22
|
-
|
|
23
21
|
config.output.path = './';
|
|
24
22
|
server = new Server({
|
|
25
23
|
apiOnly: true,
|
|
26
24
|
pwd: pwd,
|
|
27
25
|
config: config,
|
|
28
|
-
|
|
26
|
+
internalPlugins: plugins,
|
|
29
27
|
routes: routes
|
|
30
28
|
});
|
|
31
29
|
_context.next = 5;
|
|
32
30
|
return server.init();
|
|
33
|
-
|
|
34
31
|
case 5:
|
|
35
32
|
app = server.getRequestHandler();
|
|
36
33
|
return _context.abrupt("return", app);
|
|
37
|
-
|
|
38
34
|
case 7:
|
|
39
35
|
case "end":
|
|
40
36
|
return _context.stop();
|
|
@@ -42,20 +38,16 @@ var createApp = /*#__PURE__*/function () {
|
|
|
42
38
|
}
|
|
43
39
|
}, _callee);
|
|
44
40
|
}));
|
|
45
|
-
|
|
46
41
|
return function createApp(_x, _x2, _x3, _x4) {
|
|
47
42
|
return _ref.apply(this, arguments);
|
|
48
43
|
};
|
|
49
44
|
}();
|
|
50
|
-
|
|
51
45
|
var getApp = function getApp() {
|
|
52
46
|
if (!server) {
|
|
53
47
|
throw new Error('please createApp first');
|
|
54
48
|
}
|
|
55
|
-
|
|
56
49
|
return server.getRequestHandler();
|
|
57
50
|
};
|
|
58
|
-
|
|
59
51
|
var closeServer = /*#__PURE__*/function () {
|
|
60
52
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
61
53
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
@@ -66,13 +58,10 @@ var closeServer = /*#__PURE__*/function () {
|
|
|
66
58
|
_context2.next = 2;
|
|
67
59
|
break;
|
|
68
60
|
}
|
|
69
|
-
|
|
70
61
|
throw new Error('please createApp first');
|
|
71
|
-
|
|
72
62
|
case 2:
|
|
73
63
|
_context2.next = 4;
|
|
74
64
|
return server.close();
|
|
75
|
-
|
|
76
65
|
case 4:
|
|
77
66
|
case "end":
|
|
78
67
|
return _context2.stop();
|
|
@@ -80,10 +69,8 @@ var closeServer = /*#__PURE__*/function () {
|
|
|
80
69
|
}
|
|
81
70
|
}, _callee2);
|
|
82
71
|
}));
|
|
83
|
-
|
|
84
72
|
return function closeServer() {
|
|
85
73
|
return _ref2.apply(this, arguments);
|
|
86
74
|
};
|
|
87
75
|
}();
|
|
88
|
-
|
|
89
76
|
export { createApp, getApp, closeServer };
|
|
@@ -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
|
};
|
|
@@ -103,50 +94,40 @@ export default (function () {
|
|
|
103
94
|
return {
|
|
104
95
|
jestConfig: function () {
|
|
105
96
|
var _jestConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(utils, next) {
|
|
106
|
-
var appContext, pwd, userConfig
|
|
97
|
+
var appContext, pwd, userConfig;
|
|
107
98
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
108
99
|
while (1) {
|
|
109
100
|
switch (_context2.prev = _context2.next) {
|
|
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
|
-
|
|
124
|
-
return p.server;
|
|
125
|
-
}).filter(Boolean);
|
|
126
|
-
_context2.next = 8;
|
|
111
|
+
_context2.next = 7;
|
|
127
112
|
return setJestConfigForBFF({
|
|
128
113
|
pwd: pwd,
|
|
129
114
|
userConfig: userConfig,
|
|
130
|
-
plugins: plugins,
|
|
131
115
|
routes: appContext.serverRoutes,
|
|
116
|
+
plugins: appContext.serverInternalPlugins,
|
|
132
117
|
utils: utils
|
|
133
118
|
});
|
|
134
|
-
|
|
135
|
-
case 8:
|
|
119
|
+
case 7:
|
|
136
120
|
return _context2.abrupt("return", next(utils));
|
|
137
|
-
|
|
138
|
-
case 9:
|
|
121
|
+
case 8:
|
|
139
122
|
case "end":
|
|
140
123
|
return _context2.stop();
|
|
141
124
|
}
|
|
142
125
|
}
|
|
143
126
|
}, _callee2);
|
|
144
127
|
}));
|
|
145
|
-
|
|
146
128
|
function jestConfig(_x2, _x3) {
|
|
147
129
|
return _jestConfig.apply(this, arguments);
|
|
148
130
|
}
|
|
149
|
-
|
|
150
131
|
return jestConfig;
|
|
151
132
|
}()
|
|
152
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
|
});
|
|
@@ -2,15 +2,15 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
3
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
4
|
import path from 'path';
|
|
5
|
-
import { PLUGIN_SCHEMAS, createRuntimeExportsUtils
|
|
6
|
-
import { getWebpackConfig, WebpackConfigTarget } from '@modern-js/webpack';
|
|
5
|
+
import { isApiOnly, mergeAlias, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from '@modern-js/utils';
|
|
7
6
|
import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../base";
|
|
8
7
|
import { MODERNJS_CONFIG_KEY } from "../constant";
|
|
9
8
|
import TestingBffPlugin from "./bff";
|
|
10
9
|
import test from "./test";
|
|
11
10
|
export var mergeUserJestConfig = function mergeUserJestConfig(testUtils) {
|
|
12
|
-
var resolveJestConfig = testUtils.testConfig.jest;
|
|
11
|
+
var resolveJestConfig = testUtils.testConfig.jest;
|
|
13
12
|
|
|
13
|
+
// resolveJestConfig 如果是函数类型,在所有测试插件 jestConfig 都执行后,再执行生成最终配置
|
|
14
14
|
if (resolveJestConfig && typeof resolveJestConfig !== 'function') {
|
|
15
15
|
testUtils.mergeJestConfig(resolveJestConfig);
|
|
16
16
|
}
|
|
@@ -34,7 +34,6 @@ export default (function () {
|
|
|
34
34
|
case 0:
|
|
35
35
|
_context.next = 2;
|
|
36
36
|
return test(api);
|
|
37
|
-
|
|
38
37
|
case 2:
|
|
39
38
|
case "end":
|
|
40
39
|
return _context.stop();
|
|
@@ -63,8 +62,7 @@ export default (function () {
|
|
|
63
62
|
},
|
|
64
63
|
jestConfig: function () {
|
|
65
64
|
var _jestConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(utils, next) {
|
|
66
|
-
var appContext, userConfig, apiOnly,
|
|
67
|
-
|
|
65
|
+
var appContext, userConfig, apiOnly, alias;
|
|
68
66
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
69
67
|
while (1) {
|
|
70
68
|
switch (_context2.prev = _context2.next) {
|
|
@@ -73,20 +71,18 @@ export default (function () {
|
|
|
73
71
|
userConfig = api.useResolvedConfigContext();
|
|
74
72
|
_context2.next = 4;
|
|
75
73
|
return isApiOnly(appContext.appDirectory);
|
|
76
|
-
|
|
77
74
|
case 4:
|
|
78
75
|
apiOnly = _context2.sent;
|
|
79
|
-
|
|
80
76
|
if (!apiOnly) {
|
|
81
77
|
_context2.next = 7;
|
|
82
78
|
break;
|
|
83
79
|
}
|
|
84
|
-
|
|
85
80
|
return _context2.abrupt("return", next(utils));
|
|
86
|
-
|
|
87
81
|
case 7:
|
|
88
|
-
|
|
89
|
-
|
|
82
|
+
alias = mergeAlias(userConfig.source.alias);
|
|
83
|
+
if (testingExportsUtils) {
|
|
84
|
+
alias['@modern-js/runtime/testing'] = [testingExportsUtils.getPath()];
|
|
85
|
+
}
|
|
90
86
|
utils.mergeJestConfig({
|
|
91
87
|
globals: _defineProperty({}, MODERNJS_CONFIG_KEY, userConfig),
|
|
92
88
|
moduleNameMapper: getModuleNameMapper(alias),
|
|
@@ -100,7 +96,6 @@ export default (function () {
|
|
|
100
96
|
});
|
|
101
97
|
mergeUserJestConfig(utils);
|
|
102
98
|
return _context2.abrupt("return", next(utils));
|
|
103
|
-
|
|
104
99
|
case 12:
|
|
105
100
|
case "end":
|
|
106
101
|
return _context2.stop();
|
|
@@ -108,11 +103,9 @@ export default (function () {
|
|
|
108
103
|
}
|
|
109
104
|
}, _callee2);
|
|
110
105
|
}));
|
|
111
|
-
|
|
112
106
|
function jestConfig(_x, _x2) {
|
|
113
107
|
return _jestConfig.apply(this, arguments);
|
|
114
108
|
}
|
|
115
|
-
|
|
116
109
|
return jestConfig;
|
|
117
110
|
}()
|
|
118
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
|
});
|
|
@@ -3,7 +3,6 @@ import { TestConfigOperator } from './testConfigOperator';
|
|
|
3
3
|
/**
|
|
4
4
|
* Parse jest config
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
6
|
declare const getJestUtils: (testConfig: TestConfig) => TestConfigOperator;
|
|
8
7
|
declare const patchConfig: (testOperator: TestConfigOperator) => Promise<Partial<{
|
|
9
8
|
automock: boolean;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { JestConfig, TestConfig } from '../types';
|
|
2
|
-
|
|
3
2
|
declare class TestConfigOperator {
|
|
4
3
|
private _testConfig;
|
|
5
4
|
private _jestConfig;
|
|
@@ -244,5 +243,4 @@ declare class TestConfigOperator {
|
|
|
244
243
|
watchPlugins: (string | [string, Record<string, unknown>])[];
|
|
245
244
|
}>;
|
|
246
245
|
}
|
|
247
|
-
|
|
248
246
|
export { TestConfigOperator };
|