@modern-js/plugin-testing 2.20.0 → 2.20.1-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/cli/bff/index.js +3 -0
- package/dist/esm/cli/bff/index.js +3 -0
- package/dist/esm-node/cli/bff/index.js +3 -0
- package/dist/js/modern/base/config/index.js +36 -0
- package/dist/js/modern/base/config/patches/assetsModule.js +11 -0
- package/dist/js/modern/base/config/patches/filemock.js +4 -0
- package/dist/js/modern/base/config/patches/index.js +34 -0
- package/dist/js/modern/base/config/patches/transformer.js +38 -0
- package/dist/js/modern/base/config/resolver.js +21 -0
- package/dist/js/modern/base/config/testConfigOperator.js +69 -0
- package/dist/js/modern/base/config/transformer/babelTransformer.js +19 -0
- package/dist/js/modern/base/hook.js +12 -0
- package/dist/js/modern/base/index.js +14 -0
- package/dist/js/modern/base/runJest.js +102 -0
- package/dist/js/modern/base/types/index.js +0 -0
- package/dist/js/modern/base/utils.js +66 -0
- package/dist/js/modern/cli/bff/app.js +58 -0
- package/dist/js/modern/cli/bff/constant.js +4 -0
- package/dist/js/modern/cli/bff/index.js +149 -0
- package/dist/js/modern/cli/bff/mockAPI.js +109 -0
- package/dist/js/modern/cli/bff/setup.js +75 -0
- package/dist/js/modern/cli/bff/utils/index.js +37 -0
- package/dist/js/modern/cli/index.js +115 -0
- package/dist/js/modern/cli/test.js +61 -0
- package/dist/js/modern/constant.js +4 -0
- package/dist/js/modern/index.js +3 -0
- package/dist/js/modern/runtime-testing/app.js +48 -0
- package/dist/js/modern/runtime-testing/base.js +7 -0
- package/dist/js/modern/runtime-testing/customRender.js +25 -0
- package/dist/js/modern/runtime-testing/index.js +2 -0
- package/dist/js/modern/runtime-testing/reduck.js +55 -0
- package/dist/js/modern/runtime-testing/request.js +16 -0
- package/dist/js/modern/runtime-testing/resolvePlugins.js +33 -0
- package/dist/js/node/base/config/index.js +67 -0
- package/dist/js/node/base/config/patches/assetsModule.js +40 -0
- package/dist/js/node/base/config/patches/filemock.js +25 -0
- package/dist/js/node/base/config/patches/index.js +57 -0
- package/dist/js/node/base/config/patches/transformer.js +67 -0
- package/dist/js/node/base/config/resolver.js +30 -0
- package/dist/js/node/base/config/testConfigOperator.js +90 -0
- package/dist/js/node/base/config/transformer/babelTransformer.js +46 -0
- package/dist/js/node/base/hook.js +37 -0
- package/dist/js/node/base/index.js +43 -0
- package/dist/js/node/base/runJest.js +132 -0
- package/dist/js/node/base/types/index.js +15 -0
- package/dist/js/node/base/utils.js +95 -0
- package/dist/js/node/cli/bff/app.js +84 -0
- package/dist/js/node/cli/bff/constant.js +27 -0
- package/dist/js/node/cli/bff/index.js +173 -0
- package/dist/js/node/cli/bff/mockAPI.js +134 -0
- package/dist/js/node/cli/bff/setup.js +84 -0
- package/dist/js/node/cli/bff/utils/index.js +64 -0
- package/dist/js/node/cli/index.js +135 -0
- package/dist/js/node/cli/test.js +88 -0
- package/dist/js/node/constant.js +27 -0
- package/dist/js/node/index.js +19 -0
- package/dist/js/node/runtime-testing/app.js +73 -0
- package/dist/js/node/runtime-testing/base.js +38 -0
- package/dist/js/node/runtime-testing/customRender.js +50 -0
- package/dist/js/node/runtime-testing/index.js +18 -0
- package/dist/js/node/runtime-testing/reduck.js +85 -0
- package/dist/js/node/runtime-testing/request.js +45 -0
- package/dist/js/node/runtime-testing/resolvePlugins.js +52 -0
- package/dist/js/treeshaking/base/config/index.js +154 -0
- package/dist/js/treeshaking/base/config/patches/assetsModule.js +9 -0
- package/dist/js/treeshaking/base/config/patches/filemock.js +2 -0
- package/dist/js/treeshaking/base/config/patches/index.js +225 -0
- package/dist/js/treeshaking/base/config/patches/transformer.js +36 -0
- package/dist/js/treeshaking/base/config/resolver.js +37 -0
- package/dist/js/treeshaking/base/config/testConfigOperator.js +127 -0
- package/dist/js/treeshaking/base/config/transformer/babelTransformer.js +17 -0
- package/dist/js/treeshaking/base/hook.js +8 -0
- package/dist/js/treeshaking/base/index.js +7 -0
- package/dist/js/treeshaking/base/runJest.js +292 -0
- package/dist/js/treeshaking/base/types/index.js +1 -0
- package/dist/js/treeshaking/base/utils.js +76 -0
- package/dist/js/treeshaking/cli/bff/app.js +200 -0
- package/dist/js/treeshaking/cli/bff/constant.js +2 -0
- package/dist/js/treeshaking/cli/bff/index.js +297 -0
- package/dist/js/treeshaking/cli/bff/mockAPI.js +188 -0
- package/dist/js/treeshaking/cli/bff/setup.js +192 -0
- package/dist/js/treeshaking/cli/bff/utils/index.js +47 -0
- package/dist/js/treeshaking/cli/index.js +255 -0
- package/dist/js/treeshaking/cli/test.js +180 -0
- package/dist/js/treeshaking/constant.js +2 -0
- package/dist/js/treeshaking/index.js +3 -0
- package/dist/js/treeshaking/runtime-testing/app.js +90 -0
- package/dist/js/treeshaking/runtime-testing/base.js +4 -0
- package/dist/js/treeshaking/runtime-testing/customRender.js +41 -0
- package/dist/js/treeshaking/runtime-testing/index.js +2 -0
- package/dist/js/treeshaking/runtime-testing/reduck.js +89 -0
- package/dist/js/treeshaking/runtime-testing/request.js +51 -0
- package/dist/js/treeshaking/runtime-testing/resolvePlugins.js +46 -0
- 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/index.d.ts +0 -2
- 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 +8 -8
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _objectSpread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_defineProperty(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
import path from "path";
|
|
30
|
+
import { chalk } from "@modern-js/utils";
|
|
31
|
+
var isBFFProject = function(pwd) {
|
|
32
|
+
try {
|
|
33
|
+
var packageJson = require(path.join(pwd, "./package.json"));
|
|
34
|
+
var dependencies = packageJson.dependencies, devDependencies = packageJson.devDependencies;
|
|
35
|
+
var isBFF = Object.keys(_objectSpread({}, dependencies, devDependencies)).some(function(dependency) {
|
|
36
|
+
return dependency.includes("plugin-bff");
|
|
37
|
+
});
|
|
38
|
+
var isMWA = Object.keys(devDependencies).some(function(devDependency) {
|
|
39
|
+
return devDependency.includes("app-tools");
|
|
40
|
+
});
|
|
41
|
+
return isMWA && isBFF;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
console.log(chalk.red(error));
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
export { isBFFProject };
|
|
@@ -0,0 +1,255 @@
|
|
|
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
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
44
|
+
var f, y, t, g, _ = {
|
|
45
|
+
label: 0,
|
|
46
|
+
sent: function() {
|
|
47
|
+
if (t[0] & 1) throw t[1];
|
|
48
|
+
return t[1];
|
|
49
|
+
},
|
|
50
|
+
trys: [],
|
|
51
|
+
ops: []
|
|
52
|
+
};
|
|
53
|
+
return(g = {
|
|
54
|
+
next: verb(0),
|
|
55
|
+
"throw": verb(1),
|
|
56
|
+
"return": verb(2)
|
|
57
|
+
}, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
58
|
+
return this;
|
|
59
|
+
}), g);
|
|
60
|
+
function verb(n) {
|
|
61
|
+
return function(v) {
|
|
62
|
+
return step([
|
|
63
|
+
n,
|
|
64
|
+
v
|
|
65
|
+
]);
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function step(op) {
|
|
69
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
70
|
+
while(_)try {
|
|
71
|
+
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;
|
|
72
|
+
if (y = 0, t) op = [
|
|
73
|
+
op[0] & 2,
|
|
74
|
+
t.value
|
|
75
|
+
];
|
|
76
|
+
switch(op[0]){
|
|
77
|
+
case 0:
|
|
78
|
+
case 1:
|
|
79
|
+
t = op;
|
|
80
|
+
break;
|
|
81
|
+
case 4:
|
|
82
|
+
_.label++;
|
|
83
|
+
return {
|
|
84
|
+
value: op[1],
|
|
85
|
+
done: false
|
|
86
|
+
};
|
|
87
|
+
case 5:
|
|
88
|
+
_.label++;
|
|
89
|
+
y = op[1];
|
|
90
|
+
op = [
|
|
91
|
+
0
|
|
92
|
+
];
|
|
93
|
+
continue;
|
|
94
|
+
case 7:
|
|
95
|
+
op = _.ops.pop();
|
|
96
|
+
_.trys.pop();
|
|
97
|
+
continue;
|
|
98
|
+
default:
|
|
99
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
100
|
+
_ = 0;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
104
|
+
_.label = op[1];
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
108
|
+
_.label = t[1];
|
|
109
|
+
t = op;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
if (t && _.label < t[2]) {
|
|
113
|
+
_.label = t[2];
|
|
114
|
+
_.ops.push(op);
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
if (t[2]) _.ops.pop();
|
|
118
|
+
_.trys.pop();
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
op = body.call(thisArg, _);
|
|
122
|
+
} catch (e) {
|
|
123
|
+
op = [
|
|
124
|
+
6,
|
|
125
|
+
e
|
|
126
|
+
];
|
|
127
|
+
y = 0;
|
|
128
|
+
} finally{
|
|
129
|
+
f = t = 0;
|
|
130
|
+
}
|
|
131
|
+
if (op[0] & 5) throw op[1];
|
|
132
|
+
return {
|
|
133
|
+
value: op[0] ? op[1] : void 0,
|
|
134
|
+
done: true
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
import path from "path";
|
|
139
|
+
import { isApiOnly, mergeAlias, PLUGIN_SCHEMAS, createRuntimeExportsUtils } from "@modern-js/utils";
|
|
140
|
+
import { testingHooks, getModuleNameMapper, DEFAULT_RESOLVER_PATH } from "../base";
|
|
141
|
+
import { MODERNJS_CONFIG_KEY } from "../constant";
|
|
142
|
+
import testingBffPlugin from "./bff";
|
|
143
|
+
import test from "./test";
|
|
144
|
+
var mergeUserJestConfig = function(testUtils) {
|
|
145
|
+
var resolveJestConfig = testUtils.testConfig.jest;
|
|
146
|
+
if (resolveJestConfig && typeof resolveJestConfig !== "function") {
|
|
147
|
+
testUtils.mergeJestConfig(resolveJestConfig);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
var cli_default = function() {
|
|
151
|
+
var bffPlugin = testingBffPlugin();
|
|
152
|
+
return {
|
|
153
|
+
name: "@modern-js/plugin-testing",
|
|
154
|
+
usePlugins: [
|
|
155
|
+
bffPlugin
|
|
156
|
+
],
|
|
157
|
+
post: [
|
|
158
|
+
bffPlugin.name
|
|
159
|
+
],
|
|
160
|
+
registerHook: testingHooks,
|
|
161
|
+
setup: function(api) {
|
|
162
|
+
var testingExportsUtils;
|
|
163
|
+
return {
|
|
164
|
+
commands: function(param) {
|
|
165
|
+
var program = param.program;
|
|
166
|
+
program.command("test").allowUnknownOption().usage("<regexForTestFiles> --[options]").action(/*#__PURE__*/ _asyncToGenerator(function() {
|
|
167
|
+
return __generator(this, function(_state) {
|
|
168
|
+
switch(_state.label){
|
|
169
|
+
case 0:
|
|
170
|
+
return [
|
|
171
|
+
4,
|
|
172
|
+
test(api)
|
|
173
|
+
];
|
|
174
|
+
case 1:
|
|
175
|
+
_state.sent();
|
|
176
|
+
return [
|
|
177
|
+
2
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}));
|
|
182
|
+
},
|
|
183
|
+
validateSchema: function validateSchema() {
|
|
184
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-testing"];
|
|
185
|
+
},
|
|
186
|
+
config: function config() {
|
|
187
|
+
var appContext = api.useAppContext();
|
|
188
|
+
testingExportsUtils = createRuntimeExportsUtils(appContext.internalDirectory, "testing");
|
|
189
|
+
return {
|
|
190
|
+
source: {
|
|
191
|
+
alias: {
|
|
192
|
+
"@": path.join(appContext.appDirectory, "src"),
|
|
193
|
+
"@modern-js/runtime/testing": testingExportsUtils.getPath()
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
addRuntimeExports: function addRuntimeExports() {
|
|
199
|
+
var testingPath = path.resolve(__dirname, "../");
|
|
200
|
+
testingExportsUtils.addExport("export * from '".concat(testingPath, "'"));
|
|
201
|
+
},
|
|
202
|
+
jestConfig: function() {
|
|
203
|
+
var _ref = _asyncToGenerator(function(utils, next) {
|
|
204
|
+
var appContext, userConfig, apiOnly, alias;
|
|
205
|
+
return __generator(this, function(_state) {
|
|
206
|
+
switch(_state.label){
|
|
207
|
+
case 0:
|
|
208
|
+
appContext = api.useAppContext();
|
|
209
|
+
userConfig = api.useResolvedConfigContext();
|
|
210
|
+
return [
|
|
211
|
+
4,
|
|
212
|
+
isApiOnly(appContext.appDirectory)
|
|
213
|
+
];
|
|
214
|
+
case 1:
|
|
215
|
+
apiOnly = _state.sent();
|
|
216
|
+
if (apiOnly) {
|
|
217
|
+
return [
|
|
218
|
+
2,
|
|
219
|
+
next(utils)
|
|
220
|
+
];
|
|
221
|
+
}
|
|
222
|
+
alias = mergeAlias(userConfig.source.alias);
|
|
223
|
+
if (testingExportsUtils) {
|
|
224
|
+
alias["@modern-js/runtime/testing"] = [
|
|
225
|
+
testingExportsUtils.getPath()
|
|
226
|
+
];
|
|
227
|
+
}
|
|
228
|
+
utils.mergeJestConfig({
|
|
229
|
+
globals: _defineProperty({}, MODERNJS_CONFIG_KEY, userConfig),
|
|
230
|
+
moduleNameMapper: getModuleNameMapper(alias),
|
|
231
|
+
testEnvironment: "jsdom",
|
|
232
|
+
resolver: DEFAULT_RESOLVER_PATH,
|
|
233
|
+
rootDir: appContext.appDirectory || process.cwd(),
|
|
234
|
+
testMatch: [
|
|
235
|
+
"<rootDir>/src/**/*.test.[jt]s?(x)",
|
|
236
|
+
"<rootDir>/tests/**/*.test.[jt]s?(x)"
|
|
237
|
+
]
|
|
238
|
+
});
|
|
239
|
+
mergeUserJestConfig(utils);
|
|
240
|
+
return [
|
|
241
|
+
2,
|
|
242
|
+
next(utils)
|
|
243
|
+
];
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
return function(utils, next) {
|
|
248
|
+
return _ref.apply(this, arguments);
|
|
249
|
+
};
|
|
250
|
+
}()
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
export { cli_default as default, mergeUserJestConfig };
|
|
@@ -0,0 +1,180 @@
|
|
|
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 path from "path";
|
|
126
|
+
import { compiler } from "@modern-js/babel-compiler";
|
|
127
|
+
import { runTest } from "../base";
|
|
128
|
+
var test = function() {
|
|
129
|
+
var _ref = _asyncToGenerator(function(api) {
|
|
130
|
+
var ref, ref1, userConfig, appContext, jest, runtimeExportsPath;
|
|
131
|
+
return __generator(this, function(_state) {
|
|
132
|
+
switch(_state.label){
|
|
133
|
+
case 0:
|
|
134
|
+
userConfig = api.useResolvedConfigContext();
|
|
135
|
+
appContext = api.useAppContext();
|
|
136
|
+
userConfig.testing = userConfig.testing || {};
|
|
137
|
+
jest = userConfig.testing.jest || (userConfig === null || userConfig === void 0 ? void 0 : (ref = userConfig.tools) === null || ref === void 0 ? void 0 : ref.jest);
|
|
138
|
+
if (Array.isArray(jest)) {
|
|
139
|
+
userConfig.testing.jest = jest[0];
|
|
140
|
+
}
|
|
141
|
+
userConfig.testing.jest = userConfig.testing.jest || (userConfig === null || userConfig === void 0 ? void 0 : (ref1 = userConfig.tools) === null || ref1 === void 0 ? void 0 : ref1.jest);
|
|
142
|
+
runtimeExportsPath = path.join(appContext.internalDirectory, ".runtime-exports");
|
|
143
|
+
return [
|
|
144
|
+
4,
|
|
145
|
+
compiler({
|
|
146
|
+
sourceDir: runtimeExportsPath,
|
|
147
|
+
rootDir: runtimeExportsPath,
|
|
148
|
+
distDir: runtimeExportsPath,
|
|
149
|
+
quiet: true
|
|
150
|
+
}, {
|
|
151
|
+
presets: [
|
|
152
|
+
[
|
|
153
|
+
require.resolve("@babel/preset-env"),
|
|
154
|
+
{
|
|
155
|
+
modules: "cjs"
|
|
156
|
+
}
|
|
157
|
+
]
|
|
158
|
+
]
|
|
159
|
+
})
|
|
160
|
+
];
|
|
161
|
+
case 1:
|
|
162
|
+
_state.sent();
|
|
163
|
+
return [
|
|
164
|
+
4,
|
|
165
|
+
runTest(api, userConfig.testing)
|
|
166
|
+
];
|
|
167
|
+
case 2:
|
|
168
|
+
_state.sent();
|
|
169
|
+
return [
|
|
170
|
+
2
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
return function test(api) {
|
|
176
|
+
return _ref.apply(this, arguments);
|
|
177
|
+
};
|
|
178
|
+
}();
|
|
179
|
+
var test_default = test;
|
|
180
|
+
export { test_default as default };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
function _classCallCheck(instance, Constructor) {
|
|
2
|
+
if (!(instance instanceof Constructor)) {
|
|
3
|
+
throw new TypeError("Cannot call a class as a function");
|
|
4
|
+
}
|
|
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);
|
|
13
|
+
}
|
|
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;
|
|
30
|
+
}
|
|
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
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
ownKeys.forEach(function(key) {
|
|
43
|
+
_defineProperty(target, key, source[key]);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return target;
|
|
47
|
+
}
|
|
48
|
+
import { createApp } from "@modern-js/runtime";
|
|
49
|
+
import { MODERNJS_CONFIG_KEY } from "../constant";
|
|
50
|
+
import resolvePlugins from "./resolvePlugins";
|
|
51
|
+
var ModernRuntime = /*#__PURE__*/ function() {
|
|
52
|
+
"use strict";
|
|
53
|
+
function ModernRuntime(options) {
|
|
54
|
+
_classCallCheck(this, ModernRuntime);
|
|
55
|
+
_defineProperty(this, "options", void 0);
|
|
56
|
+
this.options = options;
|
|
57
|
+
}
|
|
58
|
+
_createClass(ModernRuntime, [
|
|
59
|
+
{
|
|
60
|
+
key: "init",
|
|
61
|
+
value: function init(options) {
|
|
62
|
+
this.options = options;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: "createApp",
|
|
67
|
+
value: function createApp1(props) {
|
|
68
|
+
var ref;
|
|
69
|
+
var ref1 = props || {}, entry = ref1.entry, children = ref1.children;
|
|
70
|
+
var runtimeFeatures = (ref = this.options) === null || ref === void 0 ? void 0 : ref.runtime;
|
|
71
|
+
if (entry) {
|
|
72
|
+
var ref2;
|
|
73
|
+
runtimeFeatures = _objectSpread({}, runtimeFeatures || {}, (ref2 = this.options.runtimeByEntries) === null || ref2 === void 0 ? void 0 : ref2[entry]);
|
|
74
|
+
}
|
|
75
|
+
var Component = function() {
|
|
76
|
+
if (!children) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
return children;
|
|
80
|
+
};
|
|
81
|
+
return createApp({
|
|
82
|
+
plugins: resolvePlugins(runtimeFeatures || {})
|
|
83
|
+
})(Component);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
]);
|
|
87
|
+
return ModernRuntime;
|
|
88
|
+
}();
|
|
89
|
+
var app_default = new ModernRuntime(global[MODERNJS_CONFIG_KEY] || {});
|
|
90
|
+
export { app_default as default };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
function _defineProperty(obj, key, value) {
|
|
2
|
+
if (key in obj) {
|
|
3
|
+
Object.defineProperty(obj, key, {
|
|
4
|
+
value: value,
|
|
5
|
+
enumerable: true,
|
|
6
|
+
configurable: true,
|
|
7
|
+
writable: true
|
|
8
|
+
});
|
|
9
|
+
} else {
|
|
10
|
+
obj[key] = value;
|
|
11
|
+
}
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
function _objectSpread(target) {
|
|
15
|
+
for(var i = 1; i < arguments.length; i++){
|
|
16
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
17
|
+
var ownKeys = Object.keys(source);
|
|
18
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
19
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
20
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
ownKeys.forEach(function(key) {
|
|
24
|
+
_defineProperty(target, key, source[key]);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return target;
|
|
28
|
+
}
|
|
29
|
+
import React from "react";
|
|
30
|
+
import { render } from "@testing-library/react";
|
|
31
|
+
import app from "./app";
|
|
32
|
+
var WrapModernProviders = function(props) {
|
|
33
|
+
return React.createElement(app.createApp(props));
|
|
34
|
+
};
|
|
35
|
+
var customRender = function(ui, options) {
|
|
36
|
+
return render(ui, _objectSpread({
|
|
37
|
+
wrapper: WrapModernProviders
|
|
38
|
+
}, options));
|
|
39
|
+
};
|
|
40
|
+
var customRender_default = customRender;
|
|
41
|
+
export { customRender_default as default };
|