vitest 2.0.0-beta.3 → 2.0.0-beta.5
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/browser.d.ts +5 -1
- package/dist/browser.js +18 -2
- package/dist/chunks/{integrations-globals.D0I8wu4f.js → integrations-globals.BK0Cn4q1.js} +3 -4
- package/dist/chunks/{runtime-console.CUES-L8X.js → runtime-console.DiVMr5d4.js} +54 -24
- package/dist/chunks/{runtime-runBaseTests.CsxVA4nP.js → runtime-runBaseTests.C-Bkopka.js} +5 -6
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +1 -1
- package/dist/coverage.d.ts +1 -1
- package/dist/environments.d.ts +1 -1
- package/dist/execute.d.ts +2 -2
- package/dist/execute.js +1 -1
- package/dist/index-C7JhjWOq.d.ts +1565 -0
- package/dist/index.d.ts +6 -1448
- package/dist/index.js +3 -4
- package/dist/node.d.ts +2 -6
- package/dist/node.js +6 -6
- package/dist/{reporters-C-3dxOaA.d.ts → reporters-qky6mwBH.d.ts} +237 -91
- package/dist/reporters.d.ts +1 -1
- package/dist/reporters.js +4 -4
- package/dist/runners.d.ts +2 -1
- package/dist/runners.js +6 -1
- package/dist/{suite-V5kCKZme.d.ts → suite-B5_jYIf8.d.ts} +1 -1
- package/dist/suite.d.ts +2 -2
- package/dist/vendor/{base.CfOCwoIE.js → base.D4XK-wRp.js} +2 -2
- package/dist/vendor/{cac.f5m2SesE.js → cac.sXjWMctD.js} +47 -16
- package/dist/vendor/{cli-api.pZNNj7LX.js → cli-api.BH9TJcYU.js} +372 -200
- package/dist/vendor/{constants.XmjJgDXx.js → constants.TCjCaw2D.js} +2 -1
- package/dist/vendor/{execute.Bwzklsfj.js → execute.BHj6OMh4.js} +2 -2
- package/dist/vendor/{index.DOAUPIJU.js → index.CyGfDRbW.js} +34 -14
- package/dist/vendor/{index.BHPXakMe.js → index.DHRpy7zp.js} +1 -1
- package/dist/vendor/{index.BkeKAX-R.js → index.DwR86H5i.js} +26 -3
- package/dist/vendor/{setup-common.6St9QHh1.js → setup-common.BhJvzjns.js} +2 -2
- package/dist/vendor/{utils.D5gGkwyH.js → utils.YuQ3LT2a.js} +1 -1
- package/dist/vendor/{vi.B31D70yH.js → vi.C6AfDXK6.js} +23 -11
- package/dist/vendor/{vm.rKHnSoLJ.js → vm.Ow-X2mkS.js} +2 -2
- package/dist/workers/forks.js +2 -2
- package/dist/workers/runVmTests.js +4 -5
- package/dist/workers/threads.js +2 -2
- package/dist/workers/vmForks.js +3 -3
- package/dist/workers/vmThreads.js +3 -3
- package/dist/workers.d.ts +1 -1
- package/dist/workers.js +4 -4
- package/package.json +9 -9
- package/dist/vendor/run-once.DLomgGUH.js +0 -27
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { A as API_PATH, d as defaultPort, e as extraInlineDeps, a as defaultBrowserPort, b as defaultInspectPort, E as EXIT_CODE_RESTART, w as workspacesFiles, C as CONFIG_NAMES, c as configFiles } from './constants.
|
|
1
|
+
import { join, resolve, isAbsolute, relative, dirname, normalize, basename, extname as extname$1, toNamespacedPath } from 'pathe';
|
|
2
|
+
import { A as API_PATH, d as defaultPort, e as extraInlineDeps, a as defaultBrowserPort, b as defaultInspectPort, B as BROWSER_API_PATH, E as EXIT_CODE_RESTART, w as workspacesFiles, C as CONFIG_NAMES, c as configFiles } from './constants.TCjCaw2D.js';
|
|
3
3
|
import { g as getCoverageProvider, C as CoverageProviderMap } from './coverage.ChSqD-qS.js';
|
|
4
4
|
import { g as getEnvPackageName } from './index.DeR1hhfY.js';
|
|
5
|
-
import {
|
|
5
|
+
import { searchForWorkspaceRoot, version, isFileServingAllowed, createServer, mergeConfig } from 'vite';
|
|
6
6
|
import path$8, { win32 } from 'node:path';
|
|
7
7
|
import url, { fileURLToPath as fileURLToPath$1, pathToFileURL as pathToFileURL$1, URL as URL$2 } from 'node:url';
|
|
8
8
|
import process$1 from 'node:process';
|
|
9
|
-
import fs$8, { promises as promises$1, existsSync, statSync as statSync$1, realpathSync, readFileSync } from 'node:fs';
|
|
9
|
+
import fs$8, { promises as promises$1, existsSync, statSync as statSync$1, realpathSync, readdirSync, readFileSync } from 'node:fs';
|
|
10
10
|
import { MessageChannel, isMainThread } from 'node:worker_threads';
|
|
11
11
|
import { c as commonjsGlobal, g as getDefaultExportFromCjs } from './_commonjsHelpers.BFTU3MAI.js';
|
|
12
12
|
import require$$0 from 'os';
|
|
@@ -19,14 +19,14 @@ import c from 'picocolors';
|
|
|
19
19
|
import { ViteNodeRunner } from 'vite-node/client';
|
|
20
20
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
21
21
|
import { ViteNodeServer } from 'vite-node/server';
|
|
22
|
-
import { v as version$1 } from './cac.
|
|
22
|
+
import { v as version$1 } from './cac.sXjWMctD.js';
|
|
23
23
|
import { hasFailed, createFileTask, getTasks, getTests } from '@vitest/runner/utils';
|
|
24
24
|
import { n as noop$1, b as isPrimitive, c as groupBy, A as AggregateErrorPonyfill, a as slash$1, t as toArray, d as deepMerge, e as nanoid, w as wildcardPatternToRegExp, f as stdout } from './base._gnK9Slw.js';
|
|
25
25
|
import { createDefer, toArray as toArray$1, notNullish } from '@vitest/utils';
|
|
26
26
|
import { a as isWindows } from './env.bmJgw1qP.js';
|
|
27
|
-
import { rootDir } from '../path.js';
|
|
27
|
+
import { rootDir, distDir } from '../path.js';
|
|
28
28
|
import { c as createBirpc } from './index.BpSiYbpB.js';
|
|
29
|
-
import { s as stringify, p as parse$3, w as wrapSerializableConfig, f as Typechecker, R as ReportersMap, e as BenchmarkReportsMap, g as RandomSequencer, B as BaseSequencer, h as findNodeAround, i as generateCodeFrame, j as highlightCode, L as Logger, k as BlobReporter, r as readBlobs } from './index.
|
|
29
|
+
import { s as stringify, p as parse$3, w as wrapSerializableConfig, f as Typechecker, R as ReportersMap, e as BenchmarkReportsMap, g as RandomSequencer, B as BaseSequencer, h as findNodeAround, i as generateCodeFrame, j as highlightCode, L as Logger, k as BlobReporter, r as readBlobs } from './index.CyGfDRbW.js';
|
|
30
30
|
import require$$0$4 from 'zlib';
|
|
31
31
|
import require$$0$5 from 'buffer';
|
|
32
32
|
import require$$1 from 'crypto';
|
|
@@ -47,13 +47,13 @@ import { builtinModules, createRequire } from 'node:module';
|
|
|
47
47
|
import assert from 'node:assert';
|
|
48
48
|
import { format as format$2, inspect } from 'node:util';
|
|
49
49
|
import { isCI, provider as provider$1 } from 'std-env';
|
|
50
|
-
import { normalizeRequestId, cleanUrl } from 'vite-node/utils';
|
|
50
|
+
import { normalizeRequestId, isNodeBuiltin, cleanUrl } from 'vite-node/utils';
|
|
51
51
|
import MagicString from 'magic-string';
|
|
52
52
|
import { esmWalker } from '@vitest/utils/ast';
|
|
53
|
-
import { d as divider, s as stripAnsi } from './utils.D5gGkwyH.js';
|
|
54
53
|
import { a as removeUndefinedValues } from './index._7XLd8Kd.js';
|
|
55
54
|
import readline from 'node:readline';
|
|
56
55
|
import require$$0$6 from 'readline';
|
|
56
|
+
import { s as stripAnsi } from './utils.YuQ3LT2a.js';
|
|
57
57
|
|
|
58
58
|
function _mergeNamespaces(n, m) {
|
|
59
59
|
m.forEach(function (e) {
|
|
@@ -70,21 +70,23 @@ function _mergeNamespaces(n, m) {
|
|
|
70
70
|
return Object.freeze(n);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
async function getModuleGraph(ctx, id) {
|
|
73
|
+
async function getModuleGraph(ctx, projectName, id, browser = false) {
|
|
74
74
|
const graph = {};
|
|
75
75
|
const externalized = /* @__PURE__ */ new Set();
|
|
76
76
|
const inlined = /* @__PURE__ */ new Set();
|
|
77
|
+
const project = ctx.getProjectByName(projectName);
|
|
77
78
|
function clearId(id2) {
|
|
78
79
|
return (id2 == null ? void 0 : id2.replace(/\?v=\w+$/, "")) || "";
|
|
79
80
|
}
|
|
80
81
|
async function get(mod, seen = /* @__PURE__ */ new Map()) {
|
|
82
|
+
var _a;
|
|
81
83
|
if (!mod || !mod.id)
|
|
82
84
|
return;
|
|
83
85
|
if (seen.has(mod))
|
|
84
86
|
return seen.get(mod);
|
|
85
87
|
let id2 = clearId(mod.id);
|
|
86
88
|
seen.set(mod, id2);
|
|
87
|
-
const rewrote = await
|
|
89
|
+
const rewrote = browser ? ((_a = mod.file) == null ? void 0 : _a.includes(project.browser.config.cacheDir)) ? mod.id : false : await project.vitenode.shouldExternalize(id2);
|
|
88
90
|
if (rewrote) {
|
|
89
91
|
id2 = rewrote;
|
|
90
92
|
externalized.add(id2);
|
|
@@ -96,7 +98,10 @@ async function getModuleGraph(ctx, id) {
|
|
|
96
98
|
graph[id2] = (await Promise.all(mods.map((m) => get(m, seen)))).filter(Boolean);
|
|
97
99
|
return id2;
|
|
98
100
|
}
|
|
99
|
-
|
|
101
|
+
if (browser && project.browser)
|
|
102
|
+
await get(project.browser.moduleGraph.getModuleById(id));
|
|
103
|
+
else
|
|
104
|
+
await get(project.server.moduleGraph.getModuleById(id));
|
|
100
105
|
return {
|
|
101
106
|
graph,
|
|
102
107
|
externalized: Array.from(externalized),
|
|
@@ -7582,9 +7587,8 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
|
|
|
7582
7587
|
|
|
7583
7588
|
var WebSocketServer$1 = /*@__PURE__*/getDefaultExportFromCjs(websocketServer);
|
|
7584
7589
|
|
|
7585
|
-
function setup(
|
|
7590
|
+
function setup(ctx, _server) {
|
|
7586
7591
|
var _a;
|
|
7587
|
-
const ctx = "ctx" in vitestOrWorkspace ? vitestOrWorkspace.ctx : vitestOrWorkspace;
|
|
7588
7592
|
const wss = new WebSocketServer$1({ noServer: true });
|
|
7589
7593
|
const clients = /* @__PURE__ */ new Map();
|
|
7590
7594
|
const server = _server || ctx.server;
|
|
@@ -7599,16 +7603,9 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7599
7603
|
setupClient(ws);
|
|
7600
7604
|
});
|
|
7601
7605
|
});
|
|
7602
|
-
function checkFileAccess(path) {
|
|
7603
|
-
if (!isFileServingAllowed(path, server))
|
|
7604
|
-
throw new Error(`Access denied to "${path}". See Vite config documentation for "server.fs": https://vitejs.dev/config/server-options.html#server-fs-strict.`);
|
|
7605
|
-
}
|
|
7606
7606
|
function setupClient(ws) {
|
|
7607
7607
|
const rpc = createBirpc(
|
|
7608
7608
|
{
|
|
7609
|
-
async onUnhandledError(error, type) {
|
|
7610
|
-
ctx.state.catchError(error, type);
|
|
7611
|
-
},
|
|
7612
7609
|
async onCollected(files) {
|
|
7613
7610
|
ctx.state.collectFiles(files);
|
|
7614
7611
|
await ctx.report("onCollected", files);
|
|
@@ -7617,31 +7614,12 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7617
7614
|
ctx.state.updateTasks(packs);
|
|
7618
7615
|
await ctx.report("onTaskUpdate", packs);
|
|
7619
7616
|
},
|
|
7620
|
-
onAfterSuiteRun(meta) {
|
|
7621
|
-
var _a2;
|
|
7622
|
-
(_a2 = ctx.coverageProvider) == null ? void 0 : _a2.onAfterSuiteRun(meta);
|
|
7623
|
-
},
|
|
7624
7617
|
getFiles() {
|
|
7625
7618
|
return ctx.state.getFiles();
|
|
7626
7619
|
},
|
|
7627
7620
|
getPaths() {
|
|
7628
7621
|
return ctx.state.getPaths();
|
|
7629
7622
|
},
|
|
7630
|
-
sendLog(log) {
|
|
7631
|
-
return ctx.report("onUserConsoleLog", log);
|
|
7632
|
-
},
|
|
7633
|
-
resolveSnapshotPath(testPath) {
|
|
7634
|
-
return ctx.snapshot.resolvePath(testPath);
|
|
7635
|
-
},
|
|
7636
|
-
resolveSnapshotRawPath(testPath, rawPath) {
|
|
7637
|
-
return ctx.snapshot.resolveRawPath(testPath, rawPath);
|
|
7638
|
-
},
|
|
7639
|
-
async readSnapshotFile(snapshotPath) {
|
|
7640
|
-
checkFileAccess(snapshotPath);
|
|
7641
|
-
if (!existsSync(snapshotPath))
|
|
7642
|
-
return null;
|
|
7643
|
-
return promises$1.readFile(snapshotPath, "utf-8");
|
|
7644
|
-
},
|
|
7645
7623
|
async readTestFile(id) {
|
|
7646
7624
|
if (!ctx.state.filesMap.has(id) || !existsSync(id))
|
|
7647
7625
|
return null;
|
|
@@ -7652,32 +7630,11 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7652
7630
|
throw new Error(`Test file "${id}" was not registered, so it cannot be updated using the API.`);
|
|
7653
7631
|
return promises$1.writeFile(id, content, "utf-8");
|
|
7654
7632
|
},
|
|
7655
|
-
async saveSnapshotFile(id, content) {
|
|
7656
|
-
checkFileAccess(id);
|
|
7657
|
-
await promises$1.mkdir(dirname(id), { recursive: true });
|
|
7658
|
-
return promises$1.writeFile(id, content, "utf-8");
|
|
7659
|
-
},
|
|
7660
|
-
async removeSnapshotFile(id) {
|
|
7661
|
-
checkFileAccess(id);
|
|
7662
|
-
if (!existsSync(id))
|
|
7663
|
-
throw new Error(`Snapshot file "${id}" does not exist.`);
|
|
7664
|
-
return promises$1.unlink(id);
|
|
7665
|
-
},
|
|
7666
|
-
snapshotSaved(snapshot) {
|
|
7667
|
-
ctx.snapshot.add(snapshot);
|
|
7668
|
-
},
|
|
7669
7633
|
async rerun(files) {
|
|
7670
7634
|
await ctx.rerunFiles(files);
|
|
7671
7635
|
},
|
|
7672
7636
|
getConfig() {
|
|
7673
|
-
return
|
|
7674
|
-
},
|
|
7675
|
-
async getBrowserFileSourceMap(id) {
|
|
7676
|
-
var _a2, _b;
|
|
7677
|
-
if (!("ctx" in vitestOrWorkspace))
|
|
7678
|
-
return void 0;
|
|
7679
|
-
const mod = (_a2 = vitestOrWorkspace.browser) == null ? void 0 : _a2.moduleGraph.getModuleById(id);
|
|
7680
|
-
return (_b = mod == null ? void 0 : mod.transformResult) == null ? void 0 : _b.map;
|
|
7637
|
+
return ctx.config;
|
|
7681
7638
|
},
|
|
7682
7639
|
async getTransformResult(id) {
|
|
7683
7640
|
const result = await ctx.vitenode.transformRequest(id);
|
|
@@ -7689,59 +7646,21 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7689
7646
|
return result;
|
|
7690
7647
|
}
|
|
7691
7648
|
},
|
|
7692
|
-
async getModuleGraph(id) {
|
|
7693
|
-
return getModuleGraph(ctx, id);
|
|
7649
|
+
async getModuleGraph(project, id, browser) {
|
|
7650
|
+
return getModuleGraph(ctx, project, id, browser);
|
|
7694
7651
|
},
|
|
7695
7652
|
updateSnapshot(file) {
|
|
7696
7653
|
if (!file)
|
|
7697
7654
|
return ctx.updateSnapshot();
|
|
7698
7655
|
return ctx.updateSnapshot([file.filepath]);
|
|
7699
7656
|
},
|
|
7700
|
-
onCancel(reason) {
|
|
7701
|
-
ctx.cancelCurrentRun(reason);
|
|
7702
|
-
},
|
|
7703
|
-
debug(...args) {
|
|
7704
|
-
ctx.logger.console.debug(...args);
|
|
7705
|
-
},
|
|
7706
|
-
getCountOfFailedTests() {
|
|
7707
|
-
return ctx.state.getCountOfFailedTests();
|
|
7708
|
-
},
|
|
7709
7657
|
getUnhandledErrors() {
|
|
7710
7658
|
return ctx.state.getUnhandledErrors();
|
|
7711
7659
|
},
|
|
7712
|
-
// TODO: have a separate websocket conection for private browser API
|
|
7713
|
-
triggerCommand(command, testPath, payload) {
|
|
7714
|
-
var _a2;
|
|
7715
|
-
if (!("ctx" in vitestOrWorkspace) || !vitestOrWorkspace.browserProvider)
|
|
7716
|
-
throw new Error("Commands are only available for browser tests.");
|
|
7717
|
-
const commands = (_a2 = vitestOrWorkspace.config.browser) == null ? void 0 : _a2.commands;
|
|
7718
|
-
if (!commands || !commands[command])
|
|
7719
|
-
throw new Error(`Unknown command "${command}".`);
|
|
7720
|
-
return commands[command]({
|
|
7721
|
-
testPath,
|
|
7722
|
-
project: vitestOrWorkspace,
|
|
7723
|
-
provider: vitestOrWorkspace.browserProvider
|
|
7724
|
-
}, ...payload);
|
|
7725
|
-
},
|
|
7726
|
-
getBrowserFiles() {
|
|
7727
|
-
var _a2;
|
|
7728
|
-
if (!("ctx" in vitestOrWorkspace))
|
|
7729
|
-
throw new Error("`getBrowserTestFiles` is only available in the browser API");
|
|
7730
|
-
return ((_a2 = vitestOrWorkspace.browserState) == null ? void 0 : _a2.files) ?? [];
|
|
7731
|
-
},
|
|
7732
|
-
finishBrowserTests() {
|
|
7733
|
-
var _a2;
|
|
7734
|
-
if (!("ctx" in vitestOrWorkspace))
|
|
7735
|
-
throw new Error("`finishBrowserTests` is only available in the browser API");
|
|
7736
|
-
return (_a2 = vitestOrWorkspace.browserState) == null ? void 0 : _a2.resolve();
|
|
7737
|
-
},
|
|
7738
|
-
getProvidedContext() {
|
|
7739
|
-
return "ctx" in vitestOrWorkspace ? vitestOrWorkspace.getProvidedContext() : {};
|
|
7740
|
-
},
|
|
7741
7660
|
async getTestFiles() {
|
|
7742
7661
|
const spec = await ctx.globTestFiles();
|
|
7743
7662
|
return spec.map(([project, file]) => [{
|
|
7744
|
-
name: project.
|
|
7663
|
+
name: project.config.name,
|
|
7745
7664
|
root: project.config.root
|
|
7746
7665
|
}, file]);
|
|
7747
7666
|
}
|
|
@@ -7749,7 +7668,7 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7749
7668
|
{
|
|
7750
7669
|
post: (msg) => ws.send(msg),
|
|
7751
7670
|
on: (fn) => ws.on("message", fn),
|
|
7752
|
-
eventNames: ["onUserConsoleLog", "onFinished", "onFinishedReportCoverage", "onCollected", "
|
|
7671
|
+
eventNames: ["onUserConsoleLog", "onFinished", "onFinishedReportCoverage", "onCollected", "onTaskUpdate"],
|
|
7753
7672
|
serialize: (data) => stringify(data, stringifyReplace),
|
|
7754
7673
|
deserialize: parse$3,
|
|
7755
7674
|
onTimeoutError(functionName) {
|
|
@@ -7757,7 +7676,6 @@ function setup(vitestOrWorkspace, _server) {
|
|
|
7757
7676
|
}
|
|
7758
7677
|
}
|
|
7759
7678
|
);
|
|
7760
|
-
ctx.onCancel((reason) => rpc.onCancel(reason));
|
|
7761
7679
|
clients.set(ws, rpc);
|
|
7762
7680
|
ws.on("close", () => {
|
|
7763
7681
|
clients.delete(ws);
|
|
@@ -8291,6 +8209,11 @@ function createBrowserPool(ctx) {
|
|
|
8291
8209
|
const runTests = async (project, files) => {
|
|
8292
8210
|
var _a;
|
|
8293
8211
|
ctx.state.clearFiles(project, files);
|
|
8212
|
+
const mocker = project.browserMocker;
|
|
8213
|
+
mocker.mocks.forEach((_, id) => {
|
|
8214
|
+
mocker.invalidateModuleById(id);
|
|
8215
|
+
});
|
|
8216
|
+
mocker.mocks.clear();
|
|
8294
8217
|
const provider = project.browserProvider;
|
|
8295
8218
|
providers.add(provider);
|
|
8296
8219
|
const resolvedUrls = (_a = project.browser) == null ? void 0 : _a.resolvedUrls;
|
|
@@ -8298,7 +8221,14 @@ function createBrowserPool(ctx) {
|
|
|
8298
8221
|
if (!origin)
|
|
8299
8222
|
throw new Error(`Can't find browser origin URL for project "${project.config.name}"`);
|
|
8300
8223
|
const promise = waitForTests(project, files);
|
|
8301
|
-
|
|
8224
|
+
const orchestrators = project.browserRpc.orchestrators;
|
|
8225
|
+
if (orchestrators.size) {
|
|
8226
|
+
orchestrators.forEach((orchestrator) => {
|
|
8227
|
+
orchestrator.createTesters(files);
|
|
8228
|
+
});
|
|
8229
|
+
} else {
|
|
8230
|
+
await provider.openPage(new URL("/", origin).toString());
|
|
8231
|
+
}
|
|
8302
8232
|
await promise;
|
|
8303
8233
|
};
|
|
8304
8234
|
const runWorkspaceTests = async (specs) => {
|
|
@@ -11423,7 +11353,7 @@ function resolveApiServerConfig(options) {
|
|
|
11423
11353
|
return api;
|
|
11424
11354
|
}
|
|
11425
11355
|
function resolveConfig(mode, options, viteConfig, logger) {
|
|
11426
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M;
|
|
11356
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O;
|
|
11427
11357
|
if (options.dom) {
|
|
11428
11358
|
if (((_a = viteConfig.test) == null ? void 0 : _a.environment) != null && viteConfig.test.environment !== "happy-dom") {
|
|
11429
11359
|
logger.console.warn(
|
|
@@ -11471,15 +11401,14 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
11471
11401
|
if (resolved.minWorkers)
|
|
11472
11402
|
resolved.minWorkers = Number(resolved.minWorkers);
|
|
11473
11403
|
resolved.browser ?? (resolved.browser = {});
|
|
11474
|
-
(_c = resolved.browser).fileParallelism ?? (_c.fileParallelism = resolved.fileParallelism ?? false);
|
|
11475
11404
|
resolved.fileParallelism ?? (resolved.fileParallelism = mode !== "benchmark");
|
|
11476
11405
|
if (!resolved.fileParallelism) {
|
|
11477
11406
|
resolved.maxWorkers = 1;
|
|
11478
11407
|
resolved.minWorkers = 1;
|
|
11479
11408
|
}
|
|
11480
11409
|
if (resolved.inspect || resolved.inspectBrk) {
|
|
11481
|
-
const isSingleThread = resolved.pool === "threads" && ((
|
|
11482
|
-
const isSingleFork = resolved.pool === "forks" && ((
|
|
11410
|
+
const isSingleThread = resolved.pool === "threads" && ((_d = (_c = resolved.poolOptions) == null ? void 0 : _c.threads) == null ? void 0 : _d.singleThread);
|
|
11411
|
+
const isSingleFork = resolved.pool === "forks" && ((_f = (_e = resolved.poolOptions) == null ? void 0 : _e.forks) == null ? void 0 : _f.singleFork);
|
|
11483
11412
|
if (resolved.fileParallelism && !isSingleThread && !isSingleFork) {
|
|
11484
11413
|
const inspectOption = `--inspect${resolved.inspectBrk ? "-brk" : ""}`;
|
|
11485
11414
|
throw new Error(`You cannot use ${inspectOption} without "--no-file-parallelism", "poolOptions.threads.singleThread" or "poolOptions.forks.singleFork"`);
|
|
@@ -11492,8 +11421,9 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
11492
11421
|
if (reportsDirectory === resolved.root || reportsDirectory === process.cwd())
|
|
11493
11422
|
throw new Error(`You cannot set "coverage.reportsDirectory" as ${reportsDirectory}. Vitest needs to be able to remove this directory before test run`);
|
|
11494
11423
|
}
|
|
11424
|
+
resolved.expect ?? (resolved.expect = {});
|
|
11495
11425
|
resolved.deps ?? (resolved.deps = {});
|
|
11496
|
-
(
|
|
11426
|
+
(_g = resolved.deps).moduleDirectories ?? (_g.moduleDirectories = []);
|
|
11497
11427
|
resolved.deps.moduleDirectories = resolved.deps.moduleDirectories.map((dir) => {
|
|
11498
11428
|
if (!dir.startsWith("/"))
|
|
11499
11429
|
dir = `/${dir}`;
|
|
@@ -11503,17 +11433,17 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
11503
11433
|
});
|
|
11504
11434
|
if (!resolved.deps.moduleDirectories.includes("/node_modules/"))
|
|
11505
11435
|
resolved.deps.moduleDirectories.push("/node_modules/");
|
|
11506
|
-
(
|
|
11507
|
-
(
|
|
11508
|
-
(
|
|
11509
|
-
(
|
|
11510
|
-
(
|
|
11511
|
-
(
|
|
11512
|
-
(
|
|
11513
|
-
(
|
|
11514
|
-
(
|
|
11436
|
+
(_h = resolved.deps).optimizer ?? (_h.optimizer = {});
|
|
11437
|
+
(_i = resolved.deps.optimizer).ssr ?? (_i.ssr = {});
|
|
11438
|
+
(_j = resolved.deps.optimizer.ssr).enabled ?? (_j.enabled = true);
|
|
11439
|
+
(_k = resolved.deps.optimizer).web ?? (_k.web = {});
|
|
11440
|
+
(_l = resolved.deps.optimizer.web).enabled ?? (_l.enabled = true);
|
|
11441
|
+
(_m = resolved.deps).web ?? (_m.web = {});
|
|
11442
|
+
(_n = resolved.deps.web).transformAssets ?? (_n.transformAssets = true);
|
|
11443
|
+
(_o = resolved.deps.web).transformCss ?? (_o.transformCss = true);
|
|
11444
|
+
(_p = resolved.deps.web).transformGlobPattern ?? (_p.transformGlobPattern = []);
|
|
11515
11445
|
resolved.server ?? (resolved.server = {});
|
|
11516
|
-
(
|
|
11446
|
+
(_q = resolved.server).deps ?? (_q.deps = {});
|
|
11517
11447
|
const deprecatedDepsOptions = ["inline", "external", "fallbackCJS"];
|
|
11518
11448
|
deprecatedDepsOptions.forEach((option) => {
|
|
11519
11449
|
if (resolved.deps[option] === void 0)
|
|
@@ -11538,11 +11468,11 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
11538
11468
|
if ((ssrOptions == null ? void 0 : ssrOptions.noExternal) === true && resolved.server.deps.inline == null) {
|
|
11539
11469
|
resolved.server.deps.inline = true;
|
|
11540
11470
|
} else {
|
|
11541
|
-
(
|
|
11471
|
+
(_r = resolved.server.deps).inline ?? (_r.inline = []);
|
|
11542
11472
|
resolved.server.deps.inline.push(...extraInlineDeps);
|
|
11543
11473
|
}
|
|
11544
11474
|
}
|
|
11545
|
-
(
|
|
11475
|
+
(_s = resolved.server.deps).moduleDirectories ?? (_s.moduleDirectories = []);
|
|
11546
11476
|
resolved.server.deps.moduleDirectories.push(...resolved.deps.moduleDirectories);
|
|
11547
11477
|
if (resolved.runner)
|
|
11548
11478
|
resolved.runner = resolvePath(resolved.runner, resolved.root);
|
|
@@ -11572,11 +11502,11 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
11572
11502
|
resolved.poolOptions = {
|
|
11573
11503
|
...resolved.poolOptions,
|
|
11574
11504
|
threads: {
|
|
11575
|
-
...(
|
|
11505
|
+
...(_t = resolved.poolOptions) == null ? void 0 : _t.threads,
|
|
11576
11506
|
maxThreads: Number.parseInt(process.env.VITEST_MAX_THREADS)
|
|
11577
11507
|
},
|
|
11578
11508
|
vmThreads: {
|
|
11579
|
-
...(
|
|
11509
|
+
...(_u = resolved.poolOptions) == null ? void 0 : _u.vmThreads,
|
|
11580
11510
|
maxThreads: Number.parseInt(process.env.VITEST_MAX_THREADS)
|
|
11581
11511
|
}
|
|
11582
11512
|
};
|
|
@@ -11585,11 +11515,11 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
11585
11515
|
resolved.poolOptions = {
|
|
11586
11516
|
...resolved.poolOptions,
|
|
11587
11517
|
threads: {
|
|
11588
|
-
...(
|
|
11518
|
+
...(_v = resolved.poolOptions) == null ? void 0 : _v.threads,
|
|
11589
11519
|
minThreads: Number.parseInt(process.env.VITEST_MIN_THREADS)
|
|
11590
11520
|
},
|
|
11591
11521
|
vmThreads: {
|
|
11592
|
-
...(
|
|
11522
|
+
...(_w = resolved.poolOptions) == null ? void 0 : _w.vmThreads,
|
|
11593
11523
|
minThreads: Number.parseInt(process.env.VITEST_MIN_THREADS)
|
|
11594
11524
|
}
|
|
11595
11525
|
};
|
|
@@ -11598,11 +11528,11 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
11598
11528
|
resolved.poolOptions = {
|
|
11599
11529
|
...resolved.poolOptions,
|
|
11600
11530
|
forks: {
|
|
11601
|
-
...(
|
|
11531
|
+
...(_x = resolved.poolOptions) == null ? void 0 : _x.forks,
|
|
11602
11532
|
maxForks: Number.parseInt(process.env.VITEST_MAX_FORKS)
|
|
11603
11533
|
},
|
|
11604
11534
|
vmForks: {
|
|
11605
|
-
...(
|
|
11535
|
+
...(_y = resolved.poolOptions) == null ? void 0 : _y.vmForks,
|
|
11606
11536
|
maxForks: Number.parseInt(process.env.VITEST_MAX_FORKS)
|
|
11607
11537
|
}
|
|
11608
11538
|
};
|
|
@@ -11611,11 +11541,11 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
11611
11541
|
resolved.poolOptions = {
|
|
11612
11542
|
...resolved.poolOptions,
|
|
11613
11543
|
forks: {
|
|
11614
|
-
...(
|
|
11544
|
+
...(_z = resolved.poolOptions) == null ? void 0 : _z.forks,
|
|
11615
11545
|
minForks: Number.parseInt(process.env.VITEST_MIN_FORKS)
|
|
11616
11546
|
},
|
|
11617
11547
|
vmForks: {
|
|
11618
|
-
...(
|
|
11548
|
+
...(_A = resolved.poolOptions) == null ? void 0 : _A.vmForks,
|
|
11619
11549
|
minForks: Number.parseInt(process.env.VITEST_MIN_FORKS)
|
|
11620
11550
|
}
|
|
11621
11551
|
};
|
|
@@ -11711,8 +11641,8 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
11711
11641
|
resolved.passWithNoTests ?? (resolved.passWithNoTests = true);
|
|
11712
11642
|
resolved.css ?? (resolved.css = {});
|
|
11713
11643
|
if (typeof resolved.css === "object") {
|
|
11714
|
-
(
|
|
11715
|
-
(
|
|
11644
|
+
(_B = resolved.css).modules ?? (_B.modules = {});
|
|
11645
|
+
(_C = resolved.css.modules).classNameStrategy ?? (_C.classNameStrategy = "stable");
|
|
11716
11646
|
}
|
|
11717
11647
|
if (resolved.cache !== false) {
|
|
11718
11648
|
let cacheDir = VitestCache.resolveCacheDir("", resolve(viteConfig.cacheDir, "vitest"), resolved.name);
|
|
@@ -11729,29 +11659,34 @@ function resolveConfig(mode, options, viteConfig, logger) {
|
|
|
11729
11659
|
resolved.sequence ?? (resolved.sequence = {});
|
|
11730
11660
|
if (resolved.sequence.shuffle && typeof resolved.sequence.shuffle === "object") {
|
|
11731
11661
|
const { files, tests } = resolved.sequence.shuffle;
|
|
11732
|
-
(
|
|
11662
|
+
(_D = resolved.sequence).sequencer ?? (_D.sequencer = files ? RandomSequencer : BaseSequencer);
|
|
11733
11663
|
resolved.sequence.shuffle = tests;
|
|
11734
11664
|
}
|
|
11735
|
-
if (!((
|
|
11665
|
+
if (!((_E = resolved.sequence) == null ? void 0 : _E.sequencer)) {
|
|
11736
11666
|
resolved.sequence.sequencer = resolved.sequence.shuffle ? RandomSequencer : BaseSequencer;
|
|
11737
11667
|
}
|
|
11738
|
-
(
|
|
11668
|
+
(_F = resolved.sequence).hooks ?? (_F.hooks = "stack");
|
|
11739
11669
|
if (resolved.sequence.sequencer === RandomSequencer)
|
|
11740
|
-
(
|
|
11670
|
+
(_G = resolved.sequence).seed ?? (_G.seed = Date.now());
|
|
11741
11671
|
resolved.typecheck = {
|
|
11742
11672
|
...configDefaults.typecheck,
|
|
11743
11673
|
...resolved.typecheck
|
|
11744
11674
|
};
|
|
11745
|
-
resolved.environmentMatchGlobs = (resolved.environmentMatchGlobs || []).map(
|
|
11675
|
+
resolved.environmentMatchGlobs = (resolved.environmentMatchGlobs || []).map(
|
|
11676
|
+
(i) => [resolve(resolved.root, i[0]), i[1]]
|
|
11677
|
+
);
|
|
11746
11678
|
resolved.typecheck ?? (resolved.typecheck = {});
|
|
11747
|
-
(
|
|
11679
|
+
(_H = resolved.typecheck).enabled ?? (_H.enabled = false);
|
|
11748
11680
|
if (resolved.typecheck.enabled)
|
|
11749
11681
|
logger.console.warn(c.yellow("Testing types with tsc and vue-tsc is an experimental feature.\nBreaking changes might not follow SemVer, please pin Vitest's version when using it."));
|
|
11750
11682
|
resolved.browser ?? (resolved.browser = {});
|
|
11751
|
-
(
|
|
11752
|
-
(
|
|
11753
|
-
(
|
|
11754
|
-
(
|
|
11683
|
+
(_I = resolved.browser).enabled ?? (_I.enabled = false);
|
|
11684
|
+
(_J = resolved.browser).headless ?? (_J.headless = isCI);
|
|
11685
|
+
(_K = resolved.browser).isolate ?? (_K.isolate = true);
|
|
11686
|
+
(_L = resolved.browser).ui ?? (_L.ui = !isCI);
|
|
11687
|
+
(_M = resolved.browser).viewport ?? (_M.viewport = {});
|
|
11688
|
+
(_N = resolved.browser.viewport).width ?? (_N.width = 414);
|
|
11689
|
+
(_O = resolved.browser.viewport).height ?? (_O.height = 896);
|
|
11755
11690
|
if (resolved.browser.enabled && provider$1 === "stackblitz")
|
|
11756
11691
|
resolved.browser.provider = "none";
|
|
11757
11692
|
resolved.browser.api = resolveApiServerConfig(resolved.browser) || {
|
|
@@ -12061,6 +11996,8 @@ function MocksPlugin() {
|
|
|
12061
11996
|
name: "vitest:mocks",
|
|
12062
11997
|
enforce: "post",
|
|
12063
11998
|
transform(code, id) {
|
|
11999
|
+
if (id.includes(distDir))
|
|
12000
|
+
return;
|
|
12064
12001
|
return hoistMocks(code, id, this.parse);
|
|
12065
12002
|
}
|
|
12066
12003
|
};
|
|
@@ -12163,6 +12100,157 @@ function resolveFsAllow(projectRoot, rootConfigFile) {
|
|
|
12163
12100
|
return [dirname(rootConfigFile), searchForWorkspaceRoot(projectRoot), rootDir];
|
|
12164
12101
|
}
|
|
12165
12102
|
|
|
12103
|
+
function setupBrowserRpc(project, server) {
|
|
12104
|
+
var _a;
|
|
12105
|
+
const ctx = project.ctx;
|
|
12106
|
+
const wss = new WebSocketServer$1({ noServer: true });
|
|
12107
|
+
(_a = server.httpServer) == null ? void 0 : _a.on("upgrade", (request, socket, head) => {
|
|
12108
|
+
if (!request.url)
|
|
12109
|
+
return;
|
|
12110
|
+
const { pathname, searchParams } = new URL(request.url, "http://localhost");
|
|
12111
|
+
if (pathname !== BROWSER_API_PATH)
|
|
12112
|
+
return;
|
|
12113
|
+
const type = searchParams.get("type") ?? "tester";
|
|
12114
|
+
const sessionId = searchParams.get("sessionId") ?? "0";
|
|
12115
|
+
wss.handleUpgrade(request, socket, head, (ws) => {
|
|
12116
|
+
wss.emit("connection", ws, request);
|
|
12117
|
+
const rpc = setupClient(sessionId, ws);
|
|
12118
|
+
const rpcs = project.browserRpc;
|
|
12119
|
+
const clients = type === "tester" ? rpcs.testers : rpcs.orchestrators;
|
|
12120
|
+
clients.set(sessionId, rpc);
|
|
12121
|
+
ws.on("close", () => {
|
|
12122
|
+
clients.delete(sessionId);
|
|
12123
|
+
});
|
|
12124
|
+
});
|
|
12125
|
+
});
|
|
12126
|
+
function checkFileAccess(path) {
|
|
12127
|
+
if (!isFileServingAllowed(path, server))
|
|
12128
|
+
throw new Error(`Access denied to "${path}". See Vite config documentation for "server.fs": https://vitejs.dev/config/server-options.html#server-fs-strict.`);
|
|
12129
|
+
}
|
|
12130
|
+
function setupClient(sessionId, ws) {
|
|
12131
|
+
const rpc = createBirpc(
|
|
12132
|
+
{
|
|
12133
|
+
async onUnhandledError(error, type) {
|
|
12134
|
+
ctx.state.catchError(error, type);
|
|
12135
|
+
},
|
|
12136
|
+
async onCollected(files) {
|
|
12137
|
+
ctx.state.collectFiles(files);
|
|
12138
|
+
await ctx.report("onCollected", files);
|
|
12139
|
+
},
|
|
12140
|
+
async onTaskUpdate(packs) {
|
|
12141
|
+
ctx.state.updateTasks(packs);
|
|
12142
|
+
await ctx.report("onTaskUpdate", packs);
|
|
12143
|
+
},
|
|
12144
|
+
onAfterSuiteRun(meta) {
|
|
12145
|
+
var _a2;
|
|
12146
|
+
(_a2 = ctx.coverageProvider) == null ? void 0 : _a2.onAfterSuiteRun(meta);
|
|
12147
|
+
},
|
|
12148
|
+
sendLog(log) {
|
|
12149
|
+
return ctx.report("onUserConsoleLog", log);
|
|
12150
|
+
},
|
|
12151
|
+
resolveSnapshotPath(testPath) {
|
|
12152
|
+
return ctx.snapshot.resolvePath(testPath);
|
|
12153
|
+
},
|
|
12154
|
+
resolveSnapshotRawPath(testPath, rawPath) {
|
|
12155
|
+
return ctx.snapshot.resolveRawPath(testPath, rawPath);
|
|
12156
|
+
},
|
|
12157
|
+
snapshotSaved(snapshot) {
|
|
12158
|
+
ctx.snapshot.add(snapshot);
|
|
12159
|
+
},
|
|
12160
|
+
async readSnapshotFile(snapshotPath) {
|
|
12161
|
+
checkFileAccess(snapshotPath);
|
|
12162
|
+
if (!existsSync(snapshotPath))
|
|
12163
|
+
return null;
|
|
12164
|
+
return promises$1.readFile(snapshotPath, "utf-8");
|
|
12165
|
+
},
|
|
12166
|
+
async saveSnapshotFile(id, content) {
|
|
12167
|
+
checkFileAccess(id);
|
|
12168
|
+
await promises$1.mkdir(dirname(id), { recursive: true });
|
|
12169
|
+
return promises$1.writeFile(id, content, "utf-8");
|
|
12170
|
+
},
|
|
12171
|
+
async removeSnapshotFile(id) {
|
|
12172
|
+
checkFileAccess(id);
|
|
12173
|
+
if (!existsSync(id))
|
|
12174
|
+
throw new Error(`Snapshot file "${id}" does not exist.`);
|
|
12175
|
+
return promises$1.unlink(id);
|
|
12176
|
+
},
|
|
12177
|
+
async getBrowserFileSourceMap(id) {
|
|
12178
|
+
var _a2, _b;
|
|
12179
|
+
const mod = (_a2 = project.browser) == null ? void 0 : _a2.moduleGraph.getModuleById(id);
|
|
12180
|
+
return (_b = mod == null ? void 0 : mod.transformResult) == null ? void 0 : _b.map;
|
|
12181
|
+
},
|
|
12182
|
+
onCancel(reason) {
|
|
12183
|
+
ctx.cancelCurrentRun(reason);
|
|
12184
|
+
},
|
|
12185
|
+
async resolveId(id, importer) {
|
|
12186
|
+
const result = await project.server.pluginContainer.resolveId(id, importer, {
|
|
12187
|
+
ssr: false
|
|
12188
|
+
});
|
|
12189
|
+
return result;
|
|
12190
|
+
},
|
|
12191
|
+
debug(...args) {
|
|
12192
|
+
ctx.logger.console.debug(...args);
|
|
12193
|
+
},
|
|
12194
|
+
getCountOfFailedTests() {
|
|
12195
|
+
return ctx.state.getCountOfFailedTests();
|
|
12196
|
+
},
|
|
12197
|
+
triggerCommand(command, testPath, payload) {
|
|
12198
|
+
var _a2;
|
|
12199
|
+
if (!project.browserProvider)
|
|
12200
|
+
throw new Error("Commands are only available for browser tests.");
|
|
12201
|
+
const commands = (_a2 = project.config.browser) == null ? void 0 : _a2.commands;
|
|
12202
|
+
if (!commands || !commands[command])
|
|
12203
|
+
throw new Error(`Unknown command "${command}".`);
|
|
12204
|
+
return commands[command]({
|
|
12205
|
+
testPath,
|
|
12206
|
+
project,
|
|
12207
|
+
provider: project.browserProvider
|
|
12208
|
+
}, ...payload);
|
|
12209
|
+
},
|
|
12210
|
+
getBrowserFiles() {
|
|
12211
|
+
var _a2;
|
|
12212
|
+
return ((_a2 = project.browserState) == null ? void 0 : _a2.files) ?? [];
|
|
12213
|
+
},
|
|
12214
|
+
finishBrowserTests() {
|
|
12215
|
+
var _a2;
|
|
12216
|
+
return (_a2 = project.browserState) == null ? void 0 : _a2.resolve();
|
|
12217
|
+
},
|
|
12218
|
+
getProvidedContext() {
|
|
12219
|
+
return "ctx" in project ? project.getProvidedContext() : {};
|
|
12220
|
+
},
|
|
12221
|
+
async queueMock(id, importer, hasFactory) {
|
|
12222
|
+
return project.browserMocker.mock(sessionId, id, importer, hasFactory);
|
|
12223
|
+
},
|
|
12224
|
+
async queueUnmock(id, importer) {
|
|
12225
|
+
return project.browserMocker.unmock(id, importer);
|
|
12226
|
+
},
|
|
12227
|
+
resolveMock(rawId, importer) {
|
|
12228
|
+
return project.browserMocker.resolveMock(rawId, importer, false);
|
|
12229
|
+
},
|
|
12230
|
+
invalidateMocks() {
|
|
12231
|
+
const mocker = project.browserMocker;
|
|
12232
|
+
mocker.mocks.forEach((_, id) => {
|
|
12233
|
+
mocker.invalidateModuleById(id);
|
|
12234
|
+
});
|
|
12235
|
+
mocker.mocks.clear();
|
|
12236
|
+
}
|
|
12237
|
+
},
|
|
12238
|
+
{
|
|
12239
|
+
post: (msg) => ws.send(msg),
|
|
12240
|
+
on: (fn) => ws.on("message", fn),
|
|
12241
|
+
eventNames: ["onCancel"],
|
|
12242
|
+
serialize: (data) => stringify(data, stringifyReplace),
|
|
12243
|
+
deserialize: parse$3,
|
|
12244
|
+
onTimeoutError(functionName) {
|
|
12245
|
+
throw new Error(`[vitest-api]: Timeout calling "${functionName}"`);
|
|
12246
|
+
}
|
|
12247
|
+
}
|
|
12248
|
+
);
|
|
12249
|
+
ctx.onCancel((reason) => rpc.onCancel(reason));
|
|
12250
|
+
return rpc;
|
|
12251
|
+
}
|
|
12252
|
+
}
|
|
12253
|
+
|
|
12166
12254
|
async function createBrowserServer(project, configFile) {
|
|
12167
12255
|
var _a;
|
|
12168
12256
|
const root = project.config.root;
|
|
@@ -12177,12 +12265,11 @@ async function createBrowserServer(project, configFile) {
|
|
|
12177
12265
|
// watch is handled by Vitest
|
|
12178
12266
|
server: {
|
|
12179
12267
|
hmr: false,
|
|
12180
|
-
watch:
|
|
12181
|
-
ignored: ["**/**"]
|
|
12182
|
-
}
|
|
12268
|
+
watch: null
|
|
12183
12269
|
},
|
|
12184
12270
|
plugins: [
|
|
12185
12271
|
...((_a = project.options) == null ? void 0 : _a.plugins) || [],
|
|
12272
|
+
MocksPlugin(),
|
|
12186
12273
|
(await import('@vitest/browser')).default(project, "/"),
|
|
12187
12274
|
CoverageTransform(project.ctx),
|
|
12188
12275
|
{
|
|
@@ -12211,16 +12298,18 @@ async function createBrowserServer(project, configFile) {
|
|
|
12211
12298
|
alias: (_c = config.test) == null ? void 0 : _c.alias
|
|
12212
12299
|
},
|
|
12213
12300
|
server: {
|
|
12214
|
-
watch: null
|
|
12301
|
+
watch: null,
|
|
12302
|
+
preTransformRequests: false
|
|
12215
12303
|
}
|
|
12216
12304
|
};
|
|
12217
12305
|
}
|
|
12218
|
-
}
|
|
12219
|
-
MocksPlugin()
|
|
12306
|
+
}
|
|
12220
12307
|
]
|
|
12221
12308
|
});
|
|
12222
12309
|
await server.listen();
|
|
12223
|
-
(
|
|
12310
|
+
setupBrowserRpc(project, server);
|
|
12311
|
+
if (project.config.browser.ui)
|
|
12312
|
+
setup(project.ctx, server);
|
|
12224
12313
|
return server;
|
|
12225
12314
|
}
|
|
12226
12315
|
|
|
@@ -12243,6 +12332,91 @@ async function getBrowserProvider(options, project) {
|
|
|
12243
12332
|
return customProviderModule.default;
|
|
12244
12333
|
}
|
|
12245
12334
|
|
|
12335
|
+
var __defProp = Object.defineProperty;
|
|
12336
|
+
var __typeError = (msg) => {
|
|
12337
|
+
throw TypeError(msg);
|
|
12338
|
+
};
|
|
12339
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12340
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, key + "" , value);
|
|
12341
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
12342
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
12343
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
12344
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
12345
|
+
var _project;
|
|
12346
|
+
class VitestBrowserServerMocker {
|
|
12347
|
+
constructor(project) {
|
|
12348
|
+
// string means it will read from __mocks__ folder
|
|
12349
|
+
// undefined means there is a factory mock that will be called on the server
|
|
12350
|
+
// null means it should be auto mocked
|
|
12351
|
+
__publicField(this, "mocks", /* @__PURE__ */ new Map());
|
|
12352
|
+
// private because the typecheck fails on build if it's exposed
|
|
12353
|
+
// due to a self reference
|
|
12354
|
+
__privateAdd(this, _project);
|
|
12355
|
+
__privateSet(this, _project, project);
|
|
12356
|
+
}
|
|
12357
|
+
async mock(sessionId, rawId, importer, hasFactory) {
|
|
12358
|
+
const { type, mockPath, resolvedId } = await this.resolveMock(rawId, importer, hasFactory);
|
|
12359
|
+
this.invalidateModuleById(resolvedId);
|
|
12360
|
+
if (type === "factory") {
|
|
12361
|
+
this.mocks.set(resolvedId, { sessionId, mock: void 0 });
|
|
12362
|
+
return resolvedId;
|
|
12363
|
+
}
|
|
12364
|
+
this.mocks.set(resolvedId, { sessionId, mock: mockPath });
|
|
12365
|
+
return resolvedId;
|
|
12366
|
+
}
|
|
12367
|
+
async unmock(rawId, importer) {
|
|
12368
|
+
const { id } = await this.resolveId(rawId, importer);
|
|
12369
|
+
this.invalidateModuleById(id);
|
|
12370
|
+
this.mocks.delete(id);
|
|
12371
|
+
return id;
|
|
12372
|
+
}
|
|
12373
|
+
async resolveMock(rawId, importer, hasFactory) {
|
|
12374
|
+
const { id, fsPath, external } = await this.resolveId(rawId, importer);
|
|
12375
|
+
if (hasFactory)
|
|
12376
|
+
return { type: "factory", resolvedId: id };
|
|
12377
|
+
const mockPath = this.resolveMockPath(fsPath, external);
|
|
12378
|
+
return {
|
|
12379
|
+
type: mockPath === null ? "automock" : "redirect",
|
|
12380
|
+
mockPath,
|
|
12381
|
+
resolvedId: id
|
|
12382
|
+
};
|
|
12383
|
+
}
|
|
12384
|
+
invalidateModuleById(id) {
|
|
12385
|
+
const moduleGraph = __privateGet(this, _project).browser.moduleGraph;
|
|
12386
|
+
const module = moduleGraph.getModuleById(id);
|
|
12387
|
+
if (module)
|
|
12388
|
+
moduleGraph.invalidateModule(module, /* @__PURE__ */ new Set(), Date.now(), true);
|
|
12389
|
+
}
|
|
12390
|
+
async resolveId(rawId, importer) {
|
|
12391
|
+
const resolved = await __privateGet(this, _project).browser.pluginContainer.resolveId(rawId, importer, {
|
|
12392
|
+
ssr: false
|
|
12393
|
+
});
|
|
12394
|
+
return __privateGet(this, _project).vitenode.resolveModule(rawId, resolved);
|
|
12395
|
+
}
|
|
12396
|
+
resolveMockPath(mockPath, external) {
|
|
12397
|
+
const path = external || mockPath;
|
|
12398
|
+
if (external || isNodeBuiltin(mockPath) || !existsSync(mockPath)) {
|
|
12399
|
+
const mockDirname = dirname(path);
|
|
12400
|
+
const mockFolder = join(__privateGet(this, _project).config.root, "__mocks__", mockDirname);
|
|
12401
|
+
if (!existsSync(mockFolder))
|
|
12402
|
+
return null;
|
|
12403
|
+
const files = readdirSync(mockFolder);
|
|
12404
|
+
const baseOriginal = basename(path);
|
|
12405
|
+
for (const file of files) {
|
|
12406
|
+
const baseFile = basename(file, extname$1(file));
|
|
12407
|
+
if (baseFile === baseOriginal)
|
|
12408
|
+
return resolve(mockFolder, file);
|
|
12409
|
+
}
|
|
12410
|
+
return null;
|
|
12411
|
+
}
|
|
12412
|
+
const dir = dirname(path);
|
|
12413
|
+
const baseId = basename(path);
|
|
12414
|
+
const fullPath = resolve(dir, "__mocks__", baseId);
|
|
12415
|
+
return existsSync(fullPath) ? fullPath : null;
|
|
12416
|
+
}
|
|
12417
|
+
}
|
|
12418
|
+
_project = new WeakMap();
|
|
12419
|
+
|
|
12246
12420
|
function generateCssFilenameHash(filepath) {
|
|
12247
12421
|
return createHash$2("md5").update(filepath).digest("hex").slice(0, 6);
|
|
12248
12422
|
}
|
|
@@ -12963,17 +13137,12 @@ function WorkspaceVitestPlugin(project, options) {
|
|
|
12963
13137
|
hijackVitePluginInject(viteConfig);
|
|
12964
13138
|
},
|
|
12965
13139
|
async configureServer(server) {
|
|
12966
|
-
|
|
12967
|
-
|
|
12968
|
-
|
|
12969
|
-
|
|
12970
|
-
|
|
12971
|
-
|
|
12972
|
-
await project.setServer(options2, server);
|
|
12973
|
-
} catch (err) {
|
|
12974
|
-
project.ctx.logger.printError(err, { fullStack: true });
|
|
12975
|
-
process.exit(1);
|
|
12976
|
-
}
|
|
13140
|
+
const options2 = deepMerge(
|
|
13141
|
+
{},
|
|
13142
|
+
configDefaults,
|
|
13143
|
+
server.config.test || {}
|
|
13144
|
+
);
|
|
13145
|
+
await project.setServer(options2, server);
|
|
12977
13146
|
await server.watcher.close();
|
|
12978
13147
|
}
|
|
12979
13148
|
},
|
|
@@ -13062,7 +13231,14 @@ class WorkspaceProject {
|
|
|
13062
13231
|
browser;
|
|
13063
13232
|
typechecker;
|
|
13064
13233
|
closingPromise;
|
|
13234
|
+
// TODO: abstract browser related things and move to @vitest/browser
|
|
13065
13235
|
browserProvider;
|
|
13236
|
+
browserMocker = new VitestBrowserServerMocker(this);
|
|
13237
|
+
// TODO: I mean, we really need to abstract it
|
|
13238
|
+
browserRpc = {
|
|
13239
|
+
orchestrators: /* @__PURE__ */ new Map(),
|
|
13240
|
+
testers: /* @__PURE__ */ new Map()
|
|
13241
|
+
};
|
|
13066
13242
|
browserState;
|
|
13067
13243
|
testFilesList = null;
|
|
13068
13244
|
id = nanoid();
|
|
@@ -13098,35 +13274,21 @@ class WorkspaceProject {
|
|
|
13098
13274
|
if (this._globalSetups)
|
|
13099
13275
|
return;
|
|
13100
13276
|
this._globalSetups = await loadGlobalSetupFiles(this.runner, this.config.globalSetup);
|
|
13101
|
-
|
|
13102
|
-
|
|
13103
|
-
|
|
13104
|
-
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
globalSetupFile.teardown = teardown;
|
|
13109
|
-
}
|
|
13110
|
-
} catch (e) {
|
|
13111
|
-
this.logger.error(`
|
|
13112
|
-
${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
|
|
13113
|
-
this.logger.printError(e);
|
|
13114
|
-
process.exit(1);
|
|
13277
|
+
for (const globalSetupFile of this._globalSetups) {
|
|
13278
|
+
const teardown = await ((_a = globalSetupFile.setup) == null ? void 0 : _a.call(globalSetupFile, { provide: this.provide, config: this.config }));
|
|
13279
|
+
if (teardown == null || !!globalSetupFile.teardown)
|
|
13280
|
+
continue;
|
|
13281
|
+
if (typeof teardown !== "function")
|
|
13282
|
+
throw new Error(`invalid return value in globalSetup file ${globalSetupFile.file}. Must return a function`);
|
|
13283
|
+
globalSetupFile.teardown = teardown;
|
|
13115
13284
|
}
|
|
13116
13285
|
}
|
|
13117
13286
|
async teardownGlobalSetup() {
|
|
13118
13287
|
var _a;
|
|
13119
13288
|
if (!this._globalSetups)
|
|
13120
13289
|
return;
|
|
13121
|
-
for (const globalSetupFile of [...this._globalSetups].reverse())
|
|
13122
|
-
|
|
13123
|
-
await ((_a = globalSetupFile.teardown) == null ? void 0 : _a.call(globalSetupFile));
|
|
13124
|
-
} catch (error) {
|
|
13125
|
-
this.logger.error(`error during global teardown of ${globalSetupFile.file}`, error);
|
|
13126
|
-
this.logger.printError(error);
|
|
13127
|
-
process.exitCode = 1;
|
|
13128
|
-
}
|
|
13129
|
-
}
|
|
13290
|
+
for (const globalSetupFile of [...this._globalSetups].reverse())
|
|
13291
|
+
await ((_a = globalSetupFile.teardown) == null ? void 0 : _a.call(globalSetupFile));
|
|
13130
13292
|
}
|
|
13131
13293
|
get logger() {
|
|
13132
13294
|
return this.ctx.logger;
|
|
@@ -13332,8 +13494,11 @@ ${c.red(divider(c.bold(c.inverse(" Error during global setup "))))}`);
|
|
|
13332
13494
|
},
|
|
13333
13495
|
browser: {
|
|
13334
13496
|
...this.ctx.config.browser,
|
|
13497
|
+
indexScripts: [],
|
|
13498
|
+
testerScripts: [],
|
|
13335
13499
|
commands: {}
|
|
13336
|
-
}
|
|
13500
|
+
},
|
|
13501
|
+
printConsoleTrace: this.config.printConsoleTrace ?? this.ctx.config.printConsoleTrace
|
|
13337
13502
|
}, this.ctx.configOverride || {});
|
|
13338
13503
|
}
|
|
13339
13504
|
close() {
|
|
@@ -13531,10 +13696,10 @@ class Vitest {
|
|
|
13531
13696
|
getProjectByTaskId(taskId) {
|
|
13532
13697
|
var _a;
|
|
13533
13698
|
const task = this.state.idMap.get(taskId);
|
|
13534
|
-
const projectName = task.projectName || ((_a = task == null ? void 0 : task.file) == null ? void 0 : _a.projectName);
|
|
13699
|
+
const projectName = task.projectName || ((_a = task == null ? void 0 : task.file) == null ? void 0 : _a.projectName) || "";
|
|
13535
13700
|
return this.projects.find((p) => p.getName() === projectName) || this.getCoreWorkspaceProject() || this.projects[0];
|
|
13536
13701
|
}
|
|
13537
|
-
getProjectByName(name) {
|
|
13702
|
+
getProjectByName(name = "") {
|
|
13538
13703
|
return this.projects.find((p) => p.getName() === name) || this.getCoreWorkspaceProject() || this.projects[0];
|
|
13539
13704
|
}
|
|
13540
13705
|
async getWorkspaceConfigPath() {
|
|
@@ -13624,7 +13789,8 @@ class Vitest {
|
|
|
13624
13789
|
"testNamePattern",
|
|
13625
13790
|
"passWithNoTests",
|
|
13626
13791
|
"bail",
|
|
13627
|
-
"isolate"
|
|
13792
|
+
"isolate",
|
|
13793
|
+
"printConsoleTrace"
|
|
13628
13794
|
];
|
|
13629
13795
|
const cliOverrides = overridesOptions.reduce((acc, name) => {
|
|
13630
13796
|
if (name in cliOptions)
|
|
@@ -13684,9 +13850,10 @@ class Vitest {
|
|
|
13684
13850
|
return Promise.all(this.projects.map((w) => w.initBrowserProvider()));
|
|
13685
13851
|
}
|
|
13686
13852
|
async mergeReports() {
|
|
13853
|
+
var _a, _b;
|
|
13687
13854
|
if (this.reporters.some((r) => r instanceof BlobReporter))
|
|
13688
13855
|
throw new Error("Cannot merge reports when `--reporter=blob` is used. Remove blob reporter from the config first.");
|
|
13689
|
-
const { files, errors } = await readBlobs(this.config.mergeReports, this.projects);
|
|
13856
|
+
const { files, errors, coverages } = await readBlobs(this.config.mergeReports, this.projects);
|
|
13690
13857
|
await this.report("onInit", this);
|
|
13691
13858
|
await this.report("onPathsCollected", files.flatMap((f) => f.filepath));
|
|
13692
13859
|
const workspaceSpecs = /* @__PURE__ */ new Map();
|
|
@@ -13700,8 +13867,8 @@ class Vitest {
|
|
|
13700
13867
|
const filepaths = files2.map((f) => f.filepath);
|
|
13701
13868
|
this.state.clearFiles(project, filepaths);
|
|
13702
13869
|
files2.forEach((file) => {
|
|
13703
|
-
var
|
|
13704
|
-
(
|
|
13870
|
+
var _a2;
|
|
13871
|
+
(_a2 = file.logs) == null ? void 0 : _a2.forEach((log) => this.state.updateUserLog(log));
|
|
13705
13872
|
});
|
|
13706
13873
|
this.state.collectFiles(files2);
|
|
13707
13874
|
}
|
|
@@ -13723,9 +13890,11 @@ class Vitest {
|
|
|
13723
13890
|
if (hasFailed(files))
|
|
13724
13891
|
process.exitCode = 1;
|
|
13725
13892
|
await this.report("onFinished", files, errors);
|
|
13893
|
+
await this.initCoverageProvider();
|
|
13894
|
+
await ((_b = (_a = this.coverageProvider) == null ? void 0 : _a.mergeReports) == null ? void 0 : _b.call(_a, coverages));
|
|
13726
13895
|
}
|
|
13727
13896
|
async start(filters) {
|
|
13728
|
-
var _a, _b;
|
|
13897
|
+
var _a, _b, _c, _d;
|
|
13729
13898
|
this._onClose = [];
|
|
13730
13899
|
try {
|
|
13731
13900
|
await this.initCoverageProvider();
|
|
@@ -13738,9 +13907,10 @@ class Vitest {
|
|
|
13738
13907
|
await this.globTestFiles(filters)
|
|
13739
13908
|
);
|
|
13740
13909
|
if (!files.length) {
|
|
13741
|
-
await this.
|
|
13910
|
+
const coverage = await ((_c = (_b = this.coverageProvider) == null ? void 0 : _b.generateCoverage) == null ? void 0 : _c.call(_b, { allTestsRun: true }));
|
|
13911
|
+
await this.reportCoverage(coverage, true);
|
|
13742
13912
|
this.logger.printNoTestFound(filters);
|
|
13743
|
-
if (!this.config.watch || !(this.config.changed || ((
|
|
13913
|
+
if (!this.config.watch || !(this.config.changed || ((_d = this.config.related) == null ? void 0 : _d.length))) {
|
|
13744
13914
|
const exitCode = this.config.passWithNoTests ? 0 : 1;
|
|
13745
13915
|
process.exit(exitCode);
|
|
13746
13916
|
}
|
|
@@ -13848,7 +14018,7 @@ class Vitest {
|
|
|
13848
14018
|
this.state.collectPaths(filepaths);
|
|
13849
14019
|
await this.report("onPathsCollected", filepaths);
|
|
13850
14020
|
await this.report("onSpecsCollected", specs.map(
|
|
13851
|
-
([project, file]) => [{ name: project.
|
|
14021
|
+
([project, file]) => [{ name: project.config.name, root: project.config.root }, file]
|
|
13852
14022
|
));
|
|
13853
14023
|
await this.runningPromise;
|
|
13854
14024
|
this._onCancelListeners = [];
|
|
@@ -13875,9 +14045,11 @@ class Vitest {
|
|
|
13875
14045
|
this.cache.results.updateResults(files);
|
|
13876
14046
|
await this.cache.results.writeToCache();
|
|
13877
14047
|
})().finally(async () => {
|
|
14048
|
+
var _a;
|
|
13878
14049
|
const files = Array.from(new Set(specs.map(([, p]) => p)));
|
|
13879
|
-
await
|
|
13880
|
-
await this.
|
|
14050
|
+
const coverage = await ((_a = this.coverageProvider) == null ? void 0 : _a.generateCoverage({ allTestsRun }));
|
|
14051
|
+
await this.report("onFinished", this.state.getFiles(files), this.state.getUnhandledErrors(), coverage);
|
|
14052
|
+
await this.reportCoverage(coverage, allTestsRun);
|
|
13881
14053
|
this.runningPromise = void 0;
|
|
13882
14054
|
this.isFirstRun = false;
|
|
13883
14055
|
this.config.changed = false;
|
|
@@ -14109,11 +14281,11 @@ class Vitest {
|
|
|
14109
14281
|
}
|
|
14110
14282
|
return Array.from(new Set(files));
|
|
14111
14283
|
}
|
|
14112
|
-
async reportCoverage(allTestsRun) {
|
|
14284
|
+
async reportCoverage(coverage, allTestsRun) {
|
|
14113
14285
|
if (!this.config.coverage.reportOnFailure && this.state.getCountOfFailedTests() > 0)
|
|
14114
14286
|
return;
|
|
14115
14287
|
if (this.coverageProvider) {
|
|
14116
|
-
await this.coverageProvider.reportCoverage({ allTestsRun });
|
|
14288
|
+
await this.coverageProvider.reportCoverage(coverage, { allTestsRun });
|
|
14117
14289
|
for (const reporter of this.reporters) {
|
|
14118
14290
|
if (reporter instanceof WebSocketReporter)
|
|
14119
14291
|
reporter.onFinishedReportCoverage();
|
|
@@ -21002,7 +21174,7 @@ async function startVitest(mode, cliFilters = [], options = {}, viteOverrides, v
|
|
|
21002
21174
|
await ctx.start(cliFilters);
|
|
21003
21175
|
} catch (e) {
|
|
21004
21176
|
process.exitCode = 1;
|
|
21005
|
-
|
|
21177
|
+
ctx.logger.printError(e, { fullStack: true, type: "Unhandled Error" });
|
|
21006
21178
|
ctx.logger.error("\n\n");
|
|
21007
21179
|
return ctx;
|
|
21008
21180
|
}
|