vitest 4.0.0-beta.11 → 4.0.0-beta.13
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 +4 -101
- package/dist/browser.d.ts +3 -3
- package/dist/browser.js +2 -2
- package/dist/chunks/{benchmark.LXhJ0F0X.js → benchmark.DHKMYAts.js} +1 -1
- package/dist/chunks/{browser.d.Dx7DO_Ce.d.ts → browser.d.D9YV3JvA.d.ts} +1 -1
- package/dist/chunks/{cac.elvK37c9.js → cac.BBtYKH7y.js} +16 -9
- package/dist/chunks/{cli-api.C7plPyhs.js → cli-api.CeakdBUN.js} +95 -148
- package/dist/chunks/{config.d.B_LthbQq.d.ts → config.d.DGazh2r6.d.ts} +3 -1
- package/dist/chunks/{console.CiTi59Jy.js → console.CTJL2nuH.js} +3 -5
- package/dist/chunks/{coverage.CG6Uhorw.js → coverage.DabP7UTQ.js} +69 -80
- package/dist/chunks/{creator.08Gi-vCA.js → creator.DfXDsUyL.js} +6 -8
- package/dist/chunks/{global.d.BK3X7FW1.d.ts → global.d.BcFPD2LN.d.ts} +0 -13
- package/dist/chunks/{globals.BjvYA-AD.js → globals.DC4ntO86.js} +5 -5
- package/dist/chunks/{index.DIWhzsUh.js → index.Bt-upxGS.js} +6 -12
- package/dist/chunks/{index.BwBttQPf.js → index.CHrBLuEH.js} +33 -38
- package/dist/chunks/{index.X0nbfr6-.js → index.Dc3xnDvT.js} +48 -289
- package/dist/chunks/{index.AZOjjqWP.js → index.Dnl38iQ_.js} +2 -2
- package/dist/chunks/{index.BhY64fF0.js → index.uLUz1RDt.js} +1 -1
- package/dist/chunks/{inspector.CvQD-Nie.js → inspector.Br76Q2Mb.js} +1 -4
- package/dist/chunks/{moduleRunner.d.BNa-CL9e.d.ts → moduleRunner.d.CeYc7nZ0.d.ts} +1 -1
- package/dist/chunks/{node.BsdMi6DV.js → node.BwAWWjHZ.js} +2 -3
- package/dist/chunks/{plugin.d.C5phQR6o.d.ts → plugin.d.COyglhiI.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CVzhsTvK.d.ts → reporters.d.xGvTJYG3.d.ts} +41 -4
- package/dist/chunks/{resolveSnapshotEnvironment.DQVamkje.js → resolveSnapshotEnvironment.BsJpmVZR.js} +7 -8
- package/dist/chunks/{rpc.jKGRSXIH.js → rpc.cD77ENhU.js} +12 -13
- package/dist/chunks/{setup-common.NAWRuMRP.js → setup-common.BewgbkTd.js} +5 -5
- package/dist/chunks/{startModuleRunner.oAuCu1yL.js → startModuleRunner.DPBo3mme.js} +40 -48
- package/dist/chunks/{test.KC5tH8hC.js → test.CTuWuHYH.js} +5 -5
- package/dist/chunks/{typechecker.gXq-5P3n.js → typechecker.BfOQ86_a.js} +54 -77
- package/dist/chunks/{utils.DGKhod2J.js → utils.CG9h5ccR.js} +1 -4
- package/dist/chunks/{vi.CiJ0Laa6.js → vi.B2--mG9U.js} +35 -144
- package/dist/chunks/{worker.rPGLlbkW.js → worker.DVTUM2IW.js} +11 -15
- package/dist/chunks/{worker.d.B_Fd9M_w.d.ts → worker.d.buwuBpBt.d.ts} +1 -1
- package/dist/cli.js +3 -3
- package/dist/config.d.ts +6 -6
- package/dist/coverage.d.ts +5 -5
- package/dist/coverage.js +3 -3
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +8 -8
- package/dist/index.js +5 -5
- package/dist/module-evaluator.d.ts +3 -3
- package/dist/module-evaluator.js +10 -12
- package/dist/module-runner.js +2 -2
- package/dist/node.d.ts +8 -8
- package/dist/node.js +10 -10
- package/dist/reporters.d.ts +5 -5
- package/dist/reporters.js +3 -3
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +6 -6
- package/dist/snapshot.js +2 -2
- package/dist/suite.js +2 -2
- package/dist/worker-base.js +30 -32
- package/dist/worker-vm.js +19 -30
- package/dist/workers/runVmTests.js +10 -10
- package/package.json +18 -19
|
@@ -5,8 +5,8 @@ import { Writable } from 'node:stream';
|
|
|
5
5
|
import { ViteDevServer, TransformResult as TransformResult$1, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
|
|
6
6
|
import { MockedModule } from '@vitest/mocker';
|
|
7
7
|
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
8
|
-
import { B as
|
|
9
|
-
import {
|
|
8
|
+
import { B as BrowserTraceViewMode, a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.DGazh2r6.js';
|
|
9
|
+
import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.D9YV3JvA.js';
|
|
10
10
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
11
11
|
import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
|
|
12
12
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
@@ -80,9 +80,10 @@ interface BrowserModuleMocker {
|
|
|
80
80
|
delete: (sessionId: string, url: string) => Promise<void>;
|
|
81
81
|
clear: (sessionId: string) => Promise<void>;
|
|
82
82
|
}
|
|
83
|
-
interface BrowserProviderOption {
|
|
83
|
+
interface BrowserProviderOption<Options extends object = object> {
|
|
84
84
|
name: string;
|
|
85
85
|
supportedBrowser?: ReadonlyArray<string>;
|
|
86
|
+
options: Options;
|
|
86
87
|
factory: (project: TestProject) => BrowserProvider;
|
|
87
88
|
}
|
|
88
89
|
interface BrowserProvider {
|
|
@@ -178,6 +179,31 @@ interface BrowserConfigOptions {
|
|
|
178
179
|
testIdAttribute?: string;
|
|
179
180
|
};
|
|
180
181
|
/**
|
|
182
|
+
* Generate traces that can be viewed on https://trace.playwright.dev/
|
|
183
|
+
*
|
|
184
|
+
* This option is supported only by **playwright** provider.
|
|
185
|
+
*/
|
|
186
|
+
trace?: BrowserTraceViewMode | {
|
|
187
|
+
mode: BrowserTraceViewMode;
|
|
188
|
+
/**
|
|
189
|
+
* The directory where all traces will be stored. By default, Vitest
|
|
190
|
+
* stores all traces in `__traces__` folder close to the test file.
|
|
191
|
+
*/
|
|
192
|
+
tracesDir?: string;
|
|
193
|
+
/**
|
|
194
|
+
* Whether to capture screenshots during tracing. Screenshots are used to build a timeline preview.
|
|
195
|
+
* @default true
|
|
196
|
+
*/
|
|
197
|
+
screenshots?: boolean;
|
|
198
|
+
/**
|
|
199
|
+
* If this option is true tracing will
|
|
200
|
+
* - capture DOM snapshot on every action
|
|
201
|
+
* - record network activity
|
|
202
|
+
* @default true
|
|
203
|
+
*/
|
|
204
|
+
snapshots?: boolean;
|
|
205
|
+
};
|
|
206
|
+
/**
|
|
181
207
|
* Directory where screenshots will be saved when page.screenshot() is called
|
|
182
208
|
* If not set, all screenshots are saved to __screenshots__ directory in the same folder as the test file.
|
|
183
209
|
* If this is set, it will be resolved relative to the project root.
|
|
@@ -261,7 +287,7 @@ interface ProjectBrowser {
|
|
|
261
287
|
parseStacktrace: (stack: string) => ParsedStack[];
|
|
262
288
|
parseErrorStacktrace: (error: TestError, options?: StackTraceParserOptions) => ParsedStack[];
|
|
263
289
|
}
|
|
264
|
-
interface BrowserCommand<Payload extends unknown[]> {
|
|
290
|
+
interface BrowserCommand<Payload extends unknown[] = []> {
|
|
265
291
|
(context: BrowserCommandContext, ...payload: Payload): Awaitable<any>;
|
|
266
292
|
}
|
|
267
293
|
interface BrowserScript {
|
|
@@ -308,6 +334,12 @@ interface ResolvedBrowserOptions extends BrowserConfigOptions {
|
|
|
308
334
|
locators: {
|
|
309
335
|
testIdAttribute: string;
|
|
310
336
|
};
|
|
337
|
+
trace: {
|
|
338
|
+
mode: BrowserTraceViewMode;
|
|
339
|
+
tracesDir?: string;
|
|
340
|
+
screenshots?: boolean;
|
|
341
|
+
snapshots?: boolean;
|
|
342
|
+
};
|
|
311
343
|
}
|
|
312
344
|
type ToMatchScreenshotResolvePath = (data: {
|
|
313
345
|
/**
|
|
@@ -1512,6 +1544,7 @@ declare class StateManager {
|
|
|
1512
1544
|
clearFiles(project: TestProject, paths?: string[]): void;
|
|
1513
1545
|
updateId(task: Task, project: TestProject): void;
|
|
1514
1546
|
getReportedEntity(task: Task): TestModule | TestCase | TestSuite | undefined;
|
|
1547
|
+
getReportedEntityById(taskId: string): TestModule | TestCase | TestSuite | undefined;
|
|
1515
1548
|
updateTasks(packs: TaskResultPack[]): void;
|
|
1516
1549
|
updateUserLog(log: UserConsoleLog): void;
|
|
1517
1550
|
getCountOfFailedTests(): number;
|
|
@@ -1674,6 +1707,10 @@ declare class Vitest {
|
|
|
1674
1707
|
* Merge reports from multiple runs located in the specified directory (value from `--merge-reports` if not specified).
|
|
1675
1708
|
*/
|
|
1676
1709
|
mergeReports(directory?: string): Promise<TestRunResult>;
|
|
1710
|
+
/**
|
|
1711
|
+
* Returns the seed, if tests are running in a random order.
|
|
1712
|
+
*/
|
|
1713
|
+
getSeed(): number | null;
|
|
1677
1714
|
collect(filters?: string[]): Promise<TestRunResult>;
|
|
1678
1715
|
/**
|
|
1679
1716
|
* Returns the list of test files that match the config and filters.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { chai } from '@vitest/expect';
|
|
2
|
-
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.
|
|
3
|
-
import { r as rpc } from './rpc.
|
|
4
|
-
import { g as getWorkerState } from './utils.
|
|
5
|
-
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.
|
|
2
|
+
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.BewgbkTd.js';
|
|
3
|
+
import { r as rpc } from './rpc.cD77ENhU.js';
|
|
4
|
+
import { g as getWorkerState } from './utils.CG9h5ccR.js';
|
|
5
|
+
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.CTuWuHYH.js';
|
|
6
6
|
|
|
7
7
|
function setupChaiConfig(config) {
|
|
8
8
|
Object.assign(chai.config, config);
|
|
@@ -15,7 +15,7 @@ async function getTestRunnerConstructor(config, moduleRunner) {
|
|
|
15
15
|
return mod.default;
|
|
16
16
|
}
|
|
17
17
|
async function resolveTestRunner(config, moduleRunner) {
|
|
18
|
-
const
|
|
18
|
+
const testRunner = new (await (getTestRunnerConstructor(config, moduleRunner)))(config);
|
|
19
19
|
if (Object.defineProperty(testRunner, "moduleRunner", {
|
|
20
20
|
value: moduleRunner,
|
|
21
21
|
enumerable: false,
|
|
@@ -61,8 +61,7 @@ async function resolveTestRunner(config, moduleRunner) {
|
|
|
61
61
|
const originalOnAfterRunTask = testRunner.onAfterRunTask;
|
|
62
62
|
return testRunner.onAfterRunTask = async (test) => {
|
|
63
63
|
if (config.bail && test.result?.state === "fail") {
|
|
64
|
-
|
|
65
|
-
if (currentFailures >= config.bail) rpc().onCancel("test-failure"), testRunner.cancel?.("test-failure");
|
|
64
|
+
if (1 + await rpc().getCountOfFailedTests() >= config.bail) rpc().onCancel("test-failure"), testRunner.cancel?.("test-failure");
|
|
66
65
|
}
|
|
67
66
|
await originalOnAfterRunTask?.call(testRunner, test);
|
|
68
67
|
}, testRunner;
|
|
@@ -70,7 +69,7 @@ async function resolveTestRunner(config, moduleRunner) {
|
|
|
70
69
|
|
|
71
70
|
async function resolveSnapshotEnvironment(config, executor) {
|
|
72
71
|
if (!config.snapshotEnvironment) {
|
|
73
|
-
const { VitestNodeSnapshotEnvironment } = await import('./node.
|
|
72
|
+
const { VitestNodeSnapshotEnvironment } = await import('./node.BwAWWjHZ.js');
|
|
74
73
|
return new VitestNodeSnapshotEnvironment();
|
|
75
74
|
}
|
|
76
75
|
const mod = await executor.import(config.snapshotEnvironment);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getSafeTimers } from '@vitest/utils/timers';
|
|
2
2
|
import { c as createBirpc } from './index.Bgo3tNWt.js';
|
|
3
|
-
import { g as getWorkerState } from './utils.
|
|
3
|
+
import { g as getWorkerState } from './utils.CG9h5ccR.js';
|
|
4
4
|
|
|
5
5
|
const { get } = Reflect;
|
|
6
6
|
function withSafeTimers(fn) {
|
|
@@ -9,8 +9,7 @@ function withSafeTimers(fn) {
|
|
|
9
9
|
if (globalThis.setTimeout = setTimeout, globalThis.clearTimeout = clearTimeout, setImmediate) globalThis.setImmediate = setImmediate;
|
|
10
10
|
if (clearImmediate) globalThis.clearImmediate = clearImmediate;
|
|
11
11
|
if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
|
|
12
|
-
|
|
13
|
-
return result;
|
|
12
|
+
return fn();
|
|
14
13
|
} finally {
|
|
15
14
|
if (globalThis.setTimeout = currentSetTimeout, globalThis.clearTimeout = currentClearTimeout, globalThis.setImmediate = currentSetImmediate, globalThis.clearImmediate = currentClearImmediate, globalThis.process && nextTick) nextTick(() => {
|
|
16
15
|
globalThis.process.nextTick = currentNextTick;
|
|
@@ -27,17 +26,17 @@ function createRuntimeRpc(options) {
|
|
|
27
26
|
let setCancel = (_reason) => {};
|
|
28
27
|
const onCancel = new Promise((resolve) => {
|
|
29
28
|
setCancel = resolve;
|
|
30
|
-
})
|
|
31
|
-
eventNames: [
|
|
32
|
-
"onUserConsoleLog",
|
|
33
|
-
"onCollected",
|
|
34
|
-
"onCancel"
|
|
35
|
-
],
|
|
36
|
-
timeout: -1,
|
|
37
|
-
...options
|
|
38
|
-
}));
|
|
29
|
+
});
|
|
39
30
|
return {
|
|
40
|
-
rpc,
|
|
31
|
+
rpc: createSafeRpc(createBirpc({ onCancel: setCancel }, {
|
|
32
|
+
eventNames: [
|
|
33
|
+
"onUserConsoleLog",
|
|
34
|
+
"onCollected",
|
|
35
|
+
"onCancel"
|
|
36
|
+
],
|
|
37
|
+
timeout: -1,
|
|
38
|
+
...options
|
|
39
|
+
})),
|
|
41
40
|
onCancel
|
|
42
41
|
};
|
|
43
42
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as resolveCoverageProviderModule } from './coverage.D_JHT54q.js';
|
|
2
2
|
import { addSerializer } from '@vitest/snapshot';
|
|
3
3
|
import { setSafeTimers } from '@vitest/utils/timers';
|
|
4
|
-
import { g as getWorkerState } from './utils.
|
|
4
|
+
import { g as getWorkerState } from './utils.CG9h5ccR.js';
|
|
5
5
|
|
|
6
6
|
async function startCoverageInsideWorker(options, loader, runtimeOptions) {
|
|
7
7
|
const coverageModule = await resolveCoverageProviderModule(options, loader);
|
|
@@ -18,7 +18,7 @@ async function stopCoverageInsideWorker(options, loader, runtimeOptions) {
|
|
|
18
18
|
|
|
19
19
|
let globalSetup = false;
|
|
20
20
|
async function setupCommonEnv(config) {
|
|
21
|
-
if (setupDefines(config), setupEnv(config.env), !globalSetup && (globalSetup = true, setSafeTimers(), config.globals)) (await import('./globals.
|
|
21
|
+
if (setupDefines(config), setupEnv(config.env), !globalSetup && (globalSetup = true, setSafeTimers(), config.globals)) (await import('./globals.DC4ntO86.js')).registerApiGlobally();
|
|
22
22
|
}
|
|
23
23
|
function setupDefines(config) {
|
|
24
24
|
for (const key in config.defines) globalThis[key] = config.defines[key];
|
|
@@ -35,14 +35,14 @@ async function loadDiffConfig(config, moduleRunner) {
|
|
|
35
35
|
throw new Error(`invalid diff config file ${config.diff}. Must have a default export with config object`);
|
|
36
36
|
}
|
|
37
37
|
async function loadSnapshotSerializers(config, moduleRunner) {
|
|
38
|
-
const files = config.snapshotSerializers
|
|
38
|
+
const files = config.snapshotSerializers;
|
|
39
|
+
(await Promise.all(files.map(async (file) => {
|
|
39
40
|
const mo = await moduleRunner.import(file);
|
|
40
41
|
if (!mo || typeof mo.default !== "object" || mo.default === null) throw new Error(`invalid snapshot serializer file ${file}. Must export a default object`);
|
|
41
42
|
const config = mo.default;
|
|
42
43
|
if (typeof config.test !== "function" || typeof config.serialize !== "function" && typeof config.print !== "function") throw new TypeError(`invalid snapshot serializer in ${file}. Must have a 'test' method along with either a 'serialize' or 'print' method.`);
|
|
43
44
|
return config;
|
|
44
|
-
}));
|
|
45
|
-
snapshotSerializers.forEach((serializer) => addSerializer(serializer));
|
|
45
|
+
}))).forEach((serializer) => addSerializer(serializer));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
export { stopCoverageInsideWorker as a, loadSnapshotSerializers as b, setupCommonEnv as c, loadDiffConfig as l, startCoverageInsideWorker as s, takeCoverageInsideWorker as t };
|
|
@@ -28,8 +28,8 @@ const _UNC_REGEX = /^[/\\]{2}/, _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\
|
|
|
28
28
|
for (const seg of segments) {
|
|
29
29
|
if (!seg) continue;
|
|
30
30
|
if (path.length > 0) {
|
|
31
|
-
const pathTrailing = path[path.length - 1] === "/", segLeading = seg[0] === "/"
|
|
32
|
-
if (
|
|
31
|
+
const pathTrailing = path[path.length - 1] === "/", segLeading = seg[0] === "/";
|
|
32
|
+
if (pathTrailing && segLeading) path += seg.slice(1);
|
|
33
33
|
else path += pathTrailing || segLeading ? seg : `/${seg}`;
|
|
34
34
|
} else path += seg;
|
|
35
35
|
}
|
|
@@ -114,17 +114,14 @@ function findMockRedirect(root, mockPath, external) {
|
|
|
114
114
|
const baseOriginal = basename(path);
|
|
115
115
|
function findFile(mockFolder, baseOriginal) {
|
|
116
116
|
const files = readdirSync(mockFolder);
|
|
117
|
-
for (const file of files) {
|
|
118
|
-
const
|
|
119
|
-
if
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const indexFile = findFile(path, "index");
|
|
126
|
-
if (indexFile) return indexFile;
|
|
127
|
-
}
|
|
117
|
+
for (const file of files) if (basename(file, extname(file)) === baseOriginal) {
|
|
118
|
+
const path = resolve(mockFolder, file);
|
|
119
|
+
// if the same name, return the file
|
|
120
|
+
if (statSync(path).isFile()) return path;
|
|
121
|
+
{
|
|
122
|
+
// find folder/index.{js,ts}
|
|
123
|
+
const indexFile = findFile(path, "index");
|
|
124
|
+
if (indexFile) return indexFile;
|
|
128
125
|
}
|
|
129
126
|
}
|
|
130
127
|
return null;
|
|
@@ -278,7 +275,7 @@ class VitestMocker {
|
|
|
278
275
|
if (prop === "then") {
|
|
279
276
|
if (target instanceof Promise) return target.then.bind(target);
|
|
280
277
|
} else if (!(prop in target)) {
|
|
281
|
-
if (this.filterPublicKeys.includes(prop)) return
|
|
278
|
+
if (this.filterPublicKeys.includes(prop)) return;
|
|
282
279
|
throw this.createError(`[vitest] No "${String(prop)}" export is defined on the "${mock.raw}" mock. Did you forget to return it from "vi.mock"?
|
|
283
280
|
If you need to partially mock a module, you can use "importOriginal" helper inside:
|
|
284
281
|
`, `vi.mock(import("${mock.raw}"), async (importOriginal) => {
|
|
@@ -302,8 +299,7 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
|
|
|
302
299
|
return `mock:${dep}`;
|
|
303
300
|
}
|
|
304
301
|
getDependencyMock(id) {
|
|
305
|
-
|
|
306
|
-
return registry.getById(fixLeadingSlashes(id));
|
|
302
|
+
return this.getMockerRegistry().getById(fixLeadingSlashes(id));
|
|
307
303
|
}
|
|
308
304
|
findMockRedirect(mockPath, external) {
|
|
309
305
|
return findMockRedirect(this.root, mockPath, external);
|
|
@@ -318,8 +314,7 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
|
|
|
318
314
|
}, object, mockExports);
|
|
319
315
|
}
|
|
320
316
|
unmockPath(id) {
|
|
321
|
-
|
|
322
|
-
registry.deleteById(id), this.invalidateModuleById(id);
|
|
317
|
+
this.getMockerRegistry().deleteById(id), this.invalidateModuleById(id);
|
|
323
318
|
}
|
|
324
319
|
mockPath(originalId, id, url, external, mockType, factory) {
|
|
325
320
|
const registry = this.getMockerRegistry();
|
|
@@ -334,8 +329,8 @@ If you need to partially mock a module, you can use "importOriginal" helper insi
|
|
|
334
329
|
this.invalidateModuleById(id);
|
|
335
330
|
}
|
|
336
331
|
async importActual(rawId, importer, callstack) {
|
|
337
|
-
const { url } = await this.resolveId(rawId, importer), node = await this.moduleRunner.fetchModule(url, importer)
|
|
338
|
-
return
|
|
332
|
+
const { url } = await this.resolveId(rawId, importer), node = await this.moduleRunner.fetchModule(url, importer);
|
|
333
|
+
return await this.moduleRunner.cachedRequest(node.url, node, callstack || [importer], void 0, true);
|
|
339
334
|
}
|
|
340
335
|
async importMock(rawId, importer) {
|
|
341
336
|
const { id, url, external } = await this.resolveId(rawId, importer);
|
|
@@ -420,11 +415,8 @@ const prefixedBuiltins = new Set([
|
|
|
420
415
|
// C:\root\id.js -> /id.js
|
|
421
416
|
// TODO: expose this in vite/module-runner
|
|
422
417
|
function normalizeModuleId(file) {
|
|
423
|
-
if (prefixedBuiltins.has(file)) return file;
|
|
424
|
-
// unix style, but Windows path still starts with the drive letter to check the root
|
|
425
|
-
const unixFile = slash(file).replace(/^\/@fs\//, isWindows$1 ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/");
|
|
426
418
|
// if it's not in the root, keep it as a path, not a URL
|
|
427
|
-
return
|
|
419
|
+
return prefixedBuiltins.has(file) ? file : slash(file).replace(/^\/@fs\//, isWindows$1 ? "" : "/").replace(/^node:/, "").replace(/^\/+/, "/").replace(/^file:\//, "/");
|
|
428
420
|
}
|
|
429
421
|
const windowsSlashRE = /\\/g;
|
|
430
422
|
function slash(p) {
|
|
@@ -446,17 +438,27 @@ class VitestTransport {
|
|
|
446
438
|
const { name, data } = event.data;
|
|
447
439
|
if (name !== "fetchModule") return { error: /* @__PURE__ */ new Error(`Unknown method: ${name}. Expected "fetchModule".`) };
|
|
448
440
|
try {
|
|
449
|
-
|
|
450
|
-
return { result };
|
|
441
|
+
return { result: await this.options.fetchModule(...data) };
|
|
451
442
|
} catch (error) {
|
|
452
443
|
return { error };
|
|
453
444
|
}
|
|
454
445
|
}
|
|
455
446
|
}
|
|
456
447
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
const
|
|
448
|
+
const createNodeImportMeta = (modulePath) => {
|
|
449
|
+
if (!viteModuleRunner.createDefaultImportMeta) throw new Error(`createNodeImportMeta is not supported in this version of Vite.`);
|
|
450
|
+
const defaultMeta = viteModuleRunner.createDefaultImportMeta(modulePath), href = defaultMeta.url, importMetaResolver = createImportMetaResolver();
|
|
451
|
+
return {
|
|
452
|
+
...defaultMeta,
|
|
453
|
+
main: false,
|
|
454
|
+
resolve(id, parent) {
|
|
455
|
+
return (importMetaResolver ?? defaultMeta.resolve)(id, parent ?? href);
|
|
456
|
+
}
|
|
457
|
+
};
|
|
458
|
+
};
|
|
459
|
+
function createImportMetaResolver() {
|
|
460
|
+
if (import.meta.resolve) return (specifier, importer) => import.meta.resolve(specifier, importer);
|
|
461
|
+
}
|
|
460
462
|
// @ts-expect-error overriding private method
|
|
461
463
|
class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
|
|
462
464
|
mocker;
|
|
@@ -491,11 +493,10 @@ class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
|
|
|
491
493
|
}
|
|
492
494
|
async import(rawId) {
|
|
493
495
|
const resolved = await this.vitestOptions.transport.resolveId(rawId);
|
|
494
|
-
return
|
|
496
|
+
return super.import(resolved ? resolved.url : rawId);
|
|
495
497
|
}
|
|
496
498
|
async fetchModule(url, importer) {
|
|
497
|
-
|
|
498
|
-
return module;
|
|
499
|
+
return await this.cachedModule(url, importer);
|
|
499
500
|
}
|
|
500
501
|
_cachedRequest(url, module, callstack = [], metadata) {
|
|
501
502
|
// @ts-expect-error "cachedRequest" is private
|
|
@@ -564,10 +565,10 @@ const dispose = [];
|
|
|
564
565
|
function listenForErrors(state) {
|
|
565
566
|
dispose.forEach((fn) => fn()), dispose.length = 0;
|
|
566
567
|
function catchError(err, type, event) {
|
|
567
|
-
const worker = state()
|
|
568
|
+
const worker = state();
|
|
568
569
|
// if there is another listener, assume that it's handled by user code
|
|
569
570
|
// one is Vitest's own listener
|
|
570
|
-
if (listeners.length > 1) return;
|
|
571
|
+
if (process.listeners(event).length > 1) return;
|
|
571
572
|
const error = serializeValue(err);
|
|
572
573
|
if (typeof error === "object" && error != null) {
|
|
573
574
|
if (error.VITEST_TEST_NAME = worker.current?.type === "test" ? worker.current.name : void 0, worker.filepath) error.VITEST_TEST_PATH = worker.filepath;
|
|
@@ -614,10 +615,7 @@ function startVitestModuleRunner(options) {
|
|
|
614
615
|
if (isWindows) {
|
|
615
616
|
if (id[1] === ":") {
|
|
616
617
|
// The drive letter is different for whatever reason, we need to normalize it to CWD
|
|
617
|
-
if (id[0] !== cwd[0] && id[0].toUpperCase() === cwd[0].toUpperCase())
|
|
618
|
-
const isUpperCase = cwd[0].toUpperCase() === cwd[0];
|
|
619
|
-
id = (isUpperCase ? id[0].toUpperCase() : id[0].toLowerCase()) + id.slice(1);
|
|
620
|
-
}
|
|
618
|
+
if (id[0] !== cwd[0] && id[0].toUpperCase() === cwd[0].toUpperCase()) id = (cwd[0].toUpperCase() === cwd[0] ? id[0].toUpperCase() : id[0].toLowerCase()) + id.slice(1);
|
|
621
619
|
// always mark absolute windows paths, otherwise Vite will externalize it
|
|
622
620
|
id = `/@id/${id}`;
|
|
623
621
|
}
|
|
@@ -642,14 +640,10 @@ function startVitestModuleRunner(options) {
|
|
|
642
640
|
type: "builtin"
|
|
643
641
|
};
|
|
644
642
|
const result = await rpc().fetch(id, importer, environment(), options);
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
...result
|
|
650
|
-
};
|
|
651
|
-
}
|
|
652
|
-
return result;
|
|
643
|
+
return "cached" in result ? {
|
|
644
|
+
code: readFileSync(result.tmp, "utf-8"),
|
|
645
|
+
...result
|
|
646
|
+
} : result;
|
|
653
647
|
} catch (cause) {
|
|
654
648
|
// rethrow vite error if it cannot load the module because it's not resolved
|
|
655
649
|
if (typeof cause === "object" && cause != null && cause.code === "ERR_LOAD_URL" || typeof cause?.message === "string" && cause.message.includes("Failed to load url") || typeof cause?.message === "string" && cause.message.startsWith("Cannot find module '")) {
|
|
@@ -669,8 +663,6 @@ function startVitestModuleRunner(options) {
|
|
|
669
663
|
vm,
|
|
670
664
|
createImportMeta: options.createImportMeta
|
|
671
665
|
});
|
|
672
|
-
// await moduleRunner.import('/@vite/env')
|
|
673
|
-
// await moduleRunner.mocker.initializeSpyModule()
|
|
674
666
|
return moduleRunner;
|
|
675
667
|
}
|
|
676
668
|
function toBuiltin(id) {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { updateTask } from '@vitest/runner';
|
|
2
2
|
import { createDefer } from '@vitest/utils/helpers';
|
|
3
3
|
import { getSafeTimers } from '@vitest/utils/timers';
|
|
4
|
-
import { a as getBenchOptions, g as getBenchFn } from './benchmark.
|
|
5
|
-
import { g as getWorkerState } from './utils.
|
|
4
|
+
import { a as getBenchOptions, g as getBenchFn } from './benchmark.DHKMYAts.js';
|
|
5
|
+
import { g as getWorkerState } from './utils.CG9h5ccR.js';
|
|
6
6
|
import { setState, GLOBAL_EXPECT, getState } from '@vitest/expect';
|
|
7
7
|
import { getTests, getNames, getTestName } from '@vitest/runner/utils';
|
|
8
8
|
import { processError } from '@vitest/utils/error';
|
|
9
9
|
import { normalize } from 'pathe';
|
|
10
|
-
import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.
|
|
11
|
-
import { r as rpc } from './rpc.
|
|
10
|
+
import { a as getSnapshotClient, i as inject, c as createExpect, v as vi } from './vi.B2--mG9U.js';
|
|
11
|
+
import { r as rpc } from './rpc.cD77ENhU.js';
|
|
12
12
|
|
|
13
13
|
function createBenchmarkResult(name) {
|
|
14
14
|
return {
|
|
@@ -37,7 +37,7 @@ async function runBenchmarkSuite(suite, runner) {
|
|
|
37
37
|
}, updateTask$1("suite-prepare", suite);
|
|
38
38
|
const addBenchTaskListener = (task, benchmark) => {
|
|
39
39
|
task.addEventListener("complete", (e) => {
|
|
40
|
-
const
|
|
40
|
+
const taskRes = e.task.result, result = benchmark.result.benchmark;
|
|
41
41
|
benchmark.result.state = "pass", Object.assign(result, taskRes);
|
|
42
42
|
// compute extra stats and free raw samples as early as possible
|
|
43
43
|
const samples = result.samples;
|