vitest 2.0.0-beta.1 → 2.0.0-beta.11
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/LICENSE.md +1 -1
- package/dist/browser.d.ts +22 -2
- package/dist/browser.js +5 -3
- package/dist/chunks/{integrations-globals.B5Jl0grA.js → integrations-globals.CC2ed6Py.js} +9 -9
- package/dist/chunks/{node-git.CCI8evVZ.js → node-git.ZtkbKc8u.js} +14 -15
- package/dist/chunks/{runtime-console.CUES-L8X.js → runtime-console.Ckl0vEQr.js} +76 -31
- package/dist/chunks/{runtime-runBaseTests._dXkRAZc.js → runtime-runBaseTests.BXW_BJeO.js} +40 -32
- package/dist/cli.js +3 -3
- package/dist/config.cjs +43 -20
- package/dist/config.d.ts +2 -2
- package/dist/config.js +43 -21
- package/dist/coverage.d.ts +4 -4
- package/dist/coverage.js +125 -37
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +2 -2
- package/dist/execute.js +2 -2
- package/dist/index.d.ts +20 -30
- package/dist/index.js +9 -9
- package/dist/node.d.ts +22 -9
- package/dist/node.js +25 -15
- package/dist/path.js +4 -1
- package/dist/{reporters-MGvT5U9f.d.ts → reporters-fiIq_dT9.d.ts} +310 -148
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +8 -8
- package/dist/runners.d.ts +4 -2
- package/dist/runners.js +103 -57
- package/dist/{suite-8WAe-urM.d.ts → suite-D4aoU9rI.d.ts} +1 -1
- package/dist/suite.d.ts +2 -2
- package/dist/suite.js +2 -2
- package/dist/utils.d.ts +1 -5
- package/dist/utils.js +1 -6
- package/dist/vendor/{base.VFkIJ66g.js → base.C2DbLEfT.js} +4 -3
- package/dist/vendor/{base._gnK9Slw.js → base.CTYV4Gnz.js} +24 -17
- package/dist/vendor/{benchmark.BNLebNi5.js → benchmark.CMp8QfyL.js} +13 -14
- package/dist/vendor/{cac.DzKZaJu2.js → cac.BcJW7n2j.js} +127 -51
- package/dist/vendor/{cli-api.DTeni0Qq.js → cli-api.C8t8m4__.js} +2771 -1711
- package/dist/vendor/{constants.5SOfHUj0.js → constants.BWsVtsAj.js} +6 -22
- package/dist/vendor/{coverage.ChSqD-qS.js → coverage.BhYSDdTT.js} +27 -11
- package/dist/vendor/{date.BKM1wewY.js → date.W2xKR2qe.js} +5 -3
- package/dist/vendor/{execute.CLLNVNnK.js → execute.T3gg2ZK6.js} +177 -63
- package/dist/vendor/{index.BfoZyXD1.js → index.-dbR4KUi.js} +17 -9
- package/dist/vendor/{index.CRxYS9H3.js → index.BC5zhX9y.js} +1201 -491
- package/dist/vendor/{index.DP-km6lF.js → index.BMmMjLIQ.js} +64 -51
- package/dist/vendor/{index._7XLd8Kd.js → index.C9Thslzw.js} +2 -1
- package/dist/vendor/{index.CmILuxzC.js → index.CQJ2m700.js} +3 -3
- package/dist/vendor/{index.DeR1hhfY.js → index.D4nqnQWz.js} +71 -74
- package/dist/vendor/{rpc.DRDE9Pu1.js → rpc.BGx7q_k2.js} +30 -19
- package/dist/vendor/{run-once.DLomgGUH.js → run-once.Db8Hgq9X.js} +2 -1
- package/dist/vendor/{setup-common.XeoZAW8t.js → setup-common.uqZOEWuR.js} +30 -15
- package/dist/vendor/spy.Cf_4R5Oe.js +22 -0
- package/dist/vendor/{tasks.WC7M-K-v.js → tasks.DhVtQBtW.js} +3 -1
- package/dist/vendor/{utils.D5gGkwyH.js → utils.DSO2UK15.js} +41 -26
- package/dist/vendor/{utils.CUjzkRH7.js → utils.DkxLWvS1.js} +12 -5
- package/dist/vendor/{vi.ClD3hi7L.js → vi.BPjl8cAZ.js} +350 -166
- package/dist/vendor/{vm.Bi3bljci.js → vm.CycSoHnJ.js} +151 -86
- package/dist/worker.js +31 -15
- package/dist/workers/forks.js +4 -4
- package/dist/workers/runVmTests.js +14 -13
- package/dist/workers/threads.js +4 -4
- package/dist/workers/vmForks.js +6 -6
- package/dist/workers/vmThreads.js +6 -6
- package/dist/workers.d.ts +2 -2
- package/dist/workers.js +9 -9
- package/package.json +22 -22
- package/suppress-warnings.cjs +2 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import vm, { isContext } from 'node:vm';
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
3
3
|
import { dirname, basename, extname, normalize, join, resolve } from 'pathe';
|
|
4
|
-
import { createCustomConsole } from '../chunks/runtime-console.
|
|
5
|
-
import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.
|
|
4
|
+
import { createCustomConsole } from '../chunks/runtime-console.Ckl0vEQr.js';
|
|
5
|
+
import { g as getDefaultRequestStubs, s as startVitestExecutor } from './execute.T3gg2ZK6.js';
|
|
6
6
|
import { distDir } from '../path.js';
|
|
7
7
|
import { dirname as dirname$1 } from 'node:path';
|
|
8
8
|
import { statSync, existsSync, promises, readFileSync } from 'node:fs';
|
|
@@ -28,7 +28,10 @@ class CommonjsExecutor {
|
|
|
28
28
|
constructor(options) {
|
|
29
29
|
this.context = options.context;
|
|
30
30
|
this.fs = options.fileMap;
|
|
31
|
-
const primitives = vm.runInContext(
|
|
31
|
+
const primitives = vm.runInContext(
|
|
32
|
+
"({ Object, Array, Error })",
|
|
33
|
+
this.context
|
|
34
|
+
);
|
|
32
35
|
const executor = this;
|
|
33
36
|
this.Module = class Module$1 {
|
|
34
37
|
exports;
|
|
@@ -50,14 +53,17 @@ class CommonjsExecutor {
|
|
|
50
53
|
}
|
|
51
54
|
get require() {
|
|
52
55
|
const require = requiresCache.get(this);
|
|
53
|
-
if (require)
|
|
56
|
+
if (require) {
|
|
54
57
|
return require;
|
|
58
|
+
}
|
|
55
59
|
const _require2 = Module$1.createRequire(this.id);
|
|
56
60
|
requiresCache.set(this, _require2);
|
|
57
61
|
return _require2;
|
|
58
62
|
}
|
|
59
63
|
static register = () => {
|
|
60
|
-
throw new Error(
|
|
64
|
+
throw new Error(
|
|
65
|
+
`[vitest] "register" is not available when running in Vitest.`
|
|
66
|
+
);
|
|
61
67
|
};
|
|
62
68
|
_compile(code, filename) {
|
|
63
69
|
const cjsModule = Module$1.wrap(code);
|
|
@@ -131,8 +137,9 @@ class CommonjsExecutor {
|
|
|
131
137
|
const require = (id) => {
|
|
132
138
|
const resolved = _require2.resolve(id);
|
|
133
139
|
const ext = extname(resolved);
|
|
134
|
-
if (ext === ".node" || isNodeBuiltin(resolved))
|
|
140
|
+
if (ext === ".node" || isNodeBuiltin(resolved)) {
|
|
135
141
|
return this.requireCoreModule(resolved);
|
|
142
|
+
}
|
|
136
143
|
const module = new this.Module(resolved);
|
|
137
144
|
return this.loadCommonJSModule(module, resolved);
|
|
138
145
|
};
|
|
@@ -166,8 +173,9 @@ class CommonjsExecutor {
|
|
|
166
173
|
// very naive implementation for Node.js require
|
|
167
174
|
loadCommonJSModule(module, filename) {
|
|
168
175
|
const cached = this.requireCache.get(filename);
|
|
169
|
-
if (cached)
|
|
176
|
+
if (cached) {
|
|
170
177
|
return cached.exports;
|
|
178
|
+
}
|
|
171
179
|
const extension = this.findLongestRegisteredExtension(filename);
|
|
172
180
|
const loader = this.extensions[extension] || this.extensions[".js"];
|
|
173
181
|
loader(module, filename);
|
|
@@ -180,25 +188,29 @@ class CommonjsExecutor {
|
|
|
180
188
|
let startIndex = 0;
|
|
181
189
|
while ((index = name.indexOf(".", startIndex)) !== -1) {
|
|
182
190
|
startIndex = index + 1;
|
|
183
|
-
if (index === 0)
|
|
191
|
+
if (index === 0) {
|
|
184
192
|
continue;
|
|
193
|
+
}
|
|
185
194
|
currentExtension = name.slice(index);
|
|
186
|
-
if (this.extensions[currentExtension])
|
|
195
|
+
if (this.extensions[currentExtension]) {
|
|
187
196
|
return currentExtension;
|
|
197
|
+
}
|
|
188
198
|
}
|
|
189
199
|
return ".js";
|
|
190
200
|
}
|
|
191
201
|
require(identifier) {
|
|
192
202
|
const ext = extname(identifier);
|
|
193
|
-
if (ext === ".node" || isNodeBuiltin(identifier))
|
|
203
|
+
if (ext === ".node" || isNodeBuiltin(identifier)) {
|
|
194
204
|
return this.requireCoreModule(identifier);
|
|
205
|
+
}
|
|
195
206
|
const module = new this.Module(identifier);
|
|
196
207
|
return this.loadCommonJSModule(module, identifier);
|
|
197
208
|
}
|
|
198
209
|
requireCoreModule(identifier) {
|
|
199
210
|
const normalized = identifier.replace(/^node:/, "");
|
|
200
|
-
if (this.builtinCache[normalized])
|
|
211
|
+
if (this.builtinCache[normalized]) {
|
|
201
212
|
return this.builtinCache[normalized].exports;
|
|
213
|
+
}
|
|
202
214
|
const moduleExports = _require(identifier);
|
|
203
215
|
if (identifier === "node:module" || identifier === "module") {
|
|
204
216
|
const module = new this.Module("/module.js");
|
|
@@ -268,18 +280,22 @@ class EsmExecutor {
|
|
|
268
280
|
if (m.status === "unlinked") {
|
|
269
281
|
this.esmLinkMap.set(
|
|
270
282
|
m,
|
|
271
|
-
m.link(
|
|
283
|
+
m.link(
|
|
284
|
+
(identifier, referencer) => this.executor.resolveModule(identifier, referencer.identifier)
|
|
285
|
+
)
|
|
272
286
|
);
|
|
273
287
|
}
|
|
274
288
|
await this.esmLinkMap.get(m);
|
|
275
|
-
if (m.status === "linked")
|
|
289
|
+
if (m.status === "linked") {
|
|
276
290
|
await m.evaluate();
|
|
291
|
+
}
|
|
277
292
|
return m;
|
|
278
293
|
}
|
|
279
294
|
async createEsModule(fileURL, getCode) {
|
|
280
295
|
const cached = this.moduleCache.get(fileURL);
|
|
281
|
-
if (cached)
|
|
296
|
+
if (cached) {
|
|
282
297
|
return cached;
|
|
298
|
+
}
|
|
283
299
|
const promise = this.loadEsModule(fileURL, getCode);
|
|
284
300
|
this.moduleCache.set(fileURL, promise);
|
|
285
301
|
return promise;
|
|
@@ -287,42 +303,40 @@ class EsmExecutor {
|
|
|
287
303
|
async loadEsModule(fileURL, getCode) {
|
|
288
304
|
const code = await getCode();
|
|
289
305
|
if (fileURL.endsWith(".json")) {
|
|
290
|
-
const m2 = new SyntheticModule$1(
|
|
291
|
-
|
|
292
|
-
()
|
|
293
|
-
|
|
294
|
-
m2.setExport("default", result);
|
|
295
|
-
}
|
|
296
|
-
);
|
|
306
|
+
const m2 = new SyntheticModule$1(["default"], () => {
|
|
307
|
+
const result = JSON.parse(code);
|
|
308
|
+
m2.setExport("default", result);
|
|
309
|
+
});
|
|
297
310
|
this.moduleCache.set(fileURL, m2);
|
|
298
311
|
return m2;
|
|
299
312
|
}
|
|
300
|
-
const m = new SourceTextModule(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
meta.filename = filename;
|
|
311
|
-
meta.dirname = dirname$1(filename);
|
|
312
|
-
}
|
|
313
|
-
meta.resolve = (specifier, importer) => {
|
|
314
|
-
return this.executor.resolve(specifier, importer != null ? importer.toString() : mod.identifier);
|
|
315
|
-
};
|
|
313
|
+
const m = new SourceTextModule(code, {
|
|
314
|
+
identifier: fileURL,
|
|
315
|
+
context: this.context,
|
|
316
|
+
importModuleDynamically: this.executor.importModuleDynamically,
|
|
317
|
+
initializeImportMeta: (meta, mod) => {
|
|
318
|
+
meta.url = mod.identifier;
|
|
319
|
+
if (mod.identifier.startsWith("file:")) {
|
|
320
|
+
const filename = fileURLToPath(mod.identifier);
|
|
321
|
+
meta.filename = filename;
|
|
322
|
+
meta.dirname = dirname$1(filename);
|
|
316
323
|
}
|
|
324
|
+
meta.resolve = (specifier, importer) => {
|
|
325
|
+
return this.executor.resolve(
|
|
326
|
+
specifier,
|
|
327
|
+
importer != null ? importer.toString() : mod.identifier
|
|
328
|
+
);
|
|
329
|
+
};
|
|
317
330
|
}
|
|
318
|
-
);
|
|
331
|
+
});
|
|
319
332
|
this.moduleCache.set(fileURL, m);
|
|
320
333
|
return m;
|
|
321
334
|
}
|
|
322
335
|
async createWebAssemblyModule(fileUrl, getCode) {
|
|
323
336
|
const cached = this.moduleCache.get(fileUrl);
|
|
324
|
-
if (cached)
|
|
337
|
+
if (cached) {
|
|
325
338
|
return cached;
|
|
339
|
+
}
|
|
326
340
|
const m = this.loadWebAssemblyModule(getCode(), fileUrl);
|
|
327
341
|
this.moduleCache.set(fileUrl, m);
|
|
328
342
|
return m;
|
|
@@ -341,8 +355,9 @@ class EsmExecutor {
|
|
|
341
355
|
}
|
|
342
356
|
async loadWebAssemblyModule(source, identifier) {
|
|
343
357
|
const cached = this.moduleCache.get(identifier);
|
|
344
|
-
if (cached)
|
|
358
|
+
if (cached) {
|
|
345
359
|
return cached;
|
|
360
|
+
}
|
|
346
361
|
const wasmModule = await WebAssembly.compile(source);
|
|
347
362
|
const exports = WebAssembly.Module.exports(wasmModule);
|
|
348
363
|
const imports = WebAssembly.Module.imports(wasmModule);
|
|
@@ -360,8 +375,9 @@ class EsmExecutor {
|
|
|
360
375
|
async () => {
|
|
361
376
|
const importsObject = {};
|
|
362
377
|
for (const { module, name } of imports) {
|
|
363
|
-
if (!importsObject[module])
|
|
378
|
+
if (!importsObject[module]) {
|
|
364
379
|
importsObject[module] = {};
|
|
380
|
+
}
|
|
365
381
|
await this.evaluateModule(moduleLookup[module]);
|
|
366
382
|
importsObject[module][name] = moduleLookup[module].namespace[name];
|
|
367
383
|
}
|
|
@@ -369,8 +385,9 @@ class EsmExecutor {
|
|
|
369
385
|
wasmModule,
|
|
370
386
|
importsObject
|
|
371
387
|
);
|
|
372
|
-
for (const { name } of exports)
|
|
388
|
+
for (const { name } of exports) {
|
|
373
389
|
syntheticModule.setExport(name, wasmInstance.exports[name]);
|
|
390
|
+
}
|
|
374
391
|
},
|
|
375
392
|
{ context: this.context, identifier }
|
|
376
393
|
);
|
|
@@ -384,18 +401,22 @@ class EsmExecutor {
|
|
|
384
401
|
}
|
|
385
402
|
async createDataModule(identifier) {
|
|
386
403
|
const cached = this.moduleCache.get(identifier);
|
|
387
|
-
if (cached)
|
|
404
|
+
if (cached) {
|
|
388
405
|
return cached;
|
|
406
|
+
}
|
|
389
407
|
const match = identifier.match(dataURIRegex);
|
|
390
|
-
if (!match || !match.groups)
|
|
408
|
+
if (!match || !match.groups) {
|
|
391
409
|
throw new Error("Invalid data URI");
|
|
410
|
+
}
|
|
392
411
|
const mime = match.groups.mime;
|
|
393
412
|
const encoding = match.groups.encoding;
|
|
394
413
|
if (mime === "application/wasm") {
|
|
395
|
-
if (!encoding)
|
|
414
|
+
if (!encoding) {
|
|
396
415
|
throw new Error("Missing data URI encoding");
|
|
397
|
-
|
|
416
|
+
}
|
|
417
|
+
if (encoding !== "base64") {
|
|
398
418
|
throw new Error(`Invalid data URI encoding: ${encoding}`);
|
|
419
|
+
}
|
|
399
420
|
const module = this.loadWebAssemblyModule(
|
|
400
421
|
Buffer.from(match.groups.code, "base64"),
|
|
401
422
|
identifier
|
|
@@ -404,12 +425,13 @@ class EsmExecutor {
|
|
|
404
425
|
return module;
|
|
405
426
|
}
|
|
406
427
|
let code = match.groups.code;
|
|
407
|
-
if (!encoding || encoding === "charset=utf-8")
|
|
428
|
+
if (!encoding || encoding === "charset=utf-8") {
|
|
408
429
|
code = decodeURIComponent(code);
|
|
409
|
-
else if (encoding === "base64")
|
|
430
|
+
} else if (encoding === "base64") {
|
|
410
431
|
code = Buffer.from(code, "base64").toString();
|
|
411
|
-
else
|
|
432
|
+
} else {
|
|
412
433
|
throw new Error(`Invalid data URI encoding: ${encoding}`);
|
|
434
|
+
}
|
|
413
435
|
if (mime === "application/json") {
|
|
414
436
|
const module = new SyntheticModule$1(
|
|
415
437
|
["default"],
|
|
@@ -428,8 +450,9 @@ class EsmExecutor {
|
|
|
428
450
|
_httpIp = new WeakMap();
|
|
429
451
|
function IPnumber(address) {
|
|
430
452
|
const ip = address.match(/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/);
|
|
431
|
-
if (ip)
|
|
453
|
+
if (ip) {
|
|
432
454
|
return (+ip[1] << 24) + (+ip[2] << 16) + (+ip[3] << 8) + +ip[4];
|
|
455
|
+
}
|
|
433
456
|
throw new Error(`Expected IP address, received ${address}`);
|
|
434
457
|
}
|
|
435
458
|
function IPmask(maskSize) {
|
|
@@ -446,8 +469,9 @@ class ViteExecutor {
|
|
|
446
469
|
esm;
|
|
447
470
|
resolve = (identifier, parent) => {
|
|
448
471
|
if (identifier === CLIENT_ID) {
|
|
449
|
-
if (this.workerState.environment.transformMode === "web")
|
|
472
|
+
if (this.workerState.environment.transformMode === "web") {
|
|
450
473
|
return identifier;
|
|
474
|
+
}
|
|
451
475
|
const packageName = this.getPackageName(parent);
|
|
452
476
|
throw new Error(
|
|
453
477
|
`[vitest] Vitest cannot handle ${CLIENT_ID} imported in ${parent} when running in SSR environment. Add "${packageName}" to "ssr.noExternal" if you are using Vite SSR, or to "server.deps.inline" if you are using Vite Node.`
|
|
@@ -460,30 +484,37 @@ class ViteExecutor {
|
|
|
460
484
|
getPackageName(modulePath) {
|
|
461
485
|
const path = normalize(modulePath);
|
|
462
486
|
let name = path.split("/node_modules/").pop() || "";
|
|
463
|
-
if (name == null ? void 0 : name.startsWith("@"))
|
|
487
|
+
if (name == null ? void 0 : name.startsWith("@")) {
|
|
464
488
|
name = name.split("/").slice(0, 2).join("/");
|
|
465
|
-
else
|
|
489
|
+
} else {
|
|
466
490
|
name = name.split("/")[0];
|
|
491
|
+
}
|
|
467
492
|
return name;
|
|
468
493
|
}
|
|
469
494
|
async createViteModule(fileUrl) {
|
|
470
|
-
if (fileUrl === CLIENT_FILE)
|
|
495
|
+
if (fileUrl === CLIENT_FILE) {
|
|
471
496
|
return this.createViteClientModule();
|
|
497
|
+
}
|
|
472
498
|
const cached = this.esm.resolveCachedModule(fileUrl);
|
|
473
|
-
if (cached)
|
|
499
|
+
if (cached) {
|
|
474
500
|
return cached;
|
|
501
|
+
}
|
|
475
502
|
return this.esm.createEsModule(fileUrl, async () => {
|
|
476
503
|
const result = await this.options.transform(fileUrl, "web");
|
|
477
|
-
if (!result.code)
|
|
478
|
-
throw new Error(
|
|
504
|
+
if (!result.code) {
|
|
505
|
+
throw new Error(
|
|
506
|
+
`[vitest] Failed to transform ${fileUrl}. Does the file exist?`
|
|
507
|
+
);
|
|
508
|
+
}
|
|
479
509
|
return result.code;
|
|
480
510
|
});
|
|
481
511
|
}
|
|
482
512
|
createViteClientModule() {
|
|
483
513
|
const identifier = CLIENT_ID;
|
|
484
514
|
const cached = this.esm.resolveCachedModule(identifier);
|
|
485
|
-
if (cached)
|
|
515
|
+
if (cached) {
|
|
486
516
|
return cached;
|
|
517
|
+
}
|
|
487
518
|
const stub = this.options.viteClientModule;
|
|
488
519
|
const moduleKeys = Object.keys(stub);
|
|
489
520
|
const module = new SyntheticModule$1(
|
|
@@ -501,18 +532,25 @@ class ViteExecutor {
|
|
|
501
532
|
canResolve = (fileUrl) => {
|
|
502
533
|
var _a;
|
|
503
534
|
const transformMode = this.workerState.environment.transformMode;
|
|
504
|
-
if (transformMode !== "web")
|
|
535
|
+
if (transformMode !== "web") {
|
|
505
536
|
return false;
|
|
506
|
-
|
|
537
|
+
}
|
|
538
|
+
if (fileUrl === CLIENT_FILE) {
|
|
507
539
|
return true;
|
|
540
|
+
}
|
|
508
541
|
const config = ((_a = this.workerState.config.deps) == null ? void 0 : _a.web) || {};
|
|
509
542
|
const [modulePath] = fileUrl.split("?");
|
|
510
|
-
if (config.transformCss && CSS_LANGS_RE.test(modulePath))
|
|
543
|
+
if (config.transformCss && CSS_LANGS_RE.test(modulePath)) {
|
|
511
544
|
return true;
|
|
512
|
-
|
|
545
|
+
}
|
|
546
|
+
if (config.transformAssets && KNOWN_ASSET_RE.test(modulePath)) {
|
|
513
547
|
return true;
|
|
514
|
-
|
|
548
|
+
}
|
|
549
|
+
if (toArray(config.transformGlobPattern).some(
|
|
550
|
+
(pattern) => pattern.test(modulePath)
|
|
551
|
+
)) {
|
|
515
552
|
return true;
|
|
553
|
+
}
|
|
516
554
|
return false;
|
|
517
555
|
};
|
|
518
556
|
}
|
|
@@ -547,8 +585,9 @@ class ExternalModulesExecutor {
|
|
|
547
585
|
});
|
|
548
586
|
__publicField(this, "resolveModule", async (specifier, referencer) => {
|
|
549
587
|
let identifier = this.resolve(specifier, referencer);
|
|
550
|
-
if (identifier instanceof Promise)
|
|
588
|
+
if (identifier instanceof Promise) {
|
|
551
589
|
identifier = await identifier;
|
|
590
|
+
}
|
|
552
591
|
return await this.createModule(identifier);
|
|
553
592
|
});
|
|
554
593
|
this.context = options.context;
|
|
@@ -583,8 +622,9 @@ class ExternalModulesExecutor {
|
|
|
583
622
|
resolve(specifier, parent) {
|
|
584
623
|
for (const resolver of this.resolvers) {
|
|
585
624
|
const id = resolver(specifier, parent);
|
|
586
|
-
if (id)
|
|
625
|
+
if (id) {
|
|
587
626
|
return id;
|
|
627
|
+
}
|
|
588
628
|
}
|
|
589
629
|
return nativeResolve(specifier, parent);
|
|
590
630
|
}
|
|
@@ -594,21 +634,24 @@ class ExternalModulesExecutor {
|
|
|
594
634
|
const packageCache = this.options.packageCache;
|
|
595
635
|
while (basedir) {
|
|
596
636
|
const cached = getCachedData(packageCache, basedir, originalBasedir);
|
|
597
|
-
if (cached)
|
|
637
|
+
if (cached) {
|
|
598
638
|
return cached;
|
|
639
|
+
}
|
|
599
640
|
const pkgPath = join(basedir, "package.json");
|
|
600
641
|
try {
|
|
601
642
|
if ((_a = statSync(pkgPath, { throwIfNoEntry: false })) == null ? void 0 : _a.isFile()) {
|
|
602
643
|
const pkgData = JSON.parse(this.fs.readFile(pkgPath));
|
|
603
|
-
if (packageCache)
|
|
644
|
+
if (packageCache) {
|
|
604
645
|
setCacheData(packageCache, pkgData, basedir, originalBasedir);
|
|
646
|
+
}
|
|
605
647
|
return pkgData;
|
|
606
648
|
}
|
|
607
649
|
} catch {
|
|
608
650
|
}
|
|
609
651
|
const nextBasedir = dirname$1(basedir);
|
|
610
|
-
if (nextBasedir === basedir)
|
|
652
|
+
if (nextBasedir === basedir) {
|
|
611
653
|
break;
|
|
654
|
+
}
|
|
612
655
|
basedir = nextBasedir;
|
|
613
656
|
}
|
|
614
657
|
return {};
|
|
@@ -618,8 +661,9 @@ class ExternalModulesExecutor {
|
|
|
618
661
|
const m = new SyntheticModule(
|
|
619
662
|
[...moduleKeys, "default"],
|
|
620
663
|
() => {
|
|
621
|
-
for (const key of moduleKeys)
|
|
664
|
+
for (const key of moduleKeys) {
|
|
622
665
|
m.setExport(key, exports[key]);
|
|
666
|
+
}
|
|
623
667
|
m.setExport("default", exports);
|
|
624
668
|
},
|
|
625
669
|
{
|
|
@@ -630,12 +674,16 @@ class ExternalModulesExecutor {
|
|
|
630
674
|
return m;
|
|
631
675
|
}
|
|
632
676
|
wrapCommonJsSynteticModule(identifier, exports) {
|
|
633
|
-
const { keys, moduleExports, defaultExport } = interopCommonJsModule(
|
|
677
|
+
const { keys, moduleExports, defaultExport } = interopCommonJsModule(
|
|
678
|
+
this.options.interopDefault,
|
|
679
|
+
exports
|
|
680
|
+
);
|
|
634
681
|
const m = new SyntheticModule(
|
|
635
682
|
[...keys, "default"],
|
|
636
683
|
() => {
|
|
637
|
-
for (const key of keys)
|
|
684
|
+
for (const key of keys) {
|
|
638
685
|
m.setExport(key, moduleExports[key]);
|
|
686
|
+
}
|
|
639
687
|
m.setExport("default", defaultExport);
|
|
640
688
|
},
|
|
641
689
|
{
|
|
@@ -646,13 +694,16 @@ class ExternalModulesExecutor {
|
|
|
646
694
|
return m;
|
|
647
695
|
}
|
|
648
696
|
getModuleInformation(identifier) {
|
|
649
|
-
if (identifier.startsWith("data:"))
|
|
697
|
+
if (identifier.startsWith("data:")) {
|
|
650
698
|
return { type: "data", url: identifier, path: identifier };
|
|
699
|
+
}
|
|
651
700
|
const extension = extname(identifier);
|
|
652
|
-
if (extension === ".node" || isNodeBuiltin(identifier))
|
|
701
|
+
if (extension === ".node" || isNodeBuiltin(identifier)) {
|
|
653
702
|
return { type: "builtin", url: identifier, path: identifier };
|
|
654
|
-
|
|
703
|
+
}
|
|
704
|
+
if (this.isNetworkSupported && (identifier.startsWith("http:") || identifier.startsWith("https:"))) {
|
|
655
705
|
return { type: "network", url: identifier, path: identifier };
|
|
706
|
+
}
|
|
656
707
|
const isFileUrl = identifier.startsWith("file://");
|
|
657
708
|
const pathUrl = isFileUrl ? fileURLToPath(identifier.split("?")[0]) : identifier;
|
|
658
709
|
const fileUrl = isFileUrl ? identifier : pathToFileURL(pathUrl).toString();
|
|
@@ -706,12 +757,13 @@ class ExternalModulesExecutor {
|
|
|
706
757
|
get isNetworkSupported() {
|
|
707
758
|
var _a;
|
|
708
759
|
if (__privateGet(this, _networkSupported) == null) {
|
|
709
|
-
if (process.execArgv.includes("--experimental-network-imports"))
|
|
760
|
+
if (process.execArgv.includes("--experimental-network-imports")) {
|
|
710
761
|
__privateSet(this, _networkSupported, true);
|
|
711
|
-
else if ((_a = process.env.NODE_OPTIONS) == null ? void 0 : _a.includes("--experimental-network-imports"))
|
|
762
|
+
} else if ((_a = process.env.NODE_OPTIONS) == null ? void 0 : _a.includes("--experimental-network-imports")) {
|
|
712
763
|
__privateSet(this, _networkSupported, true);
|
|
713
|
-
else
|
|
764
|
+
} else {
|
|
714
765
|
__privateSet(this, _networkSupported, false);
|
|
766
|
+
}
|
|
715
767
|
}
|
|
716
768
|
return __privateGet(this, _networkSupported);
|
|
717
769
|
}
|
|
@@ -723,24 +775,27 @@ class FileMap {
|
|
|
723
775
|
fsBufferCache = /* @__PURE__ */ new Map();
|
|
724
776
|
async readFileAsync(path) {
|
|
725
777
|
const cached = this.fsCache.get(path);
|
|
726
|
-
if (cached != null)
|
|
778
|
+
if (cached != null) {
|
|
727
779
|
return cached;
|
|
780
|
+
}
|
|
728
781
|
const source = await promises.readFile(path, "utf-8");
|
|
729
782
|
this.fsCache.set(path, source);
|
|
730
783
|
return source;
|
|
731
784
|
}
|
|
732
785
|
readFile(path) {
|
|
733
786
|
const cached = this.fsCache.get(path);
|
|
734
|
-
if (cached != null)
|
|
787
|
+
if (cached != null) {
|
|
735
788
|
return cached;
|
|
789
|
+
}
|
|
736
790
|
const source = readFileSync(path, "utf-8");
|
|
737
791
|
this.fsCache.set(path, source);
|
|
738
792
|
return source;
|
|
739
793
|
}
|
|
740
794
|
readBuffer(path) {
|
|
741
795
|
const cached = this.fsBufferCache.get(path);
|
|
742
|
-
if (cached != null)
|
|
796
|
+
if (cached != null) {
|
|
743
797
|
return cached;
|
|
798
|
+
}
|
|
744
799
|
const buffer = readFileSync(path);
|
|
745
800
|
this.fsBufferCache.set(path, buffer);
|
|
746
801
|
return buffer;
|
|
@@ -760,14 +815,22 @@ async function runVmTests(state) {
|
|
|
760
815
|
`Environment "${ctx.environment.name}" is not a valid environment. Path "${packageId}" doesn't support vm environment because it doesn't provide "setupVM" method.`
|
|
761
816
|
);
|
|
762
817
|
}
|
|
763
|
-
const vm = await environment.setupVM(
|
|
818
|
+
const vm = await environment.setupVM(
|
|
819
|
+
ctx.environment.options || ctx.config.environmentOptions || {}
|
|
820
|
+
);
|
|
764
821
|
state.durations.environment = performance.now() - state.durations.environment;
|
|
765
822
|
process.env.VITEST_VM_POOL = "1";
|
|
766
|
-
if (!vm.getVmContext)
|
|
767
|
-
throw new TypeError(
|
|
823
|
+
if (!vm.getVmContext) {
|
|
824
|
+
throw new TypeError(
|
|
825
|
+
`Environment ${environment.name} doesn't provide "getVmContext" method. It should return a context created by "vm.createContext" method.`
|
|
826
|
+
);
|
|
827
|
+
}
|
|
768
828
|
const context = vm.getVmContext();
|
|
769
|
-
if (!isContext(context))
|
|
770
|
-
throw new TypeError(
|
|
829
|
+
if (!isContext(context)) {
|
|
830
|
+
throw new TypeError(
|
|
831
|
+
`Environment ${environment.name} doesn't provide a valid context. It should be created by "vm.createContext" method.`
|
|
832
|
+
);
|
|
833
|
+
}
|
|
771
834
|
provideWorkerState(context, state);
|
|
772
835
|
context.process = process;
|
|
773
836
|
context.global = context;
|
|
@@ -791,7 +854,9 @@ async function runVmTests(state) {
|
|
|
791
854
|
requestStubs: stubs
|
|
792
855
|
});
|
|
793
856
|
context.__vitest_mocker__ = executor.mocker;
|
|
794
|
-
const { run } = await executor.importExternalModule(
|
|
857
|
+
const { run } = await executor.importExternalModule(
|
|
858
|
+
entryFile
|
|
859
|
+
);
|
|
795
860
|
try {
|
|
796
861
|
await run(ctx.files, ctx.config, executor);
|
|
797
862
|
} finally {
|
package/dist/worker.js
CHANGED
|
@@ -3,10 +3,10 @@ import { workerId } from 'tinypool';
|
|
|
3
3
|
import { ViteNodeRunner, ModuleCacheMap } from 'vite-node/client';
|
|
4
4
|
import { readFileSync } from 'node:fs';
|
|
5
5
|
import { resolve, normalize } from 'pathe';
|
|
6
|
-
import { e as environments } from './vendor/index.
|
|
7
|
-
import { i as isChildProcess, s as setProcessTitle } from './vendor/base.
|
|
6
|
+
import { e as environments } from './vendor/index.D4nqnQWz.js';
|
|
7
|
+
import { i as isChildProcess, s as setProcessTitle } from './vendor/base.CTYV4Gnz.js';
|
|
8
8
|
import { s as setupInspect } from './vendor/inspector.hPQncR7V.js';
|
|
9
|
-
import { c as createRuntimeRpc, a as rpcDone } from './vendor/rpc.
|
|
9
|
+
import { c as createRuntimeRpc, a as rpcDone } from './vendor/rpc.BGx7q_k2.js';
|
|
10
10
|
import 'node:console';
|
|
11
11
|
import '@vitest/utils';
|
|
12
12
|
import 'node:module';
|
|
@@ -28,14 +28,16 @@ async function createEnvironmentLoader(options) {
|
|
|
28
28
|
async function loadEnvironment(ctx, rpc) {
|
|
29
29
|
var _a;
|
|
30
30
|
const name = ctx.environment.name;
|
|
31
|
-
if (isBuiltinEnvironment(name))
|
|
31
|
+
if (isBuiltinEnvironment(name)) {
|
|
32
32
|
return environments[name];
|
|
33
|
+
}
|
|
33
34
|
const loader = await createEnvironmentLoader({
|
|
34
35
|
root: ctx.config.root,
|
|
35
36
|
fetchModule: async (id) => {
|
|
36
37
|
const result = await rpc.fetch(id, "ssr");
|
|
37
|
-
if (result.id)
|
|
38
|
+
if (result.id) {
|
|
38
39
|
return { code: readFileSync(result.id, "utf-8") };
|
|
40
|
+
}
|
|
39
41
|
return result;
|
|
40
42
|
},
|
|
41
43
|
resolveId: (id, importer) => rpc.resolveId(id, importer, "ssr")
|
|
@@ -57,28 +59,39 @@ async function loadEnvironment(ctx, rpc) {
|
|
|
57
59
|
return environment;
|
|
58
60
|
}
|
|
59
61
|
|
|
60
|
-
if (isChildProcess())
|
|
62
|
+
if (isChildProcess()) {
|
|
61
63
|
setProcessTitle(`vitest ${workerId}`);
|
|
64
|
+
}
|
|
62
65
|
async function run(ctx) {
|
|
63
66
|
const prepareStart = performance.now();
|
|
64
67
|
const inspectorCleanup = setupInspect(ctx);
|
|
65
68
|
process.env.VITEST_WORKER_ID = String(ctx.workerId);
|
|
66
69
|
process.env.VITEST_POOL_ID = String(workerId);
|
|
67
70
|
try {
|
|
68
|
-
if (ctx.worker[0] === ".")
|
|
69
|
-
throw new Error(
|
|
71
|
+
if (ctx.worker[0] === ".") {
|
|
72
|
+
throw new Error(
|
|
73
|
+
`Path to the test runner cannot be relative, received "${ctx.worker}"`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
70
76
|
const file = ctx.worker.startsWith("file:") ? ctx.worker : pathToFileURL(ctx.worker).toString();
|
|
71
77
|
const testRunnerModule = await import(file);
|
|
72
|
-
if (!testRunnerModule.default || typeof testRunnerModule.default !== "object")
|
|
73
|
-
throw new TypeError(
|
|
78
|
+
if (!testRunnerModule.default || typeof testRunnerModule.default !== "object") {
|
|
79
|
+
throw new TypeError(
|
|
80
|
+
`Test worker object should be exposed as a default export. Received "${typeof testRunnerModule.default}"`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
74
83
|
const worker = testRunnerModule.default;
|
|
75
|
-
if (!worker.getRpcOptions || typeof worker.getRpcOptions !== "function")
|
|
76
|
-
throw new TypeError(
|
|
84
|
+
if (!worker.getRpcOptions || typeof worker.getRpcOptions !== "function") {
|
|
85
|
+
throw new TypeError(
|
|
86
|
+
`Test worker should expose "getRpcOptions" method. Received "${typeof worker.getRpcOptions}".`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
77
89
|
const { rpc, onCancel } = createRuntimeRpc(worker.getRpcOptions(ctx));
|
|
78
90
|
const beforeEnvironmentTime = performance.now();
|
|
79
91
|
const environment = await loadEnvironment(ctx, rpc);
|
|
80
|
-
if (ctx.environment.transformMode)
|
|
92
|
+
if (ctx.environment.transformMode) {
|
|
81
93
|
environment.transformMode = ctx.environment.transformMode;
|
|
94
|
+
}
|
|
82
95
|
const state = {
|
|
83
96
|
ctx,
|
|
84
97
|
// here we create a new one, workers can reassign this if they need to keep it non-isolated
|
|
@@ -94,8 +107,11 @@ async function run(ctx) {
|
|
|
94
107
|
rpc,
|
|
95
108
|
providedContext: ctx.providedContext
|
|
96
109
|
};
|
|
97
|
-
if (!worker.runTests || typeof worker.runTests !== "function")
|
|
98
|
-
throw new TypeError(
|
|
110
|
+
if (!worker.runTests || typeof worker.runTests !== "function") {
|
|
111
|
+
throw new TypeError(
|
|
112
|
+
`Test worker should expose "runTests" method. Received "${typeof worker.runTests}".`
|
|
113
|
+
);
|
|
114
|
+
}
|
|
99
115
|
await worker.runTests(state);
|
|
100
116
|
} finally {
|
|
101
117
|
await rpcDone().catch(() => {
|
package/dist/workers/forks.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import v8 from 'node:v8';
|
|
2
|
-
import { c as createForksRpcOptions, u as unwrapSerializableConfig } from '../vendor/utils.
|
|
3
|
-
import { r as runBaseTests } from '../vendor/base.
|
|
2
|
+
import { c as createForksRpcOptions, u as unwrapSerializableConfig } from '../vendor/utils.DkxLWvS1.js';
|
|
3
|
+
import { r as runBaseTests } from '../vendor/base.C2DbLEfT.js';
|
|
4
4
|
import '@vitest/utils';
|
|
5
5
|
import 'vite-node/client';
|
|
6
6
|
import '../vendor/global.7bFbnyXl.js';
|
|
7
|
-
import '../vendor/execute.
|
|
7
|
+
import '../vendor/execute.T3gg2ZK6.js';
|
|
8
8
|
import 'node:vm';
|
|
9
9
|
import 'node:url';
|
|
10
10
|
import 'node:fs';
|
|
@@ -12,7 +12,7 @@ import 'vite-node/utils';
|
|
|
12
12
|
import 'pathe';
|
|
13
13
|
import '@vitest/utils/error';
|
|
14
14
|
import '../path.js';
|
|
15
|
-
import '../vendor/base.
|
|
15
|
+
import '../vendor/base.CTYV4Gnz.js';
|
|
16
16
|
|
|
17
17
|
class ForksBaseWorker {
|
|
18
18
|
getRpcOptions() {
|