vitest 3.2.0-beta.1 → 3.2.0-beta.3
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 +0 -232
- package/dist/browser.d.ts +5 -3
- package/dist/browser.js +3 -4
- package/dist/chunks/{base.SfTiRNZf.js → base.D4119yLM.js} +4 -3
- package/dist/chunks/{benchmark.BoF7jW0Q.js → benchmark.Cf_PACH1.js} +1 -1
- package/dist/chunks/{cac.TfX2-DVH.js → cac.DWaWHIIE.js} +21 -16
- package/dist/chunks/{cli-api.2970Nj9J.js → cli-api.CnmEXkxs.js} +292 -59
- package/dist/chunks/{config.d.UqE-KR0o.d.ts → config.d.D2ROskhv.d.ts} +2 -0
- package/dist/chunks/{console.K1NMVOSc.js → console.Cwr-MFPV.js} +3 -2
- package/dist/chunks/{constants.BZZyIeIE.js → constants.DnKduX2e.js} +1 -0
- package/dist/chunks/{coverage.z0LVMxgb.js → coverage.C73DaDgS.js} +241 -4226
- package/dist/chunks/{creator.CuL7xDWI.js → creator.C8WKy2eW.js} +26 -44
- package/dist/chunks/{date.CDOsz-HY.js → date.ByMsSlOr.js} +25 -0
- package/dist/chunks/{defaults.DSxsTG0h.js → defaults.DpVH7vbg.js} +1 -0
- package/dist/chunks/{environment.d.D8YDy2v5.d.ts → environment.d.cL3nLXbE.d.ts} +1 -0
- package/dist/chunks/{execute.BpmIjFTD.js → execute.B3q-2LPV.js} +28 -5
- package/dist/chunks/{global.d.BCOHQEpR.d.ts → global.d.BNLIi6yo.d.ts} +13 -11
- package/dist/chunks/{globals.Cg4NtV4P.js → globals.CI21aWXF.js} +7 -7
- package/dist/chunks/{index.DFXFpH3w.js → index.2jgTs_Q5.js} +19 -1
- package/dist/chunks/{index.CUacZlWG.js → index.Bter3jj9.js} +954 -954
- package/dist/chunks/{index.DbWBPwtH.js → index.CbT4iuwc.js} +7 -4
- package/dist/chunks/index.D3XRDfWc.js +213 -0
- package/dist/chunks/{index.BPc7M5ni.js → index.DNgLEKsQ.js} +5 -15
- package/dist/chunks/index.JOzufsrU.js +276 -0
- package/dist/chunks/{index.DBIGubLC.js → index.X0nbfr6-.js} +7 -7
- package/dist/chunks/{inspector.DbDkSkFn.js → inspector.BFsh5KO0.js} +3 -0
- package/dist/chunks/{node.3xsWotC9.js → node.Be-ntJnD.js} +1 -1
- package/dist/chunks/{reporters.d.DGm4k1Wx.d.ts → reporters.d.Bt4IGtsa.d.ts} +41 -6
- package/dist/chunks/{rpc.D9_013TY.js → rpc.BKExFSRG.js} +2 -1
- package/dist/chunks/{runBaseTests.CguliJB5.js → runBaseTests.B_M1TTsK.js} +19 -11
- package/dist/chunks/{setup-common.BP6KrF_Z.js → setup-common.CF-O-dZX.js} +2 -3
- package/dist/chunks/typechecker.BgzF-6iO.js +954 -0
- package/dist/chunks/{utils.CgTj3MsC.js → utils.BlI4TC7Y.js} +1 -0
- package/dist/chunks/{utils.BfxieIyZ.js → utils.DPCq3gzW.js} +3 -0
- package/dist/chunks/{vi.BFR5YIgu.js → vi.pkoYCV6A.js} +25 -2
- package/dist/chunks/{vite.d.DjP_ALCZ.d.ts → vite.d.B-Kx3KCF.d.ts} +3 -1
- package/dist/chunks/{vm.CuLHT1BG.js → vm.DPYem2so.js} +72 -4
- package/dist/chunks/{worker.d.CoCI7hzP.d.ts → worker.d.BKbBp2ga.d.ts} +2 -2
- package/dist/chunks/{worker.d.D5Xdi-Zr.d.ts → worker.d.Bl1O4kuf.d.ts} +1 -1
- package/dist/cli.js +21 -2
- package/dist/config.cjs +2 -0
- package/dist/config.d.ts +7 -6
- package/dist/config.js +2 -2
- package/dist/coverage.d.ts +4 -4
- package/dist/coverage.js +7 -10
- package/dist/environments.d.ts +6 -2
- package/dist/environments.js +1 -1
- package/dist/execute.d.ts +9 -3
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +25 -35
- package/dist/index.js +5 -6
- package/dist/node.d.ts +18 -10
- package/dist/node.js +22 -22
- package/dist/reporters.d.ts +4 -4
- package/dist/reporters.js +14 -14
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +13 -5
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker.js +9 -5
- package/dist/workers/forks.js +6 -4
- package/dist/workers/runVmTests.js +14 -10
- 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 +4 -4
- package/dist/workers.js +10 -10
- package/package.json +22 -26
- package/dist/chunks/index.Bw6JxgX8.js +0 -143
- package/dist/chunks/run-once.Dimr7O9f.js +0 -47
- package/dist/chunks/typechecker.DYQbn8uK.js +0 -956
- package/dist/chunks/utils.8gfOgtry.js +0 -207
- package/dist/utils.d.ts +0 -3
- package/dist/utils.js +0 -2
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { existsSync, writeFileSync, readFileSync } from 'node:fs';
|
|
2
2
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
3
3
|
import { resolve, dirname, relative } from 'node:path';
|
|
4
|
-
import { detectPackageManager, installPackage } from './index.
|
|
5
|
-
import { p as prompt, f as findUp } from './index.
|
|
4
|
+
import { detectPackageManager, installPackage } from './index.D3XRDfWc.js';
|
|
5
|
+
import { p as prompt, f as findUp } from './index.X0nbfr6-.js';
|
|
6
6
|
import { x } from 'tinyexec';
|
|
7
7
|
import c from 'tinyrainbow';
|
|
8
|
-
import { c as configFiles } from './constants.
|
|
8
|
+
import { c as configFiles } from './constants.DnKduX2e.js';
|
|
9
9
|
import 'node:process';
|
|
10
10
|
import 'node:url';
|
|
11
11
|
import './_commonjsHelpers.BFTU3MAI.js';
|
|
@@ -236,14 +236,14 @@ test('renders name', () => {
|
|
|
236
236
|
};
|
|
237
237
|
function getExampleTest(framework) {
|
|
238
238
|
switch (framework) {
|
|
239
|
-
case "solid":
|
|
240
|
-
case "preact": return {
|
|
239
|
+
case "solid": return {
|
|
241
240
|
...jsxExample,
|
|
242
241
|
test: jsxExample.test.replace("@testing-library/jsx", `@testing-library/${framework}`)
|
|
243
242
|
};
|
|
243
|
+
case "preact":
|
|
244
244
|
case "react": return {
|
|
245
245
|
...jsxExample,
|
|
246
|
-
test: jsxExample.test.replace("@testing-library/jsx",
|
|
246
|
+
test: jsxExample.test.replace("@testing-library/jsx", `vitest-browser-${framework}`)
|
|
247
247
|
};
|
|
248
248
|
case "vue": return vueExample;
|
|
249
249
|
case "svelte": return svelteExample;
|
|
@@ -273,6 +273,7 @@ async function generateExampleFiles(framework, lang) {
|
|
|
273
273
|
return testPath;
|
|
274
274
|
}
|
|
275
275
|
|
|
276
|
+
// eslint-disable-next-line no-console
|
|
276
277
|
const log = console.log;
|
|
277
278
|
function getProviderOptions() {
|
|
278
279
|
const providers = {
|
|
@@ -376,7 +377,7 @@ function getFrameworkTestPackage(framework) {
|
|
|
376
377
|
case "svelte": return "vitest-browser-svelte";
|
|
377
378
|
case "react": return "vitest-browser-react";
|
|
378
379
|
case "lit": return "vitest-browser-lit";
|
|
379
|
-
case "preact": return "
|
|
380
|
+
case "preact": return "vitest-browser-preact";
|
|
380
381
|
case "solid": return "@solidjs/testing-library";
|
|
381
382
|
case "marko": return "@marko/testing-library";
|
|
382
383
|
}
|
|
@@ -469,6 +470,7 @@ function getPossibleProvider(dependencies) {
|
|
|
469
470
|
if (dependencies.webdriverio || dependencies["@wdio/cli"] || dependencies["@wdio/config"]) {
|
|
470
471
|
return "webdriverio";
|
|
471
472
|
}
|
|
473
|
+
// playwright is the default recommendation
|
|
472
474
|
return "playwright";
|
|
473
475
|
}
|
|
474
476
|
function getProviderDocsLink(provider) {
|
|
@@ -488,32 +490,6 @@ function sort(choices, value) {
|
|
|
488
490
|
function fail() {
|
|
489
491
|
process.exitCode = 1;
|
|
490
492
|
}
|
|
491
|
-
async function generateWorkspaceFile(options) {
|
|
492
|
-
const relativeRoot = relative(dirname(options.configPath), options.rootConfig);
|
|
493
|
-
const workspaceContent = [
|
|
494
|
-
`import { defineWorkspace } from 'vitest/config'`,
|
|
495
|
-
"",
|
|
496
|
-
"export default defineWorkspace([",
|
|
497
|
-
" // If you want to keep running your existing tests in Node.js, uncomment the next line.",
|
|
498
|
-
` // '${relativeRoot}',`,
|
|
499
|
-
` {`,
|
|
500
|
-
` extends: '${relativeRoot}',`,
|
|
501
|
-
` test: {`,
|
|
502
|
-
` browser: {`,
|
|
503
|
-
` enabled: true,`,
|
|
504
|
-
` provider: '${options.provider}',`,
|
|
505
|
-
options.provider !== "preview" && ` // ${getProviderDocsLink(options.provider)}`,
|
|
506
|
-
` instances: [`,
|
|
507
|
-
...options.browsers.map((browser) => ` { browser: '${browser}' },`),
|
|
508
|
-
` ],`,
|
|
509
|
-
` },`,
|
|
510
|
-
` },`,
|
|
511
|
-
` },`,
|
|
512
|
-
`])`,
|
|
513
|
-
""
|
|
514
|
-
].filter((c) => typeof c === "string").join("\n");
|
|
515
|
-
await writeFile(options.configPath, workspaceContent);
|
|
516
|
-
}
|
|
517
493
|
async function generateFrameworkConfigFile(options) {
|
|
518
494
|
const frameworkImport = options.framework === "svelte" ? `import { svelte } from '${options.frameworkPlugin}'` : `import ${options.framework} from '${options.frameworkPlugin}'`;
|
|
519
495
|
const configContent = [
|
|
@@ -648,19 +624,24 @@ async function create() {
|
|
|
648
624
|
let scriptCommand = "vitest";
|
|
649
625
|
log();
|
|
650
626
|
if (rootConfig) {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
await generateWorkspaceFile({
|
|
658
|
-
configPath: browserWorkspaceFile,
|
|
659
|
-
rootConfig,
|
|
627
|
+
const configPath = resolve(dirname(rootConfig), `vitest.browser.config.${lang}`);
|
|
628
|
+
scriptCommand = `vitest --config=${relative(process.cwd(), configPath)}`;
|
|
629
|
+
await generateFrameworkConfigFile({
|
|
630
|
+
configPath,
|
|
631
|
+
framework,
|
|
632
|
+
frameworkPlugin,
|
|
660
633
|
provider,
|
|
661
634
|
browsers
|
|
662
635
|
});
|
|
663
|
-
log(
|
|
636
|
+
log(
|
|
637
|
+
c.green("✔"),
|
|
638
|
+
"Created a new config file for browser tests:",
|
|
639
|
+
c.bold(relative(process.cwd(), configPath)),
|
|
640
|
+
// TODO: Can we modify the config ourselves?
|
|
641
|
+
"\nSince you already have a Vitest config file, it is recommended to copy the contents of the new file ",
|
|
642
|
+
"into your existing config located at ",
|
|
643
|
+
c.bold(relative(process.cwd(), rootConfig))
|
|
644
|
+
);
|
|
664
645
|
} else {
|
|
665
646
|
const configPath = resolve(process.cwd(), `vitest.config.${lang}`);
|
|
666
647
|
await generateFrameworkConfigFile({
|
|
@@ -670,7 +651,7 @@ async function create() {
|
|
|
670
651
|
provider,
|
|
671
652
|
browsers
|
|
672
653
|
});
|
|
673
|
-
log(c.green("✔"), "Created a config file for browser tests", c.bold(relative(process.cwd(), configPath)));
|
|
654
|
+
log(c.green("✔"), "Created a config file for browser tests:", c.bold(relative(process.cwd(), configPath)));
|
|
674
655
|
}
|
|
675
656
|
log();
|
|
676
657
|
await updatePkgJsonScripts(pkgJsonPath, scriptCommand);
|
|
@@ -691,6 +672,7 @@ async function create() {
|
|
|
691
672
|
"inherit"
|
|
692
673
|
] } });
|
|
693
674
|
}
|
|
675
|
+
// TODO: can we do this ourselves?
|
|
694
676
|
if (lang === "ts") {
|
|
695
677
|
await updateTsConfig(providerPkg?.types);
|
|
696
678
|
}
|
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
/* Ported from https://github.com/boblauer/MockDate/blob/master/src/mockdate.ts */
|
|
2
|
+
/*
|
|
3
|
+
The MIT License (MIT)
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2014 Bob Lauer
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
24
|
+
*/
|
|
1
25
|
const RealDate = Date;
|
|
2
26
|
let now = null;
|
|
3
27
|
class MockDate extends RealDate {
|
|
@@ -43,6 +67,7 @@ function mockDate(date) {
|
|
|
43
67
|
if (Number.isNaN(dateObj.getTime())) {
|
|
44
68
|
throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
45
69
|
}
|
|
70
|
+
// @ts-expect-error global
|
|
46
71
|
globalThis.Date = MockDate;
|
|
47
72
|
now = dateObj.valueOf();
|
|
48
73
|
}
|
|
@@ -36,6 +36,7 @@ const defaultCoverageExcludes = [
|
|
|
36
36
|
"**/vitest.{workspace,projects}.[jt]s?(on)",
|
|
37
37
|
"**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}"
|
|
38
38
|
];
|
|
39
|
+
// These are the generic defaults for coverage. Providers may also set some provider specific defaults.
|
|
39
40
|
const coverageConfigDefaults = {
|
|
40
41
|
provider: "v8",
|
|
41
42
|
enabled: false,
|
|
@@ -36,6 +36,7 @@ interface ModuleGraphData {
|
|
|
36
36
|
inlined: string[];
|
|
37
37
|
}
|
|
38
38
|
interface ProvidedContext {}
|
|
39
|
+
// These need to be compatible with Tinyrainbow's bg-colors, and CSS's background-color
|
|
39
40
|
type LabelColor = "black" | "red" | "green" | "yellow" | "blue" | "magenta" | "cyan" | "white";
|
|
40
41
|
|
|
41
42
|
type HappyDOMOptions = Omit<NonNullable<ConstructorParameters<typeof happyDomTypes.Window>[0]>, "console">;
|
|
@@ -187,6 +187,8 @@ const basename = function(p, extension) {
|
|
|
187
187
|
const { existsSync, readdirSync, statSync } = fs;
|
|
188
188
|
function findMockRedirect(root, mockPath, external) {
|
|
189
189
|
const path = external || mockPath;
|
|
190
|
+
// it's a node_module alias
|
|
191
|
+
// all mocks should be inside <root>/__mocks__
|
|
190
192
|
if (external || isNodeBuiltin(mockPath) || !existsSync(mockPath)) {
|
|
191
193
|
const mockDirname = dirname(path);
|
|
192
194
|
const mockFolder = join(root, "__mocks__", mockDirname);
|
|
@@ -200,9 +202,11 @@ function findMockRedirect(root, mockPath, external) {
|
|
|
200
202
|
const baseFile = basename(file, extname(file));
|
|
201
203
|
if (baseFile === baseOriginal) {
|
|
202
204
|
const path = resolve(mockFolder, file);
|
|
205
|
+
// if the same name, return the file
|
|
203
206
|
if (statSync(path).isFile()) {
|
|
204
207
|
return path;
|
|
205
208
|
} else {
|
|
209
|
+
// find folder/index.{js,ts}
|
|
206
210
|
const indexFile = findFile(path, "index");
|
|
207
211
|
if (indexFile) {
|
|
208
212
|
return indexFile;
|
|
@@ -235,6 +239,7 @@ const builtins = new Set([
|
|
|
235
239
|
"util/types",
|
|
236
240
|
"wasi"
|
|
237
241
|
]);
|
|
242
|
+
// https://nodejs.org/api/modules.html#built-in-modules-with-mandatory-node-prefix
|
|
238
243
|
const prefixedBuiltins = new Set([
|
|
239
244
|
"node:sea",
|
|
240
245
|
"node:sqlite",
|
|
@@ -337,6 +342,7 @@ class VitestMocker {
|
|
|
337
342
|
try {
|
|
338
343
|
[id, fsPath] = await this.executor.originalResolveUrl(rawId, importer);
|
|
339
344
|
} catch (error) {
|
|
345
|
+
// it's allowed to mock unresolved modules
|
|
340
346
|
if (error.code === "ERR_MODULE_NOT_FOUND") {
|
|
341
347
|
const { id: unresolvedId } = error[Symbol.for("vitest.error.not_found.data")];
|
|
342
348
|
id = unresolvedId;
|
|
@@ -345,6 +351,8 @@ class VitestMocker {
|
|
|
345
351
|
throw error;
|
|
346
352
|
}
|
|
347
353
|
}
|
|
354
|
+
// external is node_module or unresolved module
|
|
355
|
+
// for example, some people mock "vscode" and don't have it installed
|
|
348
356
|
const external = !isAbsolute$1(fsPath) || this.isModuleDirectory(fsPath) ? rawId : null;
|
|
349
357
|
return {
|
|
350
358
|
id,
|
|
@@ -375,6 +383,7 @@ class VitestMocker {
|
|
|
375
383
|
const exports = await mock.resolve();
|
|
376
384
|
const moduleExports = new Proxy(exports, { get: (target, prop) => {
|
|
377
385
|
const val = target[prop];
|
|
386
|
+
// 'then' can exist on non-Promise objects, need nested instanceof check for logic to work
|
|
378
387
|
if (prop === "then") {
|
|
379
388
|
if (target instanceof Promise) {
|
|
380
389
|
return target.then.bind(target);
|
|
@@ -396,9 +405,11 @@ class VitestMocker {
|
|
|
396
405
|
this.moduleCache.set(dep, { exports: moduleExports });
|
|
397
406
|
return moduleExports;
|
|
398
407
|
}
|
|
408
|
+
// public method to avoid circular dependency
|
|
399
409
|
getMockContext() {
|
|
400
410
|
return this.mockContext;
|
|
401
411
|
}
|
|
412
|
+
// path used to store mocked dependencies
|
|
402
413
|
getMockPath(dep) {
|
|
403
414
|
return `mock:${dep}`;
|
|
404
415
|
}
|
|
@@ -444,6 +455,7 @@ class VitestMocker {
|
|
|
444
455
|
registry.register("automock", originalId, id, id);
|
|
445
456
|
}
|
|
446
457
|
}
|
|
458
|
+
// every time the mock is registered, we remove the previous one from the cache
|
|
447
459
|
this.deleteCachedItem(id);
|
|
448
460
|
}
|
|
449
461
|
async importActual(rawId, importer, callstack) {
|
|
@@ -485,6 +497,7 @@ class VitestMocker {
|
|
|
485
497
|
return cache.exports;
|
|
486
498
|
}
|
|
487
499
|
const exports = {};
|
|
500
|
+
// Assign the empty exports object early to allow for cycles to work. The object will be filled by mockObject()
|
|
488
501
|
this.moduleCache.set(mockPath, { exports });
|
|
489
502
|
const mod = await this.executor.directRequest(url, url, callstack);
|
|
490
503
|
this.mockObject(mod, exports, mock.type);
|
|
@@ -493,6 +506,9 @@ class VitestMocker {
|
|
|
493
506
|
if (mock.type === "manual" && !callstack.includes(mockPath) && !callstack.includes(url)) {
|
|
494
507
|
try {
|
|
495
508
|
callstack.push(mockPath);
|
|
509
|
+
// this will not work if user does Promise.all(import(), import())
|
|
510
|
+
// we can also use AsyncLocalStorage to store callstack, but this won't work in the browser
|
|
511
|
+
// maybe we should improve mock API in the future?
|
|
496
512
|
this.mockContext.callstack = callstack;
|
|
497
513
|
return await this.callFunctionMock(mockPath, mock);
|
|
498
514
|
} finally {
|
|
@@ -548,11 +564,11 @@ function listenForErrors(state) {
|
|
|
548
564
|
dispose.length = 0;
|
|
549
565
|
function catchError(err, type, event) {
|
|
550
566
|
const worker = state();
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
567
|
+
const listeners = process.listeners(event);
|
|
568
|
+
// if there is another listener, assume that it's handled by user code
|
|
569
|
+
// one is Vitest's own listener
|
|
570
|
+
if (listeners.length > 1) {
|
|
571
|
+
return;
|
|
556
572
|
}
|
|
557
573
|
const error = processError(err);
|
|
558
574
|
if (!isPrimitive(error)) {
|
|
@@ -578,6 +594,8 @@ function getVitestImport(id, state) {
|
|
|
578
594
|
if (externalizeMap.has(id)) {
|
|
579
595
|
return { externalize: externalizeMap.get(id) };
|
|
580
596
|
}
|
|
597
|
+
// always externalize Vitest because we import from there before running tests
|
|
598
|
+
// so we already have it cached by Node.js
|
|
581
599
|
const root = state().config.root;
|
|
582
600
|
const relativeRoot = relativeIds[root] ?? (relativeIds[root] = normalizedDistDir.slice(root.length));
|
|
583
601
|
if (id.includes(distDir) || id.includes(normalizedDistDir) || relativeRoot && relativeRoot !== "/" && id.startsWith(relativeRoot)) {
|
|
@@ -715,6 +733,7 @@ class VitestExecutor extends ViteNodeRunner {
|
|
|
715
733
|
return this.primitives;
|
|
716
734
|
}
|
|
717
735
|
get state() {
|
|
736
|
+
// @ts-expect-error injected untyped global
|
|
718
737
|
return globalThis.__vitest_worker__ || this.options.state;
|
|
719
738
|
}
|
|
720
739
|
get moduleExecutionInfo() {
|
|
@@ -725,6 +744,8 @@ class VitestExecutor extends ViteNodeRunner {
|
|
|
725
744
|
return false;
|
|
726
745
|
}
|
|
727
746
|
const transformMode = this.state.environment?.transformMode ?? "ssr";
|
|
747
|
+
// do not try and resolve node builtins in Node
|
|
748
|
+
// import('url') returns Node internal even if 'url' package is installed
|
|
728
749
|
return transformMode === "ssr" ? !isNodeBuiltin$1(id) : !id.startsWith("node:");
|
|
729
750
|
}
|
|
730
751
|
async originalResolveUrl(id, importer) {
|
|
@@ -756,6 +777,7 @@ class VitestExecutor extends ViteNodeRunner {
|
|
|
756
777
|
if (!vmContext || !this.externalModules) {
|
|
757
778
|
return super.runModule(context, transformed);
|
|
758
779
|
}
|
|
780
|
+
// add 'use strict' since ESM enables it by default
|
|
759
781
|
const codeDefinition = `'use strict';async (${Object.keys(context).join(",")})=>{{`;
|
|
760
782
|
const code = `${codeDefinition}${transformed}\n}}`;
|
|
761
783
|
const options = {
|
|
@@ -787,6 +809,7 @@ class VitestExecutor extends ViteNodeRunner {
|
|
|
787
809
|
return super.dependencyRequest(id, fsPath, callstack);
|
|
788
810
|
}
|
|
789
811
|
prepareContext(context) {
|
|
812
|
+
// support `import.meta.vitest` for test entry
|
|
790
813
|
if (this.state.filepath && normalize$1(this.state.filepath) === normalize$1(context.__filename)) {
|
|
791
814
|
const globalNamespace = this.options.context || globalThis;
|
|
792
815
|
Object.defineProperty(context.__vite_ssr_import_meta__, "vitest", { get: () => globalNamespace.__vitest_index__ });
|
|
@@ -2,7 +2,7 @@ import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
|
|
|
2
2
|
import { Plugin } from '@vitest/pretty-format';
|
|
3
3
|
import { SnapshotState } from '@vitest/snapshot';
|
|
4
4
|
import { B as BenchmarkResult } from './benchmark.d.BwvBVTda.js';
|
|
5
|
-
import { U as UserConsoleLog } from './environment.d.
|
|
5
|
+
import { U as UserConsoleLog } from './environment.d.cL3nLXbE.js';
|
|
6
6
|
|
|
7
7
|
type RawErrsMap = Map<string, TscErrorInfo[]>;
|
|
8
8
|
interface TscErrorInfo {
|
|
@@ -29,6 +29,7 @@ type Context = RootAndTarget & {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
declare global {
|
|
32
|
+
// eslint-disable-next-line ts/no-namespace
|
|
32
33
|
namespace Chai {
|
|
33
34
|
interface Assertion {
|
|
34
35
|
containSubset: (expected: any) => Assertion;
|
|
@@ -39,12 +40,12 @@ declare global {
|
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
interface SnapshotMatcher<T> {
|
|
42
|
-
<U extends { [P in keyof T] : any }>(snapshot: Partial<U>,
|
|
43
|
-
(
|
|
43
|
+
<U extends { [P in keyof T] : any }>(snapshot: Partial<U>, hint?: string): void;
|
|
44
|
+
(hint?: string): void;
|
|
44
45
|
}
|
|
45
46
|
interface InlineSnapshotMatcher<T> {
|
|
46
|
-
<U extends { [P in keyof T] : any }>(properties: Partial<U>, snapshot?: string,
|
|
47
|
-
(
|
|
47
|
+
<U extends { [P in keyof T] : any }>(properties: Partial<U>, snapshot?: string, hint?: string): void;
|
|
48
|
+
(hint?: string): void;
|
|
48
49
|
}
|
|
49
50
|
declare module "@vitest/expect" {
|
|
50
51
|
interface MatcherState {
|
|
@@ -66,41 +67,42 @@ declare module "@vitest/expect" {
|
|
|
66
67
|
addSnapshotSerializer: (plugin: Plugin) => void;
|
|
67
68
|
}
|
|
68
69
|
interface Assertion<T> {
|
|
70
|
+
// Snapshots are extended in @vitest/snapshot and are not part of @vitest/expect
|
|
69
71
|
matchSnapshot: SnapshotMatcher<T>;
|
|
70
72
|
toMatchSnapshot: SnapshotMatcher<T>;
|
|
71
73
|
toMatchInlineSnapshot: InlineSnapshotMatcher<T>;
|
|
72
74
|
/**
|
|
73
75
|
* Checks that an error thrown by a function matches a previously recorded snapshot.
|
|
74
76
|
*
|
|
75
|
-
* @param
|
|
77
|
+
* @param hint - Optional custom error message.
|
|
76
78
|
*
|
|
77
79
|
* @example
|
|
78
80
|
* expect(functionWithError).toThrowErrorMatchingSnapshot();
|
|
79
81
|
*/
|
|
80
|
-
toThrowErrorMatchingSnapshot: (
|
|
82
|
+
toThrowErrorMatchingSnapshot: (hint?: string) => void;
|
|
81
83
|
/**
|
|
82
84
|
* Checks that an error thrown by a function matches an inline snapshot within the test file.
|
|
83
85
|
* Useful for keeping snapshots close to the test code.
|
|
84
86
|
*
|
|
85
87
|
* @param snapshot - Optional inline snapshot string to match.
|
|
86
|
-
* @param
|
|
88
|
+
* @param hint - Optional custom error message.
|
|
87
89
|
*
|
|
88
90
|
* @example
|
|
89
91
|
* const throwError = () => { throw new Error('Error occurred') };
|
|
90
92
|
* expect(throwError).toThrowErrorMatchingInlineSnapshot(`"Error occurred"`);
|
|
91
93
|
*/
|
|
92
|
-
toThrowErrorMatchingInlineSnapshot: (snapshot?: string,
|
|
94
|
+
toThrowErrorMatchingInlineSnapshot: (snapshot?: string, hint?: string) => void;
|
|
93
95
|
/**
|
|
94
96
|
* Compares the received value to a snapshot saved in a specified file.
|
|
95
97
|
* Useful for cases where snapshot content is large or needs to be shared across tests.
|
|
96
98
|
*
|
|
97
99
|
* @param filepath - Path to the snapshot file.
|
|
98
|
-
* @param
|
|
100
|
+
* @param hint - Optional custom error message.
|
|
99
101
|
*
|
|
100
102
|
* @example
|
|
101
103
|
* await expect(largeData).toMatchFileSnapshot('path/to/snapshot.json');
|
|
102
104
|
*/
|
|
103
|
-
toMatchFileSnapshot: (filepath: string,
|
|
105
|
+
toMatchFileSnapshot: (filepath: string, hint?: string) => Promise<void>;
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
declare module "@vitest/runner" {
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { g as globalApis } from './constants.
|
|
2
|
-
import { V as VitestIndex } from './index.
|
|
3
|
-
import './vi.
|
|
1
|
+
import { g as globalApis } from './constants.DnKduX2e.js';
|
|
2
|
+
import { V as VitestIndex } from './index.DNgLEKsQ.js';
|
|
3
|
+
import './vi.pkoYCV6A.js';
|
|
4
4
|
import '@vitest/expect';
|
|
5
5
|
import '@vitest/runner';
|
|
6
6
|
import '@vitest/runner/utils';
|
|
7
7
|
import 'chai';
|
|
8
|
-
import './utils.
|
|
8
|
+
import './utils.BlI4TC7Y.js';
|
|
9
9
|
import '@vitest/utils';
|
|
10
10
|
import './_commonjsHelpers.BFTU3MAI.js';
|
|
11
11
|
import '@vitest/snapshot';
|
|
12
12
|
import '@vitest/utils/error';
|
|
13
13
|
import '@vitest/spy';
|
|
14
14
|
import '@vitest/utils/source-map';
|
|
15
|
-
import './date.
|
|
16
|
-
import './
|
|
17
|
-
import './benchmark.BoF7jW0Q.js';
|
|
15
|
+
import './date.ByMsSlOr.js';
|
|
16
|
+
import './benchmark.Cf_PACH1.js';
|
|
18
17
|
import 'expect-type';
|
|
19
18
|
|
|
20
19
|
function registerApiGlobally() {
|
|
21
20
|
globalApis.forEach((api) => {
|
|
21
|
+
// @ts-expect-error I know what I am doing :P
|
|
22
22
|
globalThis[api] = VitestIndex[api];
|
|
23
23
|
});
|
|
24
24
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Console } from 'node:console';
|
|
2
2
|
|
|
3
|
+
// SEE https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/interfaces.js
|
|
3
4
|
const LIVING_KEYS = [
|
|
4
5
|
"DOMException",
|
|
5
6
|
"URL",
|
|
@@ -291,6 +292,7 @@ function populateGlobal(global, win, options = {}) {
|
|
|
291
292
|
if (global.global) {
|
|
292
293
|
global.global = global;
|
|
293
294
|
}
|
|
295
|
+
// rewrite defaultView to reference the same global context
|
|
294
296
|
if (global.document && global.document.defaultView) {
|
|
295
297
|
Object.defineProperty(global.document, "defaultView", {
|
|
296
298
|
get: () => global,
|
|
@@ -320,7 +322,9 @@ var edge = {
|
|
|
320
322
|
getVmContext() {
|
|
321
323
|
return vm.context;
|
|
322
324
|
},
|
|
323
|
-
teardown() {
|
|
325
|
+
teardown() {
|
|
326
|
+
// nothing to teardown
|
|
327
|
+
}
|
|
324
328
|
};
|
|
325
329
|
},
|
|
326
330
|
async setup(global) {
|
|
@@ -365,7 +369,9 @@ var happy = {
|
|
|
365
369
|
disableErrorCapturing: true
|
|
366
370
|
}
|
|
367
371
|
});
|
|
372
|
+
// TODO: browser doesn't expose Buffer, but a lot of dependencies use it
|
|
368
373
|
win.Buffer = Buffer;
|
|
374
|
+
// inject structuredClone if it exists
|
|
369
375
|
if (typeof structuredClone !== "undefined" && !win.structuredClone) {
|
|
370
376
|
win.structuredClone = structuredClone;
|
|
371
377
|
}
|
|
@@ -380,6 +386,8 @@ var happy = {
|
|
|
380
386
|
};
|
|
381
387
|
},
|
|
382
388
|
async setup(global, { happyDOM = {} }) {
|
|
389
|
+
// happy-dom v3 introduced a breaking change to Window, but
|
|
390
|
+
// provides GlobalWindow as a way to use previous behaviour
|
|
383
391
|
const { Window, GlobalWindow } = await import('happy-dom');
|
|
384
392
|
const win = new (GlobalWindow || Window)({
|
|
385
393
|
...happyDOM,
|
|
@@ -452,8 +460,11 @@ var jsdom = {
|
|
|
452
460
|
...restOptions
|
|
453
461
|
});
|
|
454
462
|
const clearWindowErrors = catchWindowErrors(dom.window);
|
|
463
|
+
// TODO: browser doesn't expose Buffer, but a lot of dependencies use it
|
|
455
464
|
dom.window.Buffer = Buffer;
|
|
456
465
|
dom.window.jsdom = dom;
|
|
466
|
+
// inject web globals if they missing in JSDOM but otherwise available in Nodejs
|
|
467
|
+
// https://nodejs.org/dist/latest/docs/api/globals.html
|
|
457
468
|
const globalNames = [
|
|
458
469
|
"structuredClone",
|
|
459
470
|
"fetch",
|
|
@@ -510,6 +521,7 @@ var jsdom = {
|
|
|
510
521
|
}
|
|
511
522
|
};
|
|
512
523
|
|
|
524
|
+
// some globals we do not want, either because deprecated or we set it ourselves
|
|
513
525
|
const denyList = new Set([
|
|
514
526
|
"GLOBAL",
|
|
515
527
|
"root",
|
|
@@ -540,7 +552,9 @@ var node = {
|
|
|
540
552
|
configurable: true,
|
|
541
553
|
enumerable: descriptor.enumerable,
|
|
542
554
|
get() {
|
|
555
|
+
// @ts-expect-error: no index signature
|
|
543
556
|
const val = globalThis[nodeGlobalsKey];
|
|
557
|
+
// override lazy getter
|
|
544
558
|
Object.defineProperty(global, nodeGlobalsKey, {
|
|
545
559
|
configurable: true,
|
|
546
560
|
enumerable: descriptor.enumerable,
|
|
@@ -550,6 +564,7 @@ var node = {
|
|
|
550
564
|
return val;
|
|
551
565
|
},
|
|
552
566
|
set(val) {
|
|
567
|
+
// override lazy getter
|
|
553
568
|
Object.defineProperty(global, nodeGlobalsKey, {
|
|
554
569
|
configurable: true,
|
|
555
570
|
enumerable: descriptor.enumerable,
|
|
@@ -578,6 +593,9 @@ var node = {
|
|
|
578
593
|
global.global = global;
|
|
579
594
|
global.Buffer = Buffer;
|
|
580
595
|
global.ArrayBuffer = ArrayBuffer;
|
|
596
|
+
// TextEncoder (global or via 'util') references a Uint8Array constructor
|
|
597
|
+
// different than the global one used by users in tests. This makes sure the
|
|
598
|
+
// same constructor is referenced by both.
|
|
581
599
|
global.Uint8Array = Uint8Array;
|
|
582
600
|
return {
|
|
583
601
|
getVmContext() {
|