@rstest/core 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/285.js +1 -1
- package/dist/353.js +10 -8
- package/dist/355.js +1 -1
- package/dist/44.js +375 -0
- package/dist/{992.js → 612.js} +207 -18
- package/dist/{502.js → 723.js} +2 -2
- package/dist/867.js +14 -8
- package/dist/{202.js → 965.js} +43 -33
- package/dist/cli.js +45 -18
- package/dist/cssFilterLoader.mjs +22 -0
- package/dist/worker.js +61 -25
- package/dist-types/node.d.ts +6 -1
- package/dist-types/public.d.ts +20 -11
- package/dist-types/worker.d.ts +7 -2
- package/package.json +12 -7
package/dist/{992.js → 612.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export const __webpack_ids__ = [
|
|
2
|
-
"
|
|
2
|
+
"612"
|
|
3
3
|
];
|
|
4
4
|
export const __webpack_modules__ = {
|
|
5
5
|
"./src/core/rsbuild.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
@@ -11,6 +11,38 @@ export const __webpack_modules__ = {
|
|
|
11
11
|
var core_ = __webpack_require__("@rsbuild/core");
|
|
12
12
|
var external_pathe_ = __webpack_require__("pathe");
|
|
13
13
|
var utils = __webpack_require__("./src/utils/index.ts");
|
|
14
|
+
var external_node_path_ = __webpack_require__("node:path");
|
|
15
|
+
var external_node_url_ = __webpack_require__("node:url");
|
|
16
|
+
const PLUGIN_CSS_FILTER = 'rstest:css-filter';
|
|
17
|
+
const css_filter_dirname = external_node_path_["default"].dirname((0, external_node_url_.fileURLToPath)(import.meta.url));
|
|
18
|
+
const pluginCSSFilter = ()=>({
|
|
19
|
+
name: PLUGIN_CSS_FILTER,
|
|
20
|
+
setup (api) {
|
|
21
|
+
api.modifyBundlerChain({
|
|
22
|
+
order: 'post',
|
|
23
|
+
handler: async (chain, { target, CHAIN_ID, environment })=>{
|
|
24
|
+
const emitCss = environment.config.output.emitCss ?? 'web' === target;
|
|
25
|
+
if (!emitCss) {
|
|
26
|
+
const ruleIds = [
|
|
27
|
+
CHAIN_ID.RULE.CSS,
|
|
28
|
+
CHAIN_ID.RULE.SASS,
|
|
29
|
+
CHAIN_ID.RULE.LESS,
|
|
30
|
+
CHAIN_ID.RULE.STYLUS
|
|
31
|
+
];
|
|
32
|
+
for (const ruleId of ruleIds){
|
|
33
|
+
if (!chain.module.rules.has(ruleId)) continue;
|
|
34
|
+
const rule = chain.module.rule(ruleId);
|
|
35
|
+
if (!rule.uses.has(CHAIN_ID.USE.CSS)) continue;
|
|
36
|
+
const cssLoaderOptions = rule.use(CHAIN_ID.USE.CSS).get('options');
|
|
37
|
+
if (cssLoaderOptions.modules && ('object' != typeof cssLoaderOptions.modules || false !== cssLoaderOptions.modules.auto)) rule.use('rstest-css-pre-filter').loader(external_node_path_["default"].join(css_filter_dirname, 'cssFilterLoader.mjs')).options({
|
|
38
|
+
modules: cssLoaderOptions.modules
|
|
39
|
+
}).after(ruleId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
14
46
|
class TestFileWatchPlugin {
|
|
15
47
|
contextToWatch = null;
|
|
16
48
|
constructor(contextToWatch){
|
|
@@ -47,8 +79,8 @@ export const __webpack_modules__ = {
|
|
|
47
79
|
config.watchOptions.ignored = '**/**';
|
|
48
80
|
const sourceEntries = await globTestSourceEntries();
|
|
49
81
|
config.entry = {
|
|
50
|
-
...
|
|
51
|
-
...
|
|
82
|
+
...setupFiles,
|
|
83
|
+
...sourceEntries
|
|
52
84
|
};
|
|
53
85
|
}
|
|
54
86
|
});
|
|
@@ -73,12 +105,155 @@ export const __webpack_modules__ = {
|
|
|
73
105
|
});
|
|
74
106
|
}
|
|
75
107
|
};
|
|
108
|
+
class MockRuntimeRspackPlugin {
|
|
109
|
+
apply(compiler) {
|
|
110
|
+
const { RuntimeModule } = compiler.webpack;
|
|
111
|
+
class RetestImportRuntimeModule extends RuntimeModule {
|
|
112
|
+
constructor(){
|
|
113
|
+
super('rstest runtime');
|
|
114
|
+
}
|
|
115
|
+
generate() {
|
|
116
|
+
return `
|
|
117
|
+
if (typeof __webpack_require__ === 'undefined') {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const originalRequire = __webpack_require__;
|
|
122
|
+
__webpack_require__ = function(...args) {
|
|
123
|
+
try {
|
|
124
|
+
return originalRequire(...args);
|
|
125
|
+
} catch (e) {
|
|
126
|
+
const errMsg = e.message ?? e.toString();
|
|
127
|
+
if (errMsg.includes('__webpack_modules__[moduleId] is not a function')) {
|
|
128
|
+
throw new Error(\`Cannot find module '\${args[0]}'\`)
|
|
129
|
+
}
|
|
130
|
+
throw e;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
Object.keys(originalRequire).forEach(key => {
|
|
135
|
+
__webpack_require__[key] = originalRequire[key];
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
__webpack_require__.rstest_original_modules = {};
|
|
139
|
+
|
|
140
|
+
// TODO: Remove "reset_modules" in next Rspack version.
|
|
141
|
+
__webpack_require__.rstest_reset_modules = __webpack_require__.reset_modules = () => {
|
|
142
|
+
const mockedIds = Object.keys(__webpack_require__.rstest_original_modules)
|
|
143
|
+
Object.keys(__webpack_module_cache__).forEach(id => {
|
|
144
|
+
// Do not reset mocks registry.
|
|
145
|
+
if (!mockedIds.includes(id)) {
|
|
146
|
+
delete __webpack_module_cache__[id];
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// TODO: Remove "unmock" in next Rspack version.
|
|
152
|
+
__webpack_require__.rstest_unmock = __webpack_require__.unmock = (id) => {
|
|
153
|
+
delete __webpack_module_cache__[id]
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// TODO: Remove "require_actual" and "import_actual" in next Rspack version.
|
|
157
|
+
__webpack_require__.rstest_require_actual = __webpack_require__.rstest_import_actual = __webpack_require__.require_actual = __webpack_require__.import_actual = (id) => {
|
|
158
|
+
const originalModule = __webpack_require__.rstest_original_modules[id];
|
|
159
|
+
// Use fallback module if the module is not mocked.
|
|
160
|
+
const fallbackMod = __webpack_require__(id);
|
|
161
|
+
return originalModule ? originalModule : fallbackMod;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// TODO: Remove "set_mock" in next Rspack version.
|
|
165
|
+
__webpack_require__.rstest_set_mock = __webpack_require__.set_mock = (id, modFactory) => {
|
|
166
|
+
let requiredModule = undefined
|
|
167
|
+
try {
|
|
168
|
+
requiredModule = __webpack_require__(id);
|
|
169
|
+
} catch {
|
|
170
|
+
// TODO: non-resolved module
|
|
171
|
+
} finally {
|
|
172
|
+
__webpack_require__.rstest_original_modules[id] = requiredModule;
|
|
173
|
+
}
|
|
174
|
+
if (typeof modFactory === 'string' || typeof modFactory === 'number') {
|
|
175
|
+
__webpack_module_cache__[id] = { exports: __webpack_require__(modFactory) };
|
|
176
|
+
} else if (typeof modFactory === 'function') {
|
|
177
|
+
let exports = modFactory();
|
|
178
|
+
__webpack_require__.r(exports);
|
|
179
|
+
__webpack_module_cache__[id] = { exports, id, loaded: true };
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
compiler.hooks.thisCompilation.tap('CustomPlugin', (compilation)=>{
|
|
186
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap('CustomPlugin', (chunk)=>{
|
|
187
|
+
compilation.addRuntimeModule(chunk, new RetestImportRuntimeModule());
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
const pluginMockRuntime = {
|
|
193
|
+
name: 'rstest:mock-runtime',
|
|
194
|
+
setup: (api)=>{
|
|
195
|
+
api.modifyRspackConfig(async (config)=>{
|
|
196
|
+
config.plugins.push(new MockRuntimeRspackPlugin());
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
class RstestCacheControlPlugin {
|
|
201
|
+
apply(compiler) {
|
|
202
|
+
const { RuntimeModule } = compiler.webpack;
|
|
203
|
+
class RetestCacheControlModule extends RuntimeModule {
|
|
204
|
+
constructor(){
|
|
205
|
+
super('rstest_cache_control');
|
|
206
|
+
}
|
|
207
|
+
generate() {
|
|
208
|
+
return `
|
|
209
|
+
global.setupIds = [];
|
|
210
|
+
|
|
211
|
+
function __rstest_clean_core_cache__() {
|
|
212
|
+
if (typeof __webpack_require__ === 'undefined') {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
delete __webpack_module_cache__['@rstest/core'];
|
|
216
|
+
|
|
217
|
+
global.setupIds.forEach((id) => {
|
|
218
|
+
delete __webpack_module_cache__[id];
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
global.__rstest_clean_core_cache__ = __rstest_clean_core_cache__;
|
|
223
|
+
`;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
compiler.hooks.thisCompilation.tap('CustomPlugin', (compilation)=>{
|
|
227
|
+
compilation.hooks.additionalTreeRuntimeRequirements.tap('CustomPlugin', (chunk)=>{
|
|
228
|
+
compilation.addRuntimeModule(chunk, new RetestCacheControlModule());
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
const pluginCacheControl = (setupFiles)=>({
|
|
234
|
+
name: 'rstest:cache-control',
|
|
235
|
+
setup: (api)=>{
|
|
236
|
+
api.transform({
|
|
237
|
+
test: setupFiles
|
|
238
|
+
}, ({ code })=>({
|
|
239
|
+
code: `
|
|
240
|
+
${code}
|
|
241
|
+
if (global.setupIds && __webpack_module__.id) {
|
|
242
|
+
global.setupIds.push(__webpack_module__.id);
|
|
243
|
+
}
|
|
244
|
+
`
|
|
245
|
+
}));
|
|
246
|
+
api.modifyRspackConfig(async (config)=>{
|
|
247
|
+
config.plugins.push(new RstestCacheControlPlugin());
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|
|
76
251
|
const isMultiCompiler = (compiler)=>'compilers' in compiler && Array.isArray(compiler.compilers);
|
|
77
252
|
const autoExternalNodeModules = ({ context, request, dependencyType, getResolve }, callback)=>{
|
|
78
253
|
if (!request) return callback();
|
|
79
254
|
if (request.startsWith('@swc/helpers/')) return callback();
|
|
80
255
|
const doExternal = (externalPath = request)=>{
|
|
81
|
-
callback(void 0, externalPath, 'commonjs' === dependencyType ? 'commonjs' : '
|
|
256
|
+
callback(void 0, externalPath, 'commonjs' === dependencyType ? 'commonjs' : 'import');
|
|
82
257
|
};
|
|
83
258
|
const resolver = getResolve?.();
|
|
84
259
|
if (!resolver) return callback();
|
|
@@ -98,7 +273,7 @@ export const __webpack_modules__ = {
|
|
|
98
273
|
else callback();
|
|
99
274
|
};
|
|
100
275
|
const prepareRsbuild = async (context, globTestSourceEntries, setupFiles)=>{
|
|
101
|
-
const { command, normalizedConfig: { name, plugins, resolve, source, output, tools, testEnvironment, performance, dev = {} } } = context;
|
|
276
|
+
const { command, normalizedConfig: { isolate, name, plugins, resolve, source, output, tools, testEnvironment, performance, dev = {} } } = context;
|
|
102
277
|
const debugMode = (0, utils.L1)();
|
|
103
278
|
core_.logger.level = debugMode ? 'verbose' : 'error';
|
|
104
279
|
const writeToDisk = dev.writeToDisk || debugMode;
|
|
@@ -112,7 +287,13 @@ export const __webpack_modules__ = {
|
|
|
112
287
|
server: {
|
|
113
288
|
printUrls: false,
|
|
114
289
|
strictPort: false,
|
|
115
|
-
middlewareMode: true
|
|
290
|
+
middlewareMode: true,
|
|
291
|
+
compress: false,
|
|
292
|
+
cors: false,
|
|
293
|
+
publicDir: false
|
|
294
|
+
},
|
|
295
|
+
dev: {
|
|
296
|
+
hmr: false
|
|
116
297
|
},
|
|
117
298
|
performance,
|
|
118
299
|
environments: {
|
|
@@ -143,9 +324,9 @@ export const __webpack_modules__ = {
|
|
|
143
324
|
config.output.devtoolModuleFilenameTemplate = '[absolute-resource-path]';
|
|
144
325
|
config.plugins.push(new core_.rspack.experiments.RstestPlugin({
|
|
145
326
|
injectModulePathName: true,
|
|
146
|
-
hoistMockModule: true,
|
|
147
327
|
importMetaPathName: true,
|
|
148
|
-
|
|
328
|
+
hoistMockModule: true,
|
|
329
|
+
manualMockRoot: external_pathe_["default"].resolve(context.rootPath, '__mocks__')
|
|
149
330
|
}));
|
|
150
331
|
config.externals = (0, utils.XQ)(config.externals) || [];
|
|
151
332
|
config.externals.unshift({
|
|
@@ -162,12 +343,12 @@ export const __webpack_modules__ = {
|
|
|
162
343
|
requireAsExpression: false,
|
|
163
344
|
...config.module.parser.javascript || {}
|
|
164
345
|
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
346
|
+
config.resolve ??= {};
|
|
347
|
+
config.resolve.extensions ??= [];
|
|
348
|
+
config.resolve.extensions.push('.cjs');
|
|
349
|
+
if ('node' === testEnvironment && (0, utils.mP)().major < 20) config.resolve.mainFields = config.resolve.mainFields?.filter((filed)=>'module' !== filed) || [
|
|
350
|
+
'main'
|
|
351
|
+
];
|
|
171
352
|
config.optimization = {
|
|
172
353
|
moduleIds: 'named',
|
|
173
354
|
chunkIds: 'named',
|
|
@@ -180,6 +361,8 @@ export const __webpack_modules__ = {
|
|
|
180
361
|
},
|
|
181
362
|
plugins: [
|
|
182
363
|
pluginIgnoreResolveError,
|
|
364
|
+
pluginMockRuntime,
|
|
365
|
+
pluginCSSFilter(),
|
|
183
366
|
pluginEntryWatch({
|
|
184
367
|
globTestSourceEntries,
|
|
185
368
|
setupFiles,
|
|
@@ -190,6 +373,9 @@ export const __webpack_modules__ = {
|
|
|
190
373
|
}
|
|
191
374
|
}
|
|
192
375
|
});
|
|
376
|
+
if (!isolate) rsbuildInstance.addPlugins([
|
|
377
|
+
pluginCacheControl(Object.values(setupFiles))
|
|
378
|
+
]);
|
|
193
379
|
return rsbuildInstance;
|
|
194
380
|
};
|
|
195
381
|
const createRsbuildServer = async ({ name, globTestSourceEntries, setupFiles, rsbuildInstance, normalizedConfig })=>{
|
|
@@ -405,8 +591,9 @@ export const __webpack_modules__ = {
|
|
|
405
591
|
...execArgv,
|
|
406
592
|
'--experimental-vm-modules',
|
|
407
593
|
'--experimental-import-meta-resolve',
|
|
408
|
-
'--no-warnings'
|
|
409
|
-
|
|
594
|
+
'--no-warnings',
|
|
595
|
+
(0, utils.PA)() ? '--experimental-detect-module' : void 0
|
|
596
|
+
].filter(Boolean),
|
|
410
597
|
env: {
|
|
411
598
|
NODE_ENV: 'test',
|
|
412
599
|
FORCE_COLOR: '1',
|
|
@@ -414,10 +601,11 @@ export const __webpack_modules__ = {
|
|
|
414
601
|
}
|
|
415
602
|
});
|
|
416
603
|
const { updateSnapshot } = context.snapshotManager.options;
|
|
417
|
-
const { testNamePattern, testTimeout, passWithNoTests, retry, globals, clearMocks, resetMocks, restoreMocks, unstubEnvs, unstubGlobals, maxConcurrency, printConsoleTrace, disableConsoleIntercept, testEnvironment } = context.normalizedConfig;
|
|
604
|
+
const { testNamePattern, testTimeout, passWithNoTests, retry, globals, clearMocks, resetMocks, restoreMocks, unstubEnvs, unstubGlobals, maxConcurrency, printConsoleTrace, disableConsoleIntercept, testEnvironment, hookTimeout } = context.normalizedConfig;
|
|
418
605
|
const runtimeConfig = {
|
|
419
606
|
testNamePattern,
|
|
420
607
|
testTimeout,
|
|
608
|
+
hookTimeout,
|
|
421
609
|
passWithNoTests,
|
|
422
610
|
retry,
|
|
423
611
|
globals,
|
|
@@ -429,7 +617,8 @@ export const __webpack_modules__ = {
|
|
|
429
617
|
maxConcurrency,
|
|
430
618
|
printConsoleTrace,
|
|
431
619
|
disableConsoleIntercept,
|
|
432
|
-
testEnvironment
|
|
620
|
+
testEnvironment,
|
|
621
|
+
isolate
|
|
433
622
|
};
|
|
434
623
|
const rpcMethods = {
|
|
435
624
|
onTestCaseResult: async (result)=>{
|
package/dist/{502.js → 723.js}
RENAMED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export const __webpack_ids__ = [
|
|
2
|
-
"
|
|
2
|
+
"723"
|
|
3
3
|
];
|
|
4
4
|
export const __webpack_modules__ = {
|
|
5
|
-
"../../node_modules/.pnpm/@jridgewell+trace-mapping@0.3.
|
|
5
|
+
"../../node_modules/.pnpm/@jridgewell+trace-mapping@0.3.29/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.mjs": function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
6
6
|
__webpack_require__.d(__webpack_exports__, {
|
|
7
7
|
s7: ()=>TraceMap,
|
|
8
8
|
Sk: ()=>originalPositionFor
|
package/dist/867.js
CHANGED
|
@@ -927,11 +927,12 @@ export const __webpack_modules__ = {
|
|
|
927
927
|
testPath;
|
|
928
928
|
collectStatus = 'lazy';
|
|
929
929
|
currentCollectList = [];
|
|
930
|
-
defaultHookTimeout
|
|
930
|
+
defaultHookTimeout;
|
|
931
931
|
defaultTestTimeout;
|
|
932
|
-
constructor({ testPath, testTimeout }){
|
|
932
|
+
constructor({ testPath, testTimeout, hookTimeout }){
|
|
933
933
|
this.testPath = testPath;
|
|
934
934
|
this.defaultTestTimeout = testTimeout;
|
|
935
|
+
this.defaultHookTimeout = hookTimeout;
|
|
935
936
|
}
|
|
936
937
|
afterAll(fn, timeout = this.defaultHookTimeout) {
|
|
937
938
|
const currentSuite = this.getCurrentSuite();
|
|
@@ -1139,10 +1140,11 @@ export const __webpack_modules__ = {
|
|
|
1139
1140
|
throw new Error('Expect to find a suite, but got undefined');
|
|
1140
1141
|
}
|
|
1141
1142
|
}
|
|
1142
|
-
const createRuntimeAPI = ({ testPath, testTimeout })=>{
|
|
1143
|
+
const createRuntimeAPI = ({ testPath, testTimeout, hookTimeout })=>{
|
|
1143
1144
|
const runtimeInstance = new RunnerRuntime({
|
|
1144
1145
|
testPath,
|
|
1145
|
-
testTimeout
|
|
1146
|
+
testTimeout,
|
|
1147
|
+
hookTimeout
|
|
1146
1148
|
});
|
|
1147
1149
|
const createTestAPI = (options = {})=>{
|
|
1148
1150
|
const testFn = (name, fn, timeout)=>runtimeInstance.it({
|
|
@@ -1290,10 +1292,11 @@ export const __webpack_modules__ = {
|
|
|
1290
1292
|
};
|
|
1291
1293
|
};
|
|
1292
1294
|
function createRunner({ workerState }) {
|
|
1293
|
-
const { testPath, runtimeConfig: { testTimeout, testNamePattern } } = workerState;
|
|
1295
|
+
const { testPath, runtimeConfig: { testTimeout, testNamePattern, hookTimeout } } = workerState;
|
|
1294
1296
|
const runtime = createRuntimeAPI({
|
|
1295
1297
|
testPath,
|
|
1296
|
-
testTimeout
|
|
1298
|
+
testTimeout,
|
|
1299
|
+
hookTimeout
|
|
1297
1300
|
});
|
|
1298
1301
|
const testRunner = new TestRunner();
|
|
1299
1302
|
return {
|
|
@@ -1594,10 +1597,13 @@ export const __webpack_modules__ = {
|
|
|
1594
1597
|
return rstest;
|
|
1595
1598
|
},
|
|
1596
1599
|
mock: ()=>{},
|
|
1600
|
+
mockRequire: ()=>{},
|
|
1597
1601
|
doMock: ()=>{},
|
|
1598
|
-
|
|
1599
|
-
|
|
1602
|
+
doMockRequire: ()=>{},
|
|
1603
|
+
unmock: ()=>{},
|
|
1604
|
+
doUnmock: ()=>{},
|
|
1600
1605
|
importMock: async ()=>({}),
|
|
1606
|
+
requireMock: ()=>({}),
|
|
1601
1607
|
importActual: async ()=>({}),
|
|
1602
1608
|
requireActual: ()=>({}),
|
|
1603
1609
|
resetModules: ()=>rstest,
|
package/dist/{202.js → 965.js}
RENAMED
|
@@ -1,11 +1,48 @@
|
|
|
1
1
|
export const __webpack_ids__ = [
|
|
2
|
-
"
|
|
2
|
+
"965"
|
|
3
3
|
];
|
|
4
4
|
export const __webpack_modules__ = {
|
|
5
5
|
"./src/runtime/worker/env/jsdom.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
6
6
|
__webpack_require__.d(__webpack_exports__, {
|
|
7
7
|
environment: ()=>environment
|
|
8
8
|
});
|
|
9
|
+
var _utils__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./src/runtime/worker/env/utils.ts");
|
|
10
|
+
const environment = {
|
|
11
|
+
name: 'jsdom',
|
|
12
|
+
async setup (global, { jsdom = {} }) {
|
|
13
|
+
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import("jsdom");
|
|
14
|
+
const { html = '<!DOCTYPE html>', userAgent, url = 'http://localhost:3000', contentType = 'text/html', pretendToBeVisual = true, includeNodeLocations = false, runScripts = 'dangerously', resources, console = false, cookieJar = false, ...restOptions } = jsdom;
|
|
15
|
+
const dom = new JSDOM(html, {
|
|
16
|
+
pretendToBeVisual,
|
|
17
|
+
resources: resources ?? (userAgent ? new ResourceLoader({
|
|
18
|
+
userAgent
|
|
19
|
+
}) : void 0),
|
|
20
|
+
runScripts,
|
|
21
|
+
url,
|
|
22
|
+
virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
|
|
23
|
+
cookieJar: cookieJar ? new CookieJar() : void 0,
|
|
24
|
+
includeNodeLocations,
|
|
25
|
+
contentType,
|
|
26
|
+
userAgent,
|
|
27
|
+
...restOptions
|
|
28
|
+
});
|
|
29
|
+
const cleanupGlobal = (0, _utils__WEBPACK_IMPORTED_MODULE_0__.Nc)(global, dom.window);
|
|
30
|
+
const cleanupHandler = (0, _utils__WEBPACK_IMPORTED_MODULE_0__.xp)(global);
|
|
31
|
+
return {
|
|
32
|
+
teardown () {
|
|
33
|
+
cleanupHandler();
|
|
34
|
+
dom.window.close();
|
|
35
|
+
cleanupGlobal();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
"./src/runtime/worker/env/utils.ts": function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
42
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
43
|
+
xp: ()=>addDefaultErrorHandler,
|
|
44
|
+
Nc: ()=>installGlobal
|
|
45
|
+
});
|
|
9
46
|
const LIVING_KEYS = [
|
|
10
47
|
'DOMException',
|
|
11
48
|
'URL',
|
|
@@ -273,13 +310,16 @@ export const __webpack_modules__ = {
|
|
|
273
310
|
return true;
|
|
274
311
|
}));
|
|
275
312
|
}
|
|
313
|
+
function isClassLike(name) {
|
|
314
|
+
return name[0] === name[0]?.toUpperCase();
|
|
315
|
+
}
|
|
276
316
|
function installGlobal(global, win, options = {}) {
|
|
317
|
+
const { bindFunctions = true } = options || {};
|
|
277
318
|
const keys = getWindowKeys(global, win, options.additionalKeys);
|
|
278
|
-
const isClassLike = (name)=>name[0] === name[0]?.toUpperCase();
|
|
279
319
|
const originals = new Map();
|
|
280
320
|
const overrides = new Map();
|
|
281
321
|
for (const key of keys){
|
|
282
|
-
const boundFunction = 'function'
|
|
322
|
+
const boundFunction = bindFunctions && 'function' == typeof win[key] && !isClassLike(key) && win[key].bind(win);
|
|
283
323
|
if (key in global) originals.set(key, global[key]);
|
|
284
324
|
Object.defineProperty(global, key, {
|
|
285
325
|
get () {
|
|
@@ -331,35 +371,5 @@ export const __webpack_modules__ = {
|
|
|
331
371
|
window.removeEventListener('error', throwUnhandledError);
|
|
332
372
|
};
|
|
333
373
|
}
|
|
334
|
-
const environment = {
|
|
335
|
-
name: 'jsdom',
|
|
336
|
-
async setup (global, { jsdom = {} }) {
|
|
337
|
-
const { CookieJar, JSDOM, ResourceLoader, VirtualConsole } = await import("jsdom");
|
|
338
|
-
const { html = '<!DOCTYPE html>', userAgent, url = 'http://localhost:3000', contentType = 'text/html', pretendToBeVisual = true, includeNodeLocations = false, runScripts = 'dangerously', resources, console = false, cookieJar = false, ...restOptions } = jsdom;
|
|
339
|
-
const dom = new JSDOM(html, {
|
|
340
|
-
pretendToBeVisual,
|
|
341
|
-
resources: resources ?? (userAgent ? new ResourceLoader({
|
|
342
|
-
userAgent
|
|
343
|
-
}) : void 0),
|
|
344
|
-
runScripts,
|
|
345
|
-
url,
|
|
346
|
-
virtualConsole: console && global.console ? new VirtualConsole().sendTo(global.console) : void 0,
|
|
347
|
-
cookieJar: cookieJar ? new CookieJar() : void 0,
|
|
348
|
-
includeNodeLocations,
|
|
349
|
-
contentType,
|
|
350
|
-
userAgent,
|
|
351
|
-
...restOptions
|
|
352
|
-
});
|
|
353
|
-
const cleanupGlobal = installGlobal(global, dom.window);
|
|
354
|
-
const cleanupHandler = addDefaultErrorHandler(global);
|
|
355
|
-
return {
|
|
356
|
-
teardown () {
|
|
357
|
-
cleanupHandler();
|
|
358
|
-
dom.window.close();
|
|
359
|
-
cleanupGlobal();
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
};
|
|
364
374
|
}
|
|
365
375
|
};
|
package/dist/cli.js
CHANGED
|
@@ -2238,6 +2238,7 @@ var __webpack_modules__ = {
|
|
|
2238
2238
|
passWithNoTests: false,
|
|
2239
2239
|
update: false,
|
|
2240
2240
|
testTimeout: 5000,
|
|
2241
|
+
hookTimeout: 10000,
|
|
2241
2242
|
testEnvironment: 'node',
|
|
2242
2243
|
retry: 0,
|
|
2243
2244
|
reporters: [
|
|
@@ -2292,6 +2293,7 @@ var __webpack_modules__ = {
|
|
|
2292
2293
|
$_: ()=>picocolors__WEBPACK_IMPORTED_MODULE_2___default.a,
|
|
2293
2294
|
AS: ()=>prettyTime,
|
|
2294
2295
|
H: ()=>parsePosix,
|
|
2296
|
+
PA: ()=>needFlagExperimentalDetectModule,
|
|
2295
2297
|
Tn: ()=>NODE_BUILTINS,
|
|
2296
2298
|
XQ: ()=>castArray,
|
|
2297
2299
|
Yz: ()=>getTaskNameWithPrefix,
|
|
@@ -2331,18 +2333,23 @@ var __webpack_modules__ = {
|
|
|
2331
2333
|
}
|
|
2332
2334
|
return String(error);
|
|
2333
2335
|
}
|
|
2334
|
-
const prettyTime = (milliseconds
|
|
2335
|
-
|
|
2336
|
-
const indent = shouldFormat ? ' ' : '';
|
|
2337
|
-
if (milliseconds < 1000) return `${Math.round(milliseconds)}${indent}ms`;
|
|
2336
|
+
const prettyTime = (milliseconds)=>{
|
|
2337
|
+
if (milliseconds < 1000) return `${Math.round(milliseconds)}ms`;
|
|
2338
2338
|
const seconds = milliseconds / 1000;
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2339
|
+
const getSecond = (seconds, needDigits)=>{
|
|
2340
|
+
if (!needDigits || seconds === Math.ceil(seconds)) return `${Math.round(seconds).toString()}s`;
|
|
2341
|
+
const digits = seconds < 10 ? seconds >= 0.01 ? 2 : 3 : 1;
|
|
2342
|
+
return `${seconds.toFixed(digits)}s`;
|
|
2343
|
+
};
|
|
2344
|
+
const minutes = Math.floor(seconds / 60);
|
|
2345
|
+
const secondsRemainder = seconds % 60;
|
|
2346
|
+
let time = '';
|
|
2347
|
+
if (minutes > 0) time += `${minutes}m`;
|
|
2348
|
+
if (secondsRemainder > 0) {
|
|
2349
|
+
if (minutes > 0) time += ' ';
|
|
2350
|
+
time += getSecond(secondsRemainder, !minutes);
|
|
2342
2351
|
}
|
|
2343
|
-
|
|
2344
|
-
const minutes = seconds / 60;
|
|
2345
|
-
return `${format(minutes.toFixed(2))}${indent}m`;
|
|
2352
|
+
return time;
|
|
2346
2353
|
};
|
|
2347
2354
|
const getTaskNames = (test)=>(test.parentNames || []).concat(test.name).filter(Boolean);
|
|
2348
2355
|
const getTaskNameWithPrefix = (test, delimiter = _constants__WEBPACK_IMPORTED_MODULE_1__.Qd)=>getTaskNames(test).join(` ${delimiter} `);
|
|
@@ -2355,11 +2362,27 @@ var __webpack_modules__ = {
|
|
|
2355
2362
|
testNamePattern: testNamePattern && 'string' != typeof testNamePattern ? wrapRegex(testNamePattern) : testNamePattern
|
|
2356
2363
|
};
|
|
2357
2364
|
};
|
|
2358
|
-
const getNodeVersion = ()=>
|
|
2359
|
-
|
|
2360
|
-
0,
|
|
2361
|
-
|
|
2362
|
-
|
|
2365
|
+
const getNodeVersion = ()=>{
|
|
2366
|
+
if ('string' == typeof process.versions?.node) {
|
|
2367
|
+
const [major = 0, minor = 0, patch = 0] = process.versions.node.split('.').map(Number);
|
|
2368
|
+
return {
|
|
2369
|
+
major,
|
|
2370
|
+
minor,
|
|
2371
|
+
patch
|
|
2372
|
+
};
|
|
2373
|
+
}
|
|
2374
|
+
return {
|
|
2375
|
+
major: 0,
|
|
2376
|
+
minor: 0,
|
|
2377
|
+
patch: 0
|
|
2378
|
+
};
|
|
2379
|
+
};
|
|
2380
|
+
const needFlagExperimentalDetectModule = ()=>{
|
|
2381
|
+
const { major, minor } = getNodeVersion();
|
|
2382
|
+
if (20 === major && minor >= 10) return true;
|
|
2383
|
+
if (22 === major && minor < 7) return true;
|
|
2384
|
+
return false;
|
|
2385
|
+
};
|
|
2363
2386
|
const NODE_BUILTINS = [
|
|
2364
2387
|
'assert',
|
|
2365
2388
|
'assert/strict',
|
|
@@ -2434,6 +2457,7 @@ var __webpack_modules__ = {
|
|
|
2434
2457
|
Tn: ()=>helper.Tn,
|
|
2435
2458
|
$_: ()=>helper.$_,
|
|
2436
2459
|
Yz: ()=>helper.Yz,
|
|
2460
|
+
PA: ()=>helper.PA,
|
|
2437
2461
|
L1: ()=>logger.L,
|
|
2438
2462
|
v8: ()=>helper.v8,
|
|
2439
2463
|
Qd: ()=>constants.Qd,
|
|
@@ -3647,13 +3671,13 @@ function prepareCli() {
|
|
|
3647
3671
|
if (!npm_execpath || npm_execpath.includes('npx-cli.js') || npm_execpath.includes('.bun')) console.log();
|
|
3648
3672
|
}
|
|
3649
3673
|
function showRstest() {
|
|
3650
|
-
logger.k.greet(" Rstest v0.0.
|
|
3674
|
+
logger.k.greet(" Rstest v0.0.6");
|
|
3651
3675
|
logger.k.log('');
|
|
3652
3676
|
}
|
|
3653
3677
|
const applyCommonOptions = (cli)=>{
|
|
3654
3678
|
cli.option('-c, --config <config>', 'Specify the configuration file, can be a relative or absolute path').option('--config-loader <loader>', 'Specify the loader to load the config file, can be `jiti` or `native`', {
|
|
3655
3679
|
default: 'jiti'
|
|
3656
|
-
}).option('-r, --root <root>', 'Specify the project root directory, can be an absolute path or a path relative to cwd').option('--globals', 'Provide global APIs').option('-u, --update', 'Update snapshot files').option('--passWithNoTests', 'Allows the test suite to pass when no files are found').option('--printConsoleTrace', 'Print console traces when calling any console method').option('--disableConsoleIntercept', 'Disable console intercept').option('--slowTestThreshold <value>', 'The number of milliseconds after which a test or suite is considered slow').option('-t, --testNamePattern <value>', 'Run only tests with a name that matches the regex').option('--testEnvironment <name>', 'The environment that will be used for testing').option('--testTimeout <value>', 'Timeout of a test in milliseconds').option('--retry <retry>', 'Number of times to retry a test if it fails').option('--maxConcurrency <value>', 'Maximum number of concurrent tests').option('--clearMocks', 'Automatically clear mock calls, instances, contexts and results before every test').option('--resetMocks', 'Automatically reset mock state before every test').option('--restoreMocks', 'Automatically restore mock state and implementation before every test').option('--unstubGlobals', 'Restores all global variables that were changed with `rstest.stubGlobal` before every test').option('--unstubEnvs', 'Restores all `process.env` values that were changed with `rstest.stubEnv` before every test');
|
|
3680
|
+
}).option('-r, --root <root>', 'Specify the project root directory, can be an absolute path or a path relative to cwd').option('--globals', 'Provide global APIs').option('--isolate', 'Run tests in an isolated environment').option('--exclude <exclude>', 'Exclude files from test').option('-u, --update', 'Update snapshot files').option('--passWithNoTests', 'Allows the test suite to pass when no files are found').option('--printConsoleTrace', 'Print console traces when calling any console method').option('--disableConsoleIntercept', 'Disable console intercept').option('--slowTestThreshold <value>', 'The number of milliseconds after which a test or suite is considered slow').option('-t, --testNamePattern <value>', 'Run only tests with a name that matches the regex').option('--testEnvironment <name>', 'The environment that will be used for testing').option('--testTimeout <value>', 'Timeout of a test in milliseconds').option('--hookTimeout <value>', 'Timeout of hook in milliseconds').option('--retry <retry>', 'Number of times to retry a test if it fails').option('--maxConcurrency <value>', 'Maximum number of concurrent tests').option('--clearMocks', 'Automatically clear mock calls, instances, contexts and results before every test').option('--resetMocks', 'Automatically reset mock state before every test').option('--restoreMocks', 'Automatically restore mock state and implementation before every test').option('--unstubGlobals', 'Restores all global variables that were changed with `rstest.stubGlobal` before every test').option('--unstubEnvs', 'Restores all `process.env` values that were changed with `rstest.stubEnv` before every test');
|
|
3657
3681
|
};
|
|
3658
3682
|
async function initCli(options) {
|
|
3659
3683
|
const cwd = process.cwd();
|
|
@@ -3666,10 +3690,12 @@ async function initCli(options) {
|
|
|
3666
3690
|
const keys = [
|
|
3667
3691
|
'root',
|
|
3668
3692
|
'globals',
|
|
3693
|
+
'isolate',
|
|
3669
3694
|
'passWithNoTests',
|
|
3670
3695
|
'update',
|
|
3671
3696
|
'testNamePattern',
|
|
3672
3697
|
'testTimeout',
|
|
3698
|
+
'hookTimeout',
|
|
3673
3699
|
'clearMocks',
|
|
3674
3700
|
'resetMocks',
|
|
3675
3701
|
'restoreMocks',
|
|
@@ -3683,6 +3709,7 @@ async function initCli(options) {
|
|
|
3683
3709
|
'testEnvironment'
|
|
3684
3710
|
];
|
|
3685
3711
|
for (const key of keys)if (void 0 !== options[key]) config[key] = options[key];
|
|
3712
|
+
if (options.exclude) config.exclude = (0, helper.XQ)(options.exclude);
|
|
3686
3713
|
return {
|
|
3687
3714
|
config,
|
|
3688
3715
|
configFilePath
|
|
@@ -3691,7 +3718,7 @@ async function initCli(options) {
|
|
|
3691
3718
|
function setupCommands() {
|
|
3692
3719
|
const cli = dist('rstest');
|
|
3693
3720
|
cli.help();
|
|
3694
|
-
cli.version("0.0.
|
|
3721
|
+
cli.version("0.0.6");
|
|
3695
3722
|
applyCommonOptions(cli);
|
|
3696
3723
|
cli.command('[...filters]', 'run tests').action(async (filters, options)=>{
|
|
3697
3724
|
showRstest();
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const CSS_MODULES_REGEX = /\.module\.\w+$/i;
|
|
2
|
+
const isCSSModules = ({ resourcePath, resourceQuery, resourceFragment, modules })=>{
|
|
3
|
+
if ('boolean' == typeof modules) return modules;
|
|
4
|
+
if ('string' == typeof modules) return 'global' !== modules;
|
|
5
|
+
const { auto } = modules;
|
|
6
|
+
if ('boolean' == typeof auto) return auto && CSS_MODULES_REGEX.test(resourcePath);
|
|
7
|
+
if (auto instanceof RegExp) return auto.test(resourcePath);
|
|
8
|
+
if ('function' == typeof auto) return auto(resourcePath, resourceQuery, resourceFragment);
|
|
9
|
+
return true;
|
|
10
|
+
};
|
|
11
|
+
function loader(content) {
|
|
12
|
+
const { resourcePath, resourceQuery, resourceFragment } = this;
|
|
13
|
+
const { modules = true } = this.getOptions() || {};
|
|
14
|
+
if (isCSSModules({
|
|
15
|
+
resourcePath,
|
|
16
|
+
resourceQuery,
|
|
17
|
+
resourceFragment,
|
|
18
|
+
modules
|
|
19
|
+
})) return content;
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
export { loader as default };
|