@modern-js/plugin-testing 2.21.2-alpha.0 → 2.22.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +27 -0
- package/package.json +16 -13
- package/dist/js/modern/base/config/index.js +0 -36
- package/dist/js/modern/base/config/patches/assetsModule.js +0 -11
- package/dist/js/modern/base/config/patches/filemock.js +0 -4
- package/dist/js/modern/base/config/patches/index.js +0 -34
- package/dist/js/modern/base/config/patches/transformer.js +0 -38
- package/dist/js/modern/base/config/resolver.js +0 -21
- package/dist/js/modern/base/config/testConfigOperator.js +0 -69
- package/dist/js/modern/base/config/transformer/babelTransformer.js +0 -19
- package/dist/js/modern/base/hook.js +0 -12
- package/dist/js/modern/base/index.js +0 -14
- package/dist/js/modern/base/runJest.js +0 -102
- package/dist/js/modern/base/types/index.js +0 -0
- package/dist/js/modern/base/utils.js +0 -66
- package/dist/js/modern/cli/bff/app.js +0 -58
- package/dist/js/modern/cli/bff/constant.js +0 -4
- package/dist/js/modern/cli/bff/index.js +0 -149
- package/dist/js/modern/cli/bff/mockAPI.js +0 -109
- package/dist/js/modern/cli/bff/setup.js +0 -75
- package/dist/js/modern/cli/bff/utils/index.js +0 -37
- package/dist/js/modern/cli/index.js +0 -115
- package/dist/js/modern/cli/test.js +0 -61
- package/dist/js/modern/constant.js +0 -4
- package/dist/js/modern/index.js +0 -3
- package/dist/js/modern/runtime-testing/app.js +0 -48
- package/dist/js/modern/runtime-testing/base.js +0 -7
- package/dist/js/modern/runtime-testing/customRender.js +0 -25
- package/dist/js/modern/runtime-testing/index.js +0 -2
- package/dist/js/modern/runtime-testing/reduck.js +0 -55
- package/dist/js/modern/runtime-testing/request.js +0 -16
- package/dist/js/modern/runtime-testing/resolvePlugins.js +0 -33
- package/dist/js/node/base/config/index.js +0 -67
- package/dist/js/node/base/config/patches/assetsModule.js +0 -40
- package/dist/js/node/base/config/patches/filemock.js +0 -25
- package/dist/js/node/base/config/patches/index.js +0 -57
- package/dist/js/node/base/config/patches/transformer.js +0 -67
- package/dist/js/node/base/config/resolver.js +0 -30
- package/dist/js/node/base/config/testConfigOperator.js +0 -90
- package/dist/js/node/base/config/transformer/babelTransformer.js +0 -46
- package/dist/js/node/base/hook.js +0 -37
- package/dist/js/node/base/index.js +0 -43
- package/dist/js/node/base/runJest.js +0 -132
- package/dist/js/node/base/types/index.js +0 -15
- package/dist/js/node/base/utils.js +0 -95
- package/dist/js/node/cli/bff/app.js +0 -84
- package/dist/js/node/cli/bff/constant.js +0 -27
- package/dist/js/node/cli/bff/index.js +0 -173
- package/dist/js/node/cli/bff/mockAPI.js +0 -134
- package/dist/js/node/cli/bff/setup.js +0 -84
- package/dist/js/node/cli/bff/utils/index.js +0 -64
- package/dist/js/node/cli/index.js +0 -135
- package/dist/js/node/cli/test.js +0 -88
- package/dist/js/node/constant.js +0 -27
- package/dist/js/node/index.js +0 -19
- package/dist/js/node/runtime-testing/app.js +0 -73
- package/dist/js/node/runtime-testing/base.js +0 -38
- package/dist/js/node/runtime-testing/customRender.js +0 -50
- package/dist/js/node/runtime-testing/index.js +0 -18
- package/dist/js/node/runtime-testing/reduck.js +0 -85
- package/dist/js/node/runtime-testing/request.js +0 -45
- package/dist/js/node/runtime-testing/resolvePlugins.js +0 -52
- package/dist/js/treeshaking/base/config/index.js +0 -154
- package/dist/js/treeshaking/base/config/patches/assetsModule.js +0 -9
- package/dist/js/treeshaking/base/config/patches/filemock.js +0 -2
- package/dist/js/treeshaking/base/config/patches/index.js +0 -225
- package/dist/js/treeshaking/base/config/patches/transformer.js +0 -36
- package/dist/js/treeshaking/base/config/resolver.js +0 -37
- package/dist/js/treeshaking/base/config/testConfigOperator.js +0 -127
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +0 -17
- package/dist/js/treeshaking/base/hook.js +0 -8
- package/dist/js/treeshaking/base/index.js +0 -7
- package/dist/js/treeshaking/base/runJest.js +0 -292
- package/dist/js/treeshaking/base/types/index.js +0 -1
- package/dist/js/treeshaking/base/utils.js +0 -76
- package/dist/js/treeshaking/cli/bff/app.js +0 -200
- package/dist/js/treeshaking/cli/bff/constant.js +0 -2
- package/dist/js/treeshaking/cli/bff/index.js +0 -297
- package/dist/js/treeshaking/cli/bff/mockAPI.js +0 -188
- package/dist/js/treeshaking/cli/bff/setup.js +0 -192
- package/dist/js/treeshaking/cli/bff/utils/index.js +0 -47
- package/dist/js/treeshaking/cli/index.js +0 -255
- package/dist/js/treeshaking/cli/test.js +0 -180
- package/dist/js/treeshaking/constant.js +0 -2
- package/dist/js/treeshaking/index.js +0 -3
- package/dist/js/treeshaking/runtime-testing/app.js +0 -90
- package/dist/js/treeshaking/runtime-testing/base.js +0 -4
- package/dist/js/treeshaking/runtime-testing/customRender.js +0 -41
- package/dist/js/treeshaking/runtime-testing/index.js +0 -2
- package/dist/js/treeshaking/runtime-testing/reduck.js +0 -89
- package/dist/js/treeshaking/runtime-testing/request.js +0 -51
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +0 -46
@@ -1,200 +0,0 @@
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
2
|
-
try {
|
3
|
-
var info = gen[key](arg);
|
4
|
-
var value = info.value;
|
5
|
-
} catch (error) {
|
6
|
-
reject(error);
|
7
|
-
return;
|
8
|
-
}
|
9
|
-
if (info.done) {
|
10
|
-
resolve(value);
|
11
|
-
} else {
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
13
|
-
}
|
14
|
-
}
|
15
|
-
function _asyncToGenerator(fn) {
|
16
|
-
return function() {
|
17
|
-
var self = this, args = arguments;
|
18
|
-
return new Promise(function(resolve, reject) {
|
19
|
-
var gen = fn.apply(self, args);
|
20
|
-
function _next(value) {
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
22
|
-
}
|
23
|
-
function _throw(err) {
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
25
|
-
}
|
26
|
-
_next(undefined);
|
27
|
-
});
|
28
|
-
};
|
29
|
-
}
|
30
|
-
var __generator = this && this.__generator || function(thisArg, body) {
|
31
|
-
var f, y, t, g, _ = {
|
32
|
-
label: 0,
|
33
|
-
sent: function() {
|
34
|
-
if (t[0] & 1) throw t[1];
|
35
|
-
return t[1];
|
36
|
-
},
|
37
|
-
trys: [],
|
38
|
-
ops: []
|
39
|
-
};
|
40
|
-
return(g = {
|
41
|
-
next: verb(0),
|
42
|
-
"throw": verb(1),
|
43
|
-
"return": verb(2)
|
44
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
45
|
-
return this;
|
46
|
-
}), g);
|
47
|
-
function verb(n) {
|
48
|
-
return function(v) {
|
49
|
-
return step([
|
50
|
-
n,
|
51
|
-
v
|
52
|
-
]);
|
53
|
-
};
|
54
|
-
}
|
55
|
-
function step(op) {
|
56
|
-
if (f) throw new TypeError("Generator is already executing.");
|
57
|
-
while(_)try {
|
58
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
59
|
-
if (y = 0, t) op = [
|
60
|
-
op[0] & 2,
|
61
|
-
t.value
|
62
|
-
];
|
63
|
-
switch(op[0]){
|
64
|
-
case 0:
|
65
|
-
case 1:
|
66
|
-
t = op;
|
67
|
-
break;
|
68
|
-
case 4:
|
69
|
-
_.label++;
|
70
|
-
return {
|
71
|
-
value: op[1],
|
72
|
-
done: false
|
73
|
-
};
|
74
|
-
case 5:
|
75
|
-
_.label++;
|
76
|
-
y = op[1];
|
77
|
-
op = [
|
78
|
-
0
|
79
|
-
];
|
80
|
-
continue;
|
81
|
-
case 7:
|
82
|
-
op = _.ops.pop();
|
83
|
-
_.trys.pop();
|
84
|
-
continue;
|
85
|
-
default:
|
86
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
87
|
-
_ = 0;
|
88
|
-
continue;
|
89
|
-
}
|
90
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
91
|
-
_.label = op[1];
|
92
|
-
break;
|
93
|
-
}
|
94
|
-
if (op[0] === 6 && _.label < t[1]) {
|
95
|
-
_.label = t[1];
|
96
|
-
t = op;
|
97
|
-
break;
|
98
|
-
}
|
99
|
-
if (t && _.label < t[2]) {
|
100
|
-
_.label = t[2];
|
101
|
-
_.ops.push(op);
|
102
|
-
break;
|
103
|
-
}
|
104
|
-
if (t[2]) _.ops.pop();
|
105
|
-
_.trys.pop();
|
106
|
-
continue;
|
107
|
-
}
|
108
|
-
op = body.call(thisArg, _);
|
109
|
-
} catch (e) {
|
110
|
-
op = [
|
111
|
-
6,
|
112
|
-
e
|
113
|
-
];
|
114
|
-
y = 0;
|
115
|
-
} finally{
|
116
|
-
f = t = 0;
|
117
|
-
}
|
118
|
-
if (op[0] & 5) throw op[1];
|
119
|
-
return {
|
120
|
-
value: op[0] ? op[1] : void 0,
|
121
|
-
done: true
|
122
|
-
};
|
123
|
-
}
|
124
|
-
};
|
125
|
-
import { AsyncLocalStorage } from "async_hooks";
|
126
|
-
import { Server } from "@modern-js/prod-server";
|
127
|
-
var store = new AsyncLocalStorage();
|
128
|
-
var isInHandler = function() {
|
129
|
-
return Boolean(store.getStore());
|
130
|
-
};
|
131
|
-
var server = null;
|
132
|
-
var createApp = function() {
|
133
|
-
var _ref = _asyncToGenerator(function(pwd, config, plugins, routes) {
|
134
|
-
var app;
|
135
|
-
return __generator(this, function(_state) {
|
136
|
-
switch(_state.label){
|
137
|
-
case 0:
|
138
|
-
if (!!server) return [
|
139
|
-
3,
|
140
|
-
2
|
141
|
-
];
|
142
|
-
config.output.path = "./";
|
143
|
-
server = new Server({
|
144
|
-
apiOnly: true,
|
145
|
-
pwd: pwd,
|
146
|
-
config: config,
|
147
|
-
internalPlugins: plugins,
|
148
|
-
routes: routes
|
149
|
-
});
|
150
|
-
return [
|
151
|
-
4,
|
152
|
-
server.init()
|
153
|
-
];
|
154
|
-
case 1:
|
155
|
-
_state.sent();
|
156
|
-
_state.label = 2;
|
157
|
-
case 2:
|
158
|
-
app = server.getRequestHandler();
|
159
|
-
return [
|
160
|
-
2,
|
161
|
-
app
|
162
|
-
];
|
163
|
-
}
|
164
|
-
});
|
165
|
-
});
|
166
|
-
return function createApp(pwd, config, plugins, routes) {
|
167
|
-
return _ref.apply(this, arguments);
|
168
|
-
};
|
169
|
-
}();
|
170
|
-
var getApp = function() {
|
171
|
-
if (!server) {
|
172
|
-
throw new Error("please createApp first");
|
173
|
-
}
|
174
|
-
return server.getRequestHandler();
|
175
|
-
};
|
176
|
-
var closeServer = function() {
|
177
|
-
var _ref = _asyncToGenerator(function() {
|
178
|
-
return __generator(this, function(_state) {
|
179
|
-
switch(_state.label){
|
180
|
-
case 0:
|
181
|
-
if (!server) {
|
182
|
-
throw new Error("please createApp first");
|
183
|
-
}
|
184
|
-
return [
|
185
|
-
4,
|
186
|
-
server.close()
|
187
|
-
];
|
188
|
-
case 1:
|
189
|
-
_state.sent();
|
190
|
-
return [
|
191
|
-
2
|
192
|
-
];
|
193
|
-
}
|
194
|
-
});
|
195
|
-
});
|
196
|
-
return function closeServer() {
|
197
|
-
return _ref.apply(this, arguments);
|
198
|
-
};
|
199
|
-
}();
|
200
|
-
export { closeServer, createApp, getApp, isInHandler };
|
@@ -1,297 +0,0 @@
|
|
1
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
2
|
-
try {
|
3
|
-
var info = gen[key](arg);
|
4
|
-
var value = info.value;
|
5
|
-
} catch (error) {
|
6
|
-
reject(error);
|
7
|
-
return;
|
8
|
-
}
|
9
|
-
if (info.done) {
|
10
|
-
resolve(value);
|
11
|
-
} else {
|
12
|
-
Promise.resolve(value).then(_next, _throw);
|
13
|
-
}
|
14
|
-
}
|
15
|
-
function _asyncToGenerator(fn) {
|
16
|
-
return function() {
|
17
|
-
var self = this, args = arguments;
|
18
|
-
return new Promise(function(resolve, reject) {
|
19
|
-
var gen = fn.apply(self, args);
|
20
|
-
function _next(value) {
|
21
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
22
|
-
}
|
23
|
-
function _throw(err) {
|
24
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
25
|
-
}
|
26
|
-
_next(undefined);
|
27
|
-
});
|
28
|
-
};
|
29
|
-
}
|
30
|
-
function _defineProperty(obj, key, value) {
|
31
|
-
if (key in obj) {
|
32
|
-
Object.defineProperty(obj, key, {
|
33
|
-
value: value,
|
34
|
-
enumerable: true,
|
35
|
-
configurable: true,
|
36
|
-
writable: true
|
37
|
-
});
|
38
|
-
} else {
|
39
|
-
obj[key] = value;
|
40
|
-
}
|
41
|
-
return obj;
|
42
|
-
}
|
43
|
-
function _objectSpread(target) {
|
44
|
-
for(var i = 1; i < arguments.length; i++){
|
45
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
46
|
-
var ownKeys = Object.keys(source);
|
47
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
48
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
49
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
50
|
-
}));
|
51
|
-
}
|
52
|
-
ownKeys.forEach(function(key) {
|
53
|
-
_defineProperty(target, key, source[key]);
|
54
|
-
});
|
55
|
-
}
|
56
|
-
return target;
|
57
|
-
}
|
58
|
-
var __generator = this && this.__generator || function(thisArg, body) {
|
59
|
-
var f, y, t, g, _ = {
|
60
|
-
label: 0,
|
61
|
-
sent: function() {
|
62
|
-
if (t[0] & 1) throw t[1];
|
63
|
-
return t[1];
|
64
|
-
},
|
65
|
-
trys: [],
|
66
|
-
ops: []
|
67
|
-
};
|
68
|
-
return(g = {
|
69
|
-
next: verb(0),
|
70
|
-
"throw": verb(1),
|
71
|
-
"return": verb(2)
|
72
|
-
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
73
|
-
return this;
|
74
|
-
}), g);
|
75
|
-
function verb(n) {
|
76
|
-
return function(v) {
|
77
|
-
return step([
|
78
|
-
n,
|
79
|
-
v
|
80
|
-
]);
|
81
|
-
};
|
82
|
-
}
|
83
|
-
function step(op) {
|
84
|
-
if (f) throw new TypeError("Generator is already executing.");
|
85
|
-
while(_)try {
|
86
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
87
|
-
if (y = 0, t) op = [
|
88
|
-
op[0] & 2,
|
89
|
-
t.value
|
90
|
-
];
|
91
|
-
switch(op[0]){
|
92
|
-
case 0:
|
93
|
-
case 1:
|
94
|
-
t = op;
|
95
|
-
break;
|
96
|
-
case 4:
|
97
|
-
_.label++;
|
98
|
-
return {
|
99
|
-
value: op[1],
|
100
|
-
done: false
|
101
|
-
};
|
102
|
-
case 5:
|
103
|
-
_.label++;
|
104
|
-
y = op[1];
|
105
|
-
op = [
|
106
|
-
0
|
107
|
-
];
|
108
|
-
continue;
|
109
|
-
case 7:
|
110
|
-
op = _.ops.pop();
|
111
|
-
_.trys.pop();
|
112
|
-
continue;
|
113
|
-
default:
|
114
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
115
|
-
_ = 0;
|
116
|
-
continue;
|
117
|
-
}
|
118
|
-
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
119
|
-
_.label = op[1];
|
120
|
-
break;
|
121
|
-
}
|
122
|
-
if (op[0] === 6 && _.label < t[1]) {
|
123
|
-
_.label = t[1];
|
124
|
-
t = op;
|
125
|
-
break;
|
126
|
-
}
|
127
|
-
if (t && _.label < t[2]) {
|
128
|
-
_.label = t[2];
|
129
|
-
_.ops.push(op);
|
130
|
-
break;
|
131
|
-
}
|
132
|
-
if (t[2]) _.ops.pop();
|
133
|
-
_.trys.pop();
|
134
|
-
continue;
|
135
|
-
}
|
136
|
-
op = body.call(thisArg, _);
|
137
|
-
} catch (e) {
|
138
|
-
op = [
|
139
|
-
6,
|
140
|
-
e
|
141
|
-
];
|
142
|
-
y = 0;
|
143
|
-
} finally{
|
144
|
-
f = t = 0;
|
145
|
-
}
|
146
|
-
if (op[0] & 5) throw op[1];
|
147
|
-
return {
|
148
|
-
value: op[0] ? op[1] : void 0,
|
149
|
-
done: true
|
150
|
-
};
|
151
|
-
}
|
152
|
-
};
|
153
|
-
import path from "path";
|
154
|
-
import { isApiOnly } from "@modern-js/utils";
|
155
|
-
import { getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../../base";
|
156
|
-
import { bff_info_key } from "./constant";
|
157
|
-
import { isBFFProject } from "./utils";
|
158
|
-
var setJestConfigForBFF = function() {
|
159
|
-
var _ref = _asyncToGenerator(function(param) {
|
160
|
-
var pwd, userConfig, plugins, routes, utils, _userConfig_source, bffConfig, jestConfig, alias, aliasMapper, moduleNameMapper, transform, apiOnly, mergedModuleNameMapper, resolver, configFields, commonConfig;
|
161
|
-
return __generator(this, function(_state) {
|
162
|
-
switch(_state.label){
|
163
|
-
case 0:
|
164
|
-
pwd = param.pwd, userConfig = param.userConfig, plugins = param.plugins, routes = param.routes, utils = param.utils;
|
165
|
-
bffConfig = {
|
166
|
-
rootDir: path.join(pwd, "./api"),
|
167
|
-
setupFilesAfterEnv: [
|
168
|
-
require.resolve("./setup")
|
169
|
-
],
|
170
|
-
testEnvironment: "node",
|
171
|
-
testMatch: [
|
172
|
-
"**/api/**/*.test.[jt]s"
|
173
|
-
],
|
174
|
-
globals: _defineProperty({
|
175
|
-
"ts-jest": {
|
176
|
-
diagnostics: {
|
177
|
-
warnOnly: true
|
178
|
-
}
|
179
|
-
}
|
180
|
-
}, bff_info_key, {
|
181
|
-
appDir: pwd,
|
182
|
-
modernUserConfig: userConfig,
|
183
|
-
plugins: plugins,
|
184
|
-
routes: routes
|
185
|
-
})
|
186
|
-
};
|
187
|
-
jestConfig = utils.jestConfig;
|
188
|
-
alias = (userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.alias) || {};
|
189
|
-
aliasMapper = getModuleNameMapper(alias);
|
190
|
-
moduleNameMapper = jestConfig.moduleNameMapper;
|
191
|
-
transform = {
|
192
|
-
"\\.[jt]sx?$": require.resolve("ts-jest")
|
193
|
-
};
|
194
|
-
return [
|
195
|
-
4,
|
196
|
-
isApiOnly(pwd)
|
197
|
-
];
|
198
|
-
case 1:
|
199
|
-
apiOnly = _state.sent();
|
200
|
-
mergedModuleNameMapper = _objectSpread({}, moduleNameMapper, aliasMapper);
|
201
|
-
resolver = jestConfig.resolver || DEFAULT_RESOLVER_PATH;
|
202
|
-
configFields = [
|
203
|
-
"coverage",
|
204
|
-
"collectCoverage",
|
205
|
-
"testTimeout"
|
206
|
-
];
|
207
|
-
commonConfig = configFields.reduce(function(obj, field) {
|
208
|
-
if (jestConfig.hasOwnProperty(field)) {
|
209
|
-
obj[field] = jestConfig[field];
|
210
|
-
}
|
211
|
-
return obj;
|
212
|
-
}, {});
|
213
|
-
if (!apiOnly) {
|
214
|
-
utils.setJestConfig({
|
215
|
-
projects: [
|
216
|
-
_objectSpread({}, jestConfig),
|
217
|
-
_objectSpread({
|
218
|
-
transform: transform,
|
219
|
-
moduleNameMapper: mergedModuleNameMapper,
|
220
|
-
resolver: resolver
|
221
|
-
}, bffConfig)
|
222
|
-
]
|
223
|
-
}, {
|
224
|
-
force: true
|
225
|
-
});
|
226
|
-
} else {
|
227
|
-
utils.setJestConfig({
|
228
|
-
projects: [
|
229
|
-
_objectSpread({
|
230
|
-
transform: transform,
|
231
|
-
moduleNameMapper: mergedModuleNameMapper,
|
232
|
-
resolver: resolver
|
233
|
-
}, bffConfig)
|
234
|
-
]
|
235
|
-
}, {
|
236
|
-
force: true
|
237
|
-
});
|
238
|
-
}
|
239
|
-
utils.setJestConfig(commonConfig);
|
240
|
-
return [
|
241
|
-
2
|
242
|
-
];
|
243
|
-
}
|
244
|
-
});
|
245
|
-
});
|
246
|
-
return function setJestConfigForBFF(_) {
|
247
|
-
return _ref.apply(this, arguments);
|
248
|
-
};
|
249
|
-
}();
|
250
|
-
var bff_default = function() {
|
251
|
-
return {
|
252
|
-
name: "@modern-js/testing-plugin-bff",
|
253
|
-
setup: function setup(api) {
|
254
|
-
return {
|
255
|
-
jestConfig: function() {
|
256
|
-
var _ref = _asyncToGenerator(function(utils, next) {
|
257
|
-
var appContext, pwd, userConfig;
|
258
|
-
return __generator(this, function(_state) {
|
259
|
-
switch(_state.label){
|
260
|
-
case 0:
|
261
|
-
appContext = api.useAppContext();
|
262
|
-
pwd = appContext.appDirectory;
|
263
|
-
if (!isBFFProject(pwd)) {
|
264
|
-
return [
|
265
|
-
2,
|
266
|
-
next(utils)
|
267
|
-
];
|
268
|
-
}
|
269
|
-
userConfig = api.useResolvedConfigContext();
|
270
|
-
return [
|
271
|
-
4,
|
272
|
-
setJestConfigForBFF({
|
273
|
-
pwd: pwd,
|
274
|
-
userConfig: userConfig,
|
275
|
-
routes: appContext.serverRoutes,
|
276
|
-
plugins: appContext.serverInternalPlugins,
|
277
|
-
utils: utils
|
278
|
-
})
|
279
|
-
];
|
280
|
-
case 1:
|
281
|
-
_state.sent();
|
282
|
-
return [
|
283
|
-
2,
|
284
|
-
next(utils)
|
285
|
-
];
|
286
|
-
}
|
287
|
-
});
|
288
|
-
});
|
289
|
-
return function(utils, next) {
|
290
|
-
return _ref.apply(this, arguments);
|
291
|
-
};
|
292
|
-
}()
|
293
|
-
};
|
294
|
-
}
|
295
|
-
};
|
296
|
-
};
|
297
|
-
export { bff_default as default, setJestConfigForBFF };
|
@@ -1,188 +0,0 @@
|
|
1
|
-
function _arrayLikeToArray(arr, len) {
|
2
|
-
if (len == null || len > arr.length) len = arr.length;
|
3
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
4
|
-
return arr2;
|
5
|
-
}
|
6
|
-
function _arrayWithHoles(arr) {
|
7
|
-
if (Array.isArray(arr)) return arr;
|
8
|
-
}
|
9
|
-
function _arrayWithoutHoles(arr) {
|
10
|
-
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
|
11
|
-
}
|
12
|
-
function _defineProperty(obj, key, value) {
|
13
|
-
if (key in obj) {
|
14
|
-
Object.defineProperty(obj, key, {
|
15
|
-
value: value,
|
16
|
-
enumerable: true,
|
17
|
-
configurable: true,
|
18
|
-
writable: true
|
19
|
-
});
|
20
|
-
} else {
|
21
|
-
obj[key] = value;
|
22
|
-
}
|
23
|
-
return obj;
|
24
|
-
}
|
25
|
-
function _iterableToArray(iter) {
|
26
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
27
|
-
}
|
28
|
-
function _iterableToArrayLimit(arr, i) {
|
29
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
30
|
-
if (_i == null) return;
|
31
|
-
var _arr = [];
|
32
|
-
var _n = true;
|
33
|
-
var _d = false;
|
34
|
-
var _s, _e;
|
35
|
-
try {
|
36
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
37
|
-
_arr.push(_s.value);
|
38
|
-
if (i && _arr.length === i) break;
|
39
|
-
}
|
40
|
-
} catch (err) {
|
41
|
-
_d = true;
|
42
|
-
_e = err;
|
43
|
-
} finally{
|
44
|
-
try {
|
45
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
46
|
-
} finally{
|
47
|
-
if (_d) throw _e;
|
48
|
-
}
|
49
|
-
}
|
50
|
-
return _arr;
|
51
|
-
}
|
52
|
-
function _nonIterableRest() {
|
53
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
54
|
-
}
|
55
|
-
function _nonIterableSpread() {
|
56
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
57
|
-
}
|
58
|
-
function _objectSpread(target) {
|
59
|
-
for(var i = 1; i < arguments.length; i++){
|
60
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
61
|
-
var ownKeys = Object.keys(source);
|
62
|
-
if (typeof Object.getOwnPropertySymbols === "function") {
|
63
|
-
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
64
|
-
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
65
|
-
}));
|
66
|
-
}
|
67
|
-
ownKeys.forEach(function(key) {
|
68
|
-
_defineProperty(target, key, source[key]);
|
69
|
-
});
|
70
|
-
}
|
71
|
-
return target;
|
72
|
-
}
|
73
|
-
function _slicedToArray(arr, i) {
|
74
|
-
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
75
|
-
}
|
76
|
-
function _toConsumableArray(arr) {
|
77
|
-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
78
|
-
}
|
79
|
-
function _unsupportedIterableToArray(o, minLen) {
|
80
|
-
if (!o) return;
|
81
|
-
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
82
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
83
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
84
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
85
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
86
|
-
}
|
87
|
-
import * as ptr from "path-to-regexp";
|
88
|
-
import * as mockAppModule from "./app";
|
89
|
-
var mock_replaceUrlWithParams = function(url, paramValues, payload) {
|
90
|
-
var keys = [];
|
91
|
-
ptr.pathToRegexp(url, keys);
|
92
|
-
var params = keys.reduce(function(cur, key, index) {
|
93
|
-
if (paramValues[index]) {
|
94
|
-
cur[key.name] = paramValues[index];
|
95
|
-
}
|
96
|
-
return cur;
|
97
|
-
}, {});
|
98
|
-
var getFinalPath = ptr.compile(url, {
|
99
|
-
encode: encodeURIComponent
|
100
|
-
});
|
101
|
-
return getFinalPath(_objectSpread({}, params, payload));
|
102
|
-
};
|
103
|
-
var mock_getParamsAndPayload = function(args) {
|
104
|
-
if (args.length === 0) {
|
105
|
-
return [
|
106
|
-
[],
|
107
|
-
{}
|
108
|
-
];
|
109
|
-
}
|
110
|
-
var head = args[0];
|
111
|
-
if (typeof head === "object") {
|
112
|
-
return [
|
113
|
-
[],
|
114
|
-
head
|
115
|
-
];
|
116
|
-
} else {
|
117
|
-
var latest = args[args.length - 1];
|
118
|
-
if (typeof latest === "object") {
|
119
|
-
return [
|
120
|
-
args.slice(0, args.length - 1),
|
121
|
-
latest
|
122
|
-
];
|
123
|
-
} else {
|
124
|
-
return [
|
125
|
-
args,
|
126
|
-
{}
|
127
|
-
];
|
128
|
-
}
|
129
|
-
}
|
130
|
-
};
|
131
|
-
var mockAPI_default = function(mockApiInfosByFile) {
|
132
|
-
var files = Object.keys(mockApiInfosByFile);
|
133
|
-
files.forEach(function(mockedFile) {
|
134
|
-
jest.mock(mockedFile, function() {
|
135
|
-
var supertest = require("supertest");
|
136
|
-
return mockApiInfosByFile[mockedFile].reduce(function(res, info) {
|
137
|
-
var module = _defineProperty({}, info.name, function() {
|
138
|
-
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
|
139
|
-
args[_key] = arguments[_key];
|
140
|
-
}
|
141
|
-
if (mockAppModule.isInHandler()) {
|
142
|
-
var _info;
|
143
|
-
return (_info = info).handler.apply(_info, _toConsumableArray(args));
|
144
|
-
}
|
145
|
-
var _mock_getParamsAndPayload = _slicedToArray(mock_getParamsAndPayload(args), 2), params = _mock_getParamsAndPayload[0], payload = _mock_getParamsAndPayload[1];
|
146
|
-
var returnHttp = module[info.name].returnHttp;
|
147
|
-
var url = mock_replaceUrlWithParams(info.routePath, params, payload.params);
|
148
|
-
var app = mockAppModule.getApp();
|
149
|
-
var test = supertest(app)[info.httpMethod.toLowerCase()](url);
|
150
|
-
if (payload.query) {
|
151
|
-
test = test.query(payload.query);
|
152
|
-
}
|
153
|
-
if (payload.body) {
|
154
|
-
test = test.send(payload.body);
|
155
|
-
}
|
156
|
-
if (payload.data) {
|
157
|
-
test = test.send(payload.data);
|
158
|
-
}
|
159
|
-
if (payload.headers) {
|
160
|
-
for(var name in payload.headers){
|
161
|
-
test = test.set(name, payload.headers[name]);
|
162
|
-
}
|
163
|
-
}
|
164
|
-
if (payload.cookies) {
|
165
|
-
test = test.set("Cookie", [
|
166
|
-
payload.cookies
|
167
|
-
]);
|
168
|
-
}
|
169
|
-
if (returnHttp) {
|
170
|
-
return test;
|
171
|
-
}
|
172
|
-
return test.then(function(value) {
|
173
|
-
try {
|
174
|
-
return JSON.parse(value.text);
|
175
|
-
} catch (e) {
|
176
|
-
return value.text;
|
177
|
-
}
|
178
|
-
});
|
179
|
-
});
|
180
|
-
res[info.name] = module[info.name];
|
181
|
-
Object.assign(res[info.name], info.handler);
|
182
|
-
res.__esModule = true;
|
183
|
-
return res;
|
184
|
-
}, {});
|
185
|
-
});
|
186
|
-
});
|
187
|
-
};
|
188
|
-
export { mockAPI_default as default };
|