vitest 4.0.17 → 4.1.0-beta.1
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 +1 -1
- package/dist/browser.js +1 -1
- package/dist/chunks/{base.XJJQZiKB.js → base.CBRNZa3k.js} +8 -7
- package/dist/chunks/{browser.d.ChKACdzH.d.ts → browser.d.8hOapKZr.d.ts} +3 -1
- package/dist/chunks/{cac.jRCLJDDc.js → cac.B1v3xxoC.js} +26 -8
- package/dist/chunks/{cli-api.Cx2DW4Bc.js → cli-api.B4CqEpI6.js} +102 -54
- package/dist/chunks/{config.d.Cy95HiCx.d.ts → config.d.idH22YSr.d.ts} +8 -11
- package/dist/chunks/{console.Cf-YriPC.js → console.uGgdMhyZ.js} +2 -1
- package/dist/chunks/{coverage.AVPTjMgw.js → coverage.BMlOMIWl.js} +14 -4
- package/dist/chunks/{creator.DAmOKTvJ.js → creator.C7WwjkuR.js} +32 -1
- package/dist/chunks/{globals.DOayXfHP.js → globals.DjuGMoMc.js} +10 -9
- package/dist/chunks/{index.Z5E_ObnR.js → index.BEFi2-_3.js} +3 -1
- package/dist/chunks/{index.6Qv1eEA6.js → index.BiOAd_ki.js} +16 -4
- package/dist/chunks/{index.M8mOzt4Y.js → index.Dm4xqZ0s.js} +2 -2
- package/dist/chunks/{index.C5r1PdPD.js → index.DyBZXrH3.js} +1 -1
- package/dist/chunks/{init-forks.BC6ZwHQN.js → init-forks.CHeQ9Moq.js} +1 -1
- package/dist/chunks/{init-threads.CxSxLC0N.js → init-threads.uZiNAuPk.js} +1 -1
- package/dist/chunks/{init.C9kljSTm.js → init.DVtKdFty.js} +21 -6
- package/dist/chunks/{plugin.d.CtqpEehP.d.ts → plugin.d.D8KU2PY_.d.ts} +1 -1
- package/dist/chunks/{reporters.d.CWXNI2jG.d.ts → reporters.d.Db3MiIWX.d.ts} +48 -20
- package/dist/chunks/rpc.HLmECnw_.js +148 -0
- package/dist/chunks/{setup-common.Cm-kSBVi.js → setup-common.BcqLPsn5.js} +1 -1
- package/dist/chunks/{startModuleRunner.DEj0jb3e.js → startModuleRunner.C5CcWyXW.js} +22 -22
- package/dist/chunks/{vi.2VT5v0um.js → test.prxIahgM.js} +500 -119
- package/dist/chunks/{vm.CMjifoPa.js → vm.CrifS09m.js} +5 -8
- package/dist/chunks/{worker.d.Dyxm8DEL.d.ts → worker.d.Bji1eq5g.d.ts} +1 -1
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +9 -9
- package/dist/coverage.d.ts +7 -7
- package/dist/coverage.js +3 -1
- package/dist/environments.js +2 -0
- package/dist/index.d.ts +21 -9
- package/dist/index.js +8 -7
- package/dist/module-evaluator.js +1 -5
- package/dist/node.d.ts +11 -10
- package/dist/node.js +19 -19
- package/dist/reporters.d.ts +7 -7
- package/dist/reporters.js +4 -2
- package/dist/runners.d.ts +23 -4
- package/dist/runners.js +4 -4
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +36 -0
- package/dist/snapshot.js +2 -0
- package/dist/suite.js +2 -0
- package/dist/worker.d.ts +4 -3
- package/dist/worker.js +8 -10
- package/dist/workers/forks.js +9 -11
- package/dist/workers/runVmTests.js +10 -12
- package/dist/workers/threads.js +9 -11
- package/dist/workers/vmForks.js +6 -7
- package/dist/workers/vmThreads.js +6 -7
- package/package.json +23 -27
- package/dist/chunks/date.Bq6ZW5rf.js +0 -73
- package/dist/chunks/rpc.BoxB0q7B.js +0 -76
- package/dist/chunks/test.B8ej_ZHS.js +0 -254
- package/dist/mocker.d.ts +0 -1
- package/dist/mocker.js +0 -1
- package/dist/module-runner.js +0 -17
|
@@ -2470,6 +2470,13 @@ function resolveConfig$1(vitest, options, viteConfig) {
|
|
|
2470
2470
|
root: viteConfig.root,
|
|
2471
2471
|
mode
|
|
2472
2472
|
};
|
|
2473
|
+
if (resolved.retry && typeof resolved.retry === "object" && typeof resolved.retry.condition === "function") {
|
|
2474
|
+
logger.console.warn(c.yellow("Warning: retry.condition function cannot be used inside a config file. Use a RegExp pattern instead, or define the function in your test file."));
|
|
2475
|
+
resolved.retry = {
|
|
2476
|
+
...resolved.retry,
|
|
2477
|
+
condition: void 0
|
|
2478
|
+
};
|
|
2479
|
+
}
|
|
2473
2480
|
if (options.pool && typeof options.pool !== "string") {
|
|
2474
2481
|
resolved.pool = options.pool.name;
|
|
2475
2482
|
resolved.poolRunner = options.pool;
|
|
@@ -3194,17 +3201,19 @@ Update your dependencies and make sure the versions match.`));
|
|
|
3194
3201
|
const servers = [...ctx.projects.map((project) => ({
|
|
3195
3202
|
root: project.config.root,
|
|
3196
3203
|
isBrowserEnabled: project.isBrowserEnabled(),
|
|
3197
|
-
vite: project.vite
|
|
3204
|
+
vite: project.vite,
|
|
3205
|
+
environment: project.config.environment
|
|
3198
3206
|
})), (
|
|
3199
3207
|
// Check core last as it will match all files anyway
|
|
3200
3208
|
{
|
|
3201
3209
|
root: ctx.config.root,
|
|
3202
3210
|
vite: ctx.vite,
|
|
3203
|
-
isBrowserEnabled: ctx.getRootProject().isBrowserEnabled()
|
|
3211
|
+
isBrowserEnabled: ctx.getRootProject().isBrowserEnabled(),
|
|
3212
|
+
environment: ctx.config.environment
|
|
3204
3213
|
})];
|
|
3205
3214
|
return async function transformFile(filename) {
|
|
3206
3215
|
let lastError;
|
|
3207
|
-
for (const { root, vite, isBrowserEnabled } of servers) {
|
|
3216
|
+
for (const { root, vite, isBrowserEnabled, environment } of servers) {
|
|
3208
3217
|
// On Windows root doesn't start with "/" while filenames do
|
|
3209
3218
|
if (!filename.startsWith(root) && !filename.startsWith(`/${root}`)) continue;
|
|
3210
3219
|
if (isBrowserEnabled) {
|
|
@@ -3212,12 +3221,13 @@ Update your dependencies and make sure the versions match.`));
|
|
|
3212
3221
|
if (result) return result;
|
|
3213
3222
|
}
|
|
3214
3223
|
try {
|
|
3224
|
+
if (environment === "jsdom" || environment === "happy-dom") return await vite.environments.client.transformRequest(filename);
|
|
3215
3225
|
return await vite.environments.ssr.transformRequest(filename);
|
|
3216
3226
|
} catch (error) {
|
|
3217
3227
|
lastError = error;
|
|
3218
3228
|
}
|
|
3219
3229
|
}
|
|
3220
|
-
// All vite
|
|
3230
|
+
// All vite servers failed to transform the file
|
|
3221
3231
|
throw lastError;
|
|
3222
3232
|
};
|
|
3223
3233
|
}
|
|
@@ -226,6 +226,37 @@ import { expect, test } from 'vitest'
|
|
|
226
226
|
import { render } from 'vitest-browser-qwik'
|
|
227
227
|
import HelloWorld from './HelloWorld.tsx'
|
|
228
228
|
|
|
229
|
+
test('renders name', async () => {
|
|
230
|
+
const { getByText } = render(<HelloWorld name="Vitest" />)
|
|
231
|
+
await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
|
|
232
|
+
})
|
|
233
|
+
`
|
|
234
|
+
};
|
|
235
|
+
const preactExample = {
|
|
236
|
+
name: "HelloWorld.jsx",
|
|
237
|
+
js: `
|
|
238
|
+
export default function HelloWorld({ name }) {
|
|
239
|
+
return (
|
|
240
|
+
<div>
|
|
241
|
+
<h1>Hello {name}!</h1>
|
|
242
|
+
</div>
|
|
243
|
+
)
|
|
244
|
+
}
|
|
245
|
+
`,
|
|
246
|
+
ts: `
|
|
247
|
+
export default function HelloWorld({ name }: { name: string }) {
|
|
248
|
+
return (
|
|
249
|
+
<div>
|
|
250
|
+
<h1>Hello {name}!</h1>
|
|
251
|
+
</div>
|
|
252
|
+
)
|
|
253
|
+
}
|
|
254
|
+
`,
|
|
255
|
+
test: `
|
|
256
|
+
import { expect, test } from 'vitest'
|
|
257
|
+
import { render } from 'vitest-browser-preact'
|
|
258
|
+
import HelloWorld from './HelloWorld.<EXT>x'
|
|
259
|
+
|
|
229
260
|
test('renders name', async () => {
|
|
230
261
|
const { getByText } = render(<HelloWorld name="Vitest" />)
|
|
231
262
|
await expect.element(getByText('Hello Vitest!')).toBeInTheDocument()
|
|
@@ -276,7 +307,7 @@ function getExampleTest(framework) {
|
|
|
276
307
|
...jsxExample,
|
|
277
308
|
test: jsxExample.test.replace("@testing-library/jsx", `@testing-library/${framework}`)
|
|
278
309
|
};
|
|
279
|
-
case "preact":
|
|
310
|
+
case "preact": return preactExample;
|
|
280
311
|
case "react": return {
|
|
281
312
|
...jsxExample,
|
|
282
313
|
test: jsxExample.test.replace("@testing-library/jsx", `vitest-browser-${framework}`)
|
|
@@ -1,22 +1,23 @@
|
|
|
1
1
|
import { g as globalApis } from './constants.D_Q9UYh-.js';
|
|
2
|
-
import { i as index } from './index.
|
|
3
|
-
import './
|
|
4
|
-
import '@vitest/expect';
|
|
2
|
+
import { i as index } from './index.BEFi2-_3.js';
|
|
3
|
+
import './test.prxIahgM.js';
|
|
5
4
|
import '@vitest/runner';
|
|
6
|
-
import '
|
|
5
|
+
import '@vitest/utils/helpers';
|
|
7
6
|
import '@vitest/utils/timers';
|
|
7
|
+
import './benchmark.B3N2zMcH.js';
|
|
8
8
|
import '@vitest/runner/utils';
|
|
9
|
-
import '
|
|
9
|
+
import './utils.DvEY5TfP.js';
|
|
10
|
+
import '@vitest/expect';
|
|
10
11
|
import '@vitest/utils/error';
|
|
11
|
-
import '
|
|
12
|
+
import 'pathe';
|
|
13
|
+
import '@vitest/snapshot';
|
|
12
14
|
import '@vitest/spy';
|
|
13
15
|
import '@vitest/utils/offset';
|
|
14
16
|
import '@vitest/utils/source-map';
|
|
15
17
|
import './_commonjsHelpers.D26ty3Ew.js';
|
|
16
|
-
import './
|
|
17
|
-
import './
|
|
18
|
+
import './rpc.HLmECnw_.js';
|
|
19
|
+
import './index.Chj8NDwU.js';
|
|
18
20
|
import './evaluatedModules.Dg1zASAC.js';
|
|
19
|
-
import 'pathe';
|
|
20
21
|
import 'vite/module-runner';
|
|
21
22
|
import 'expect-type';
|
|
22
23
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { N as NodeBenchmarkRunner, T as TestRunner, a as assert, c as createExpect, g as globalExpect, i as inject, s as should, v as vi, b as vitest } from './test.prxIahgM.js';
|
|
2
2
|
import { b as bench } from './benchmark.B3N2zMcH.js';
|
|
3
3
|
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
4
4
|
import { expectTypeOf } from 'expect-type';
|
|
@@ -9,7 +9,9 @@ const assertType = function assertType() {};
|
|
|
9
9
|
|
|
10
10
|
var index = /*#__PURE__*/Object.freeze({
|
|
11
11
|
__proto__: null,
|
|
12
|
+
BenchmarkRunner: NodeBenchmarkRunner,
|
|
12
13
|
EvaluatedModules: VitestEvaluatedModules,
|
|
14
|
+
TestRunner: TestRunner,
|
|
13
15
|
afterAll: afterAll,
|
|
14
16
|
afterEach: afterEach,
|
|
15
17
|
assert: assert,
|
|
@@ -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.
|
|
2
|
+
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.BcqLPsn5.js';
|
|
3
|
+
import { r as rpc } from './rpc.HLmECnw_.js';
|
|
4
4
|
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
5
|
-
import {
|
|
5
|
+
import { T as TestRunner, N as NodeBenchmarkRunner } from './test.prxIahgM.js';
|
|
6
6
|
|
|
7
7
|
function setupChaiConfig(config) {
|
|
8
8
|
Object.assign(chai.config, config);
|
|
@@ -19,7 +19,7 @@ async function resolveSnapshotEnvironment(config, executor) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
async function getTestRunnerConstructor(config, moduleRunner) {
|
|
22
|
-
if (!config.runner) return config.mode === "test" ?
|
|
22
|
+
if (!config.runner) return config.mode === "test" ? TestRunner : NodeBenchmarkRunner;
|
|
23
23
|
const mod = await moduleRunner.import(config.runner);
|
|
24
24
|
if (!mod.default && typeof mod.default !== "function") throw new Error(`Runner must export a default function, but got ${typeof mod.default} imported from ${config.runner}`);
|
|
25
25
|
return mod.default;
|
|
@@ -78,6 +78,18 @@ async function resolveTestRunner(config, moduleRunner, traces) {
|
|
|
78
78
|
state.durations.prepare = 0;
|
|
79
79
|
state.durations.environment = 0;
|
|
80
80
|
});
|
|
81
|
+
// Strip function conditions from retry config before sending via RPC
|
|
82
|
+
// Functions cannot be cloned by structured clone algorithm
|
|
83
|
+
const sanitizeRetryConditions = (task) => {
|
|
84
|
+
if (task.retry && typeof task.retry === "object" && typeof task.retry.condition === "function")
|
|
85
|
+
// Remove function condition - it can't be serialized
|
|
86
|
+
task.retry = {
|
|
87
|
+
...task.retry,
|
|
88
|
+
condition: void 0
|
|
89
|
+
};
|
|
90
|
+
if (task.tasks) task.tasks.forEach(sanitizeRetryConditions);
|
|
91
|
+
};
|
|
92
|
+
files.forEach(sanitizeRetryConditions);
|
|
81
93
|
rpc().onCollected(files);
|
|
82
94
|
await originalOnCollected?.call(testRunner, files);
|
|
83
95
|
};
|
|
@@ -2599,7 +2599,7 @@ async function collectTests(ctx, filepath) {
|
|
|
2599
2599
|
});
|
|
2600
2600
|
calculateSuiteHash(file);
|
|
2601
2601
|
const hasOnly = someTasksAreOnly(file);
|
|
2602
|
-
interpretTaskModes(file, ctx.config.testNamePattern, void 0, hasOnly, false, ctx.config.allowOnly);
|
|
2602
|
+
interpretTaskModes(file, ctx.config.testNamePattern, void 0, void 0, hasOnly, false, ctx.config.allowOnly);
|
|
2603
2603
|
return {
|
|
2604
2604
|
file,
|
|
2605
2605
|
parsed: request.code,
|
|
@@ -3677,7 +3677,7 @@ class JUnitReporter {
|
|
|
3677
3677
|
await this.writeElement("testsuite", {
|
|
3678
3678
|
name: filename,
|
|
3679
3679
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3680
|
-
hostname: hostname(),
|
|
3680
|
+
hostname: this.options.hostname || hostname(),
|
|
3681
3681
|
tests: file.tasks.length,
|
|
3682
3682
|
failures: file.stats.failures,
|
|
3683
3683
|
errors: 0,
|
|
@@ -2,7 +2,7 @@ import fs from 'node:fs';
|
|
|
2
2
|
import { getTasks, getFullName, getTests } from '@vitest/runner/utils';
|
|
3
3
|
import * as pathe from 'pathe';
|
|
4
4
|
import c from 'tinyrainbow';
|
|
5
|
-
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName, s as separator } from './index.
|
|
5
|
+
import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName, s as separator } from './index.Dm4xqZ0s.js';
|
|
6
6
|
import { stripVTControlCharacters } from 'node:util';
|
|
7
7
|
import { notNullish } from '@vitest/utils/helpers';
|
|
8
8
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isMainThread, parentPort } from 'node:worker_threads';
|
|
2
|
-
import { i as init } from './init.
|
|
2
|
+
import { i as init } from './init.DVtKdFty.js';
|
|
3
3
|
|
|
4
4
|
if (isMainThread || !parentPort) throw new Error("Expected worker to be run in node:worker_threads");
|
|
5
5
|
function workerInit(options) {
|
|
@@ -3,11 +3,11 @@ import { isBuiltin } from 'node:module';
|
|
|
3
3
|
import { pathToFileURL } from 'node:url';
|
|
4
4
|
import { resolve } from 'pathe';
|
|
5
5
|
import { ModuleRunner } from 'vite/module-runner';
|
|
6
|
-
import { b as VitestTransport } from './startModuleRunner.
|
|
6
|
+
import { b as VitestTransport } from './startModuleRunner.C5CcWyXW.js';
|
|
7
7
|
import { e as environments } from './index.CyBMJtT7.js';
|
|
8
8
|
import { serializeError } from '@vitest/utils/error';
|
|
9
9
|
import { T as Traces } from './traces.CCmnQaNT.js';
|
|
10
|
-
import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.
|
|
10
|
+
import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.HLmECnw_.js';
|
|
11
11
|
import { createStackString, parseStacktrace } from '@vitest/utils/source-map';
|
|
12
12
|
import { s as setupInspect } from './inspector.CvyFGlXm.js';
|
|
13
13
|
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
@@ -65,8 +65,22 @@ async function loadEnvironment(name, root, rpc, traces) {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
const cleanupListeners = /* @__PURE__ */ new Set();
|
|
69
|
+
const moduleRunnerListeners = /* @__PURE__ */ new Set();
|
|
70
|
+
function onCleanup(cb) {
|
|
71
|
+
cleanupListeners.add(cb);
|
|
72
|
+
}
|
|
73
|
+
async function cleanup() {
|
|
74
|
+
await Promise.all([...cleanupListeners].map((l) => l()));
|
|
75
|
+
}
|
|
76
|
+
function onModuleRunner(cb) {
|
|
77
|
+
moduleRunnerListeners.add(cb);
|
|
78
|
+
}
|
|
79
|
+
function emitModuleRunner(moduleRunner) {
|
|
80
|
+
moduleRunnerListeners.forEach((l) => l(moduleRunner));
|
|
81
|
+
}
|
|
82
|
+
|
|
68
83
|
const resolvingModules = /* @__PURE__ */ new Set();
|
|
69
|
-
const globalListeners = /* @__PURE__ */ new Set();
|
|
70
84
|
async function execute(method, ctx, worker, traces) {
|
|
71
85
|
const prepareStart = performance.now();
|
|
72
86
|
const cleanups = [setupInspect(ctx)];
|
|
@@ -92,7 +106,7 @@ async function execute(method, ctx, worker, traces) {
|
|
|
92
106
|
},
|
|
93
107
|
rpc,
|
|
94
108
|
onCancel,
|
|
95
|
-
onCleanup:
|
|
109
|
+
onCleanup: onCleanup,
|
|
96
110
|
providedContext: ctx.providedContext,
|
|
97
111
|
onFilterStackTrace(stack) {
|
|
98
112
|
return createStackString(parseStacktrace(stack));
|
|
@@ -114,7 +128,7 @@ function collect(ctx, worker, traces) {
|
|
|
114
128
|
return execute("collect", ctx, worker, traces);
|
|
115
129
|
}
|
|
116
130
|
async function teardown() {
|
|
117
|
-
await
|
|
131
|
+
await cleanup();
|
|
118
132
|
}
|
|
119
133
|
const env = process.env;
|
|
120
134
|
function createImportMetaEnvProxy() {
|
|
@@ -146,6 +160,7 @@ let traces;
|
|
|
146
160
|
/** @experimental */
|
|
147
161
|
function init(worker) {
|
|
148
162
|
worker.on(onMessage);
|
|
163
|
+
if (worker.onModuleRunner) onModuleRunner(worker.onModuleRunner);
|
|
149
164
|
let runPromise;
|
|
150
165
|
let isRunning = false;
|
|
151
166
|
let workerTeardown;
|
|
@@ -316,4 +331,4 @@ function getFilesWithLocations(files) {
|
|
|
316
331
|
});
|
|
317
332
|
}
|
|
318
333
|
|
|
319
|
-
export { init as i, loadEnvironment as l };
|
|
334
|
+
export { emitModuleRunner as e, init as i, loadEnvironment as l };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DevEnvironment } from 'vite';
|
|
2
|
-
import { V as Vitest, T as TestProject,
|
|
2
|
+
import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.Db3MiIWX.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Generate a unique cache identifier.
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { TaskMeta, Suite, File, TestAnnotation, TestArtifact, ImportDuration, Test, Task, TaskResultPack, FileSpecification, CancelReason, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
|
|
1
|
+
import { TaskMeta, Suite, File, SerializableRetry, TestAnnotation, TestArtifact, ImportDuration, Test, Task, TaskResultPack, FileSpecification, CancelReason, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
|
|
2
2
|
import { TestError, SerializedError, Arrayable, ParsedStack, Awaitable } from '@vitest/utils';
|
|
3
3
|
import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, L as LabelColor } from './rpc.d.RH3apGEf.js';
|
|
4
4
|
import { Writable } from 'node:stream';
|
|
5
5
|
import { DevEnvironment, TransformResult as TransformResult$1, ViteDevServer, Plugin, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
|
|
6
|
-
import { S as SerializedTestSpecification, c as SourceModuleDiagnostic, B as BrowserTesterOptions } from './browser.d.
|
|
7
|
-
import {
|
|
8
|
-
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
9
|
-
import { BrowserCommands } from 'vitest/browser';
|
|
10
|
-
import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.Cy95HiCx.js';
|
|
6
|
+
import { S as SerializedTestSpecification, c as SourceModuleDiagnostic, B as BrowserTesterOptions } from './browser.d.8hOapKZr.js';
|
|
7
|
+
import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.idH22YSr.js';
|
|
11
8
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
|
12
9
|
import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
|
|
13
10
|
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
14
11
|
import { chai } from '@vitest/expect';
|
|
15
12
|
import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
|
|
16
|
-
import { c as ContextTestEnvironment, d as WorkerExecuteContext, e as WorkerTestEnvironment } from './worker.d.
|
|
13
|
+
import { c as ContextTestEnvironment, d as WorkerExecuteContext, e as WorkerTestEnvironment } from './worker.d.Bji1eq5g.js';
|
|
17
14
|
import { O as OTELCarrier } from './traces.d.402V_yFI.js';
|
|
18
15
|
import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
|
|
16
|
+
import { MockedModule } from '@vitest/mocker';
|
|
17
|
+
import { StackTraceParserOptions } from '@vitest/utils/source-map';
|
|
18
|
+
import { BrowserCommands } from 'vitest/browser';
|
|
19
19
|
import { a as RuntimeCoverageProviderModule } from './coverage.d.BZtK59WP.js';
|
|
20
20
|
import { SnapshotManager } from '@vitest/snapshot/manager';
|
|
21
21
|
import { Console } from 'node:console';
|
|
@@ -278,7 +278,7 @@ interface TaskOptions {
|
|
|
278
278
|
readonly fails: boolean | undefined;
|
|
279
279
|
readonly concurrent: boolean | undefined;
|
|
280
280
|
readonly shuffle: boolean | undefined;
|
|
281
|
-
readonly retry:
|
|
281
|
+
readonly retry: SerializableRetry | undefined;
|
|
282
282
|
readonly repeats: number | undefined;
|
|
283
283
|
readonly mode: "run" | "only" | "skip" | "todo";
|
|
284
284
|
}
|
|
@@ -402,9 +402,14 @@ declare function experimental_getRunnerTask(entity: TestSuite): Suite;
|
|
|
402
402
|
declare function experimental_getRunnerTask(entity: TestModule): File;
|
|
403
403
|
declare function experimental_getRunnerTask(entity: TestCase | TestSuite | TestModule): Suite | File | Test;
|
|
404
404
|
|
|
405
|
+
interface TestSpecificationOptions {
|
|
406
|
+
testNamePattern?: RegExp;
|
|
407
|
+
testIds?: string[];
|
|
408
|
+
testLines?: number[];
|
|
409
|
+
}
|
|
405
410
|
declare class TestSpecification {
|
|
406
411
|
/**
|
|
407
|
-
* The task
|
|
412
|
+
* The task id associated with the test module.
|
|
408
413
|
*/
|
|
409
414
|
readonly taskId: string;
|
|
410
415
|
/**
|
|
@@ -412,21 +417,28 @@ declare class TestSpecification {
|
|
|
412
417
|
*/
|
|
413
418
|
readonly project: TestProject;
|
|
414
419
|
/**
|
|
415
|
-
* The
|
|
420
|
+
* The id of the module in the Vite module graph. It is usually an absolute file path.
|
|
416
421
|
*/
|
|
417
422
|
readonly moduleId: string;
|
|
418
423
|
/**
|
|
419
|
-
* The current test pool. It's possible to have multiple pools in a single test project with `
|
|
420
|
-
* @experimental In
|
|
424
|
+
* The current test pool. It's possible to have multiple pools in a single test project with `typecheck.enabled`.
|
|
425
|
+
* @experimental In later versions, the project will only support a single pool.
|
|
421
426
|
*/
|
|
422
427
|
readonly pool: Pool;
|
|
423
428
|
/**
|
|
424
429
|
* Line numbers of the test locations to run.
|
|
425
430
|
*/
|
|
426
431
|
readonly testLines: number[] | undefined;
|
|
427
|
-
constructor(project: TestProject, moduleId: string, pool: Pool, testLines?: number[] | undefined);
|
|
428
432
|
/**
|
|
429
|
-
*
|
|
433
|
+
* Regular expression pattern to filter test names.
|
|
434
|
+
*/
|
|
435
|
+
readonly testNamePattern: RegExp | undefined;
|
|
436
|
+
/**
|
|
437
|
+
* The ids of tasks inside of this specification to run.
|
|
438
|
+
*/
|
|
439
|
+
readonly testIds: string[] | undefined;
|
|
440
|
+
/**
|
|
441
|
+
* Test module associated with the specification. This will be `undefined` if tests have not been run yet.
|
|
430
442
|
*/
|
|
431
443
|
get testModule(): TestModule | undefined;
|
|
432
444
|
toJSON(): SerializedTestSpecification;
|
|
@@ -1278,6 +1290,12 @@ declare class Vitest {
|
|
|
1278
1290
|
*/
|
|
1279
1291
|
runTestSpecifications(specifications: TestSpecification[], allTestsRun?: boolean): Promise<TestRunResult>;
|
|
1280
1292
|
/**
|
|
1293
|
+
* Runs tests for the given file paths. This does not trigger `onWatcher*` events.
|
|
1294
|
+
* @param filepaths A list of file paths to run tests for.
|
|
1295
|
+
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
1296
|
+
*/
|
|
1297
|
+
runTestFiles(filepaths: string[], allTestsRun?: boolean): Promise<TestRunResult>;
|
|
1298
|
+
/**
|
|
1281
1299
|
* Rerun files and trigger `onWatcherRerun`, `onWatcherStart` and `onTestsRerun` events.
|
|
1282
1300
|
* @param specifications A list of specifications to run.
|
|
1283
1301
|
* @param allTestsRun Indicates whether all tests were run. This only matters for coverage.
|
|
@@ -1825,7 +1843,7 @@ declare class TestProject {
|
|
|
1825
1843
|
* Creates a new test specification. Specifications describe how to run tests.
|
|
1826
1844
|
* @param moduleId The file path
|
|
1827
1845
|
*/
|
|
1828
|
-
createSpecification(moduleId: string,
|
|
1846
|
+
createSpecification(moduleId: string, locationsOrOptions?: number[] | TestSpecificationOptions | undefined, pool?: string): TestSpecification;
|
|
1829
1847
|
toJSON(): SerializedTestProject;
|
|
1830
1848
|
/**
|
|
1831
1849
|
* Vite's dev server instance. Every workspace project has its own server.
|
|
@@ -2166,6 +2184,10 @@ interface JUnitOptions {
|
|
|
2166
2184
|
* @default false
|
|
2167
2185
|
*/
|
|
2168
2186
|
addFileAttribute?: boolean;
|
|
2187
|
+
/**
|
|
2188
|
+
* Hostname to use in the report. By default, it uses os.hostname()
|
|
2189
|
+
*/
|
|
2190
|
+
hostname?: string;
|
|
2169
2191
|
}
|
|
2170
2192
|
declare class JUnitReporter implements Reporter {
|
|
2171
2193
|
private ctx;
|
|
@@ -2976,11 +2998,17 @@ interface InlineConfig {
|
|
|
2976
2998
|
*/
|
|
2977
2999
|
bail?: number;
|
|
2978
3000
|
/**
|
|
2979
|
-
* Retry
|
|
3001
|
+
* Retry configuration for tests.
|
|
3002
|
+
* - If a number, specifies how many times to retry failed tests
|
|
3003
|
+
* - If an object, allows fine-grained retry control
|
|
2980
3004
|
*
|
|
2981
|
-
*
|
|
3005
|
+
* ⚠️ WARNING: Function form is NOT supported in a config file
|
|
3006
|
+
* because configurations are serialized when passed to worker threads.
|
|
3007
|
+
* Use the function form only in test files directly.
|
|
3008
|
+
*
|
|
3009
|
+
* @default 0 // Don't retry
|
|
2982
3010
|
*/
|
|
2983
|
-
retry?:
|
|
3011
|
+
retry?: SerializableRetry;
|
|
2984
3012
|
/**
|
|
2985
3013
|
* Show full diff when snapshot fails instead of a patch.
|
|
2986
3014
|
*/
|
|
@@ -3267,5 +3295,5 @@ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
|
|
|
3267
3295
|
});
|
|
3268
3296
|
type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
|
|
3269
3297
|
|
|
3270
|
-
export {
|
|
3271
|
-
export type {
|
|
3298
|
+
export { BenchmarkReporter as B, DefaultReporter as D, GithubActionsReporter as G, HangingProcessReporter as H, JsonReporter as J, Logger as L, TestProject as T, Vitest as V, TestCase as a3, TestCollection as a4, TestModule as a6, CoverageMap as aY, TestSuite as ad, experimental_getRunnerTask as af, TestSpecification as i, VitestPackageInstaller as n, BenchmarkReportsMap as r, DotReporter as s, JUnitReporter as t, ReportersMap as u, TapFlatReporter as v, TapReporter as w, VerboseBenchmarkReporter as x, VerboseReporter as y, BaseReporter as z };
|
|
3299
|
+
export type { JsonOptions as $, ApiConfig as A, CoverageV8Options as C, BenchmarkBuiltinReporters as E, BuiltinReporterOptions as F, InlineConfig as I, BuiltinReporters as K, JsonAssertionResult as M, JsonTestResult as N, OnServerRestartHandler as O, PoolWorker as P, JsonTestResults as Q, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, ReportedHookContext as X, Reporter as Y, TestRunEndReason as Z, HTMLOptions as _, TestProjectConfiguration as a, JUnitOptions as a0, ModuleDiagnostic as a1, TaskOptions as a2, TestDiagnostic as a5, TestModuleState as a7, TestResult as a8, TestResultFailed as a9, ProjectBrowser as aA, ResolvedBrowserOptions as aB, ToMatchScreenshotComparators as aC, ToMatchScreenshotOptions as aD, BuiltinEnvironment as aE, CSSModuleScopeStrategy as aF, DepsOptimizationOptions as aG, EnvironmentOptions as aH, Pool as aI, ProjectConfig as aJ, ResolvedProjectConfig as aK, ResolveSnapshotPathHandler as aL, ResolveSnapshotPathHandlerContext as aM, TypecheckConfig as aN, VitestEnvironment as aO, BaseCoverageOptions as aP, CoverageIstanbulOptions as aQ, CoverageOptions as aR, CoverageProvider as aS, CoverageProviderModule as aT, CoverageReporter as aU, CustomProviderOptions as aV, ReportContext as aW, TestRunResult as aX, TestResultPassed as aa, TestResultSkipped as ab, TestState as ac, TestSuiteState as ae, TestSequencerConstructor as ag, TestSpecificationOptions as ah, BenchmarkUserOptions as ai, _BrowserNames as aj, BrowserBuiltinProvider as ak, BrowserCommand as al, BrowserCommandContext as am, BrowserConfigOptions as an, BrowserInstanceOption as ao, BrowserModuleMocker as ap, BrowserOrchestrator as aq, BrowserProvider as ar, BrowserProviderOption as as, BrowserScript as at, BrowserServerFactory as au, BrowserServerOptions as av, BrowserServerState as aw, BrowserServerStateSession as ax, CDPSession as ay, ParentProjectBrowser as az, UserProjectConfigFn as b, UserProjectConfigExport as c, UserConfig as d, TestProjectInlineConfiguration as e, ResolvedConfig as f, VitestRunMode as g, VitestOptions as h, PoolOptions as j, WorkerRequest as k, TestSequencer as l, OnTestsRerunHandler as m, PoolRunnerInitializer as o, PoolTask as p, WorkerResponse as q };
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { getSafeTimers } from '@vitest/utils/timers';
|
|
2
|
+
import { c as createBirpc } from './index.Chj8NDwU.js';
|
|
3
|
+
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
4
|
+
|
|
5
|
+
/* Ported from https://github.com/boblauer/MockDate/blob/master/src/mockdate.ts */
|
|
6
|
+
/*
|
|
7
|
+
The MIT License (MIT)
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2014 Bob Lauer
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
*/
|
|
29
|
+
const RealDate = Date;
|
|
30
|
+
let now = null;
|
|
31
|
+
class MockDate extends RealDate {
|
|
32
|
+
constructor(y, m, d, h, M, s, ms) {
|
|
33
|
+
super();
|
|
34
|
+
let date;
|
|
35
|
+
switch (arguments.length) {
|
|
36
|
+
case 0:
|
|
37
|
+
if (now !== null) date = new RealDate(now.valueOf());
|
|
38
|
+
else date = new RealDate();
|
|
39
|
+
break;
|
|
40
|
+
case 1:
|
|
41
|
+
date = new RealDate(y);
|
|
42
|
+
break;
|
|
43
|
+
default:
|
|
44
|
+
d = typeof d === "undefined" ? 1 : d;
|
|
45
|
+
h = h || 0;
|
|
46
|
+
M = M || 0;
|
|
47
|
+
s = s || 0;
|
|
48
|
+
ms = ms || 0;
|
|
49
|
+
date = new RealDate(y, m, d, h, M, s, ms);
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
Object.setPrototypeOf(date, MockDate.prototype);
|
|
53
|
+
return date;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
MockDate.UTC = RealDate.UTC;
|
|
57
|
+
MockDate.now = function() {
|
|
58
|
+
return new MockDate().valueOf();
|
|
59
|
+
};
|
|
60
|
+
MockDate.parse = function(dateString) {
|
|
61
|
+
return RealDate.parse(dateString);
|
|
62
|
+
};
|
|
63
|
+
MockDate.toString = function() {
|
|
64
|
+
return RealDate.toString();
|
|
65
|
+
};
|
|
66
|
+
function mockDate(date) {
|
|
67
|
+
const dateObj = new RealDate(date.valueOf());
|
|
68
|
+
if (Number.isNaN(dateObj.getTime())) throw new TypeError(`mockdate: The time set is an invalid date: ${date}`);
|
|
69
|
+
// @ts-expect-error global
|
|
70
|
+
globalThis.Date = MockDate;
|
|
71
|
+
now = dateObj.valueOf();
|
|
72
|
+
}
|
|
73
|
+
function resetDate() {
|
|
74
|
+
globalThis.Date = RealDate;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const { get } = Reflect;
|
|
78
|
+
function withSafeTimers(fn) {
|
|
79
|
+
const { setTimeout, clearTimeout, nextTick, setImmediate, clearImmediate } = getSafeTimers();
|
|
80
|
+
const currentSetTimeout = globalThis.setTimeout;
|
|
81
|
+
const currentClearTimeout = globalThis.clearTimeout;
|
|
82
|
+
const currentSetImmediate = globalThis.setImmediate;
|
|
83
|
+
const currentClearImmediate = globalThis.clearImmediate;
|
|
84
|
+
const currentNextTick = globalThis.process?.nextTick;
|
|
85
|
+
try {
|
|
86
|
+
globalThis.setTimeout = setTimeout;
|
|
87
|
+
globalThis.clearTimeout = clearTimeout;
|
|
88
|
+
if (setImmediate) globalThis.setImmediate = setImmediate;
|
|
89
|
+
if (clearImmediate) globalThis.clearImmediate = clearImmediate;
|
|
90
|
+
if (globalThis.process && nextTick) globalThis.process.nextTick = nextTick;
|
|
91
|
+
return fn();
|
|
92
|
+
} finally {
|
|
93
|
+
globalThis.setTimeout = currentSetTimeout;
|
|
94
|
+
globalThis.clearTimeout = currentClearTimeout;
|
|
95
|
+
globalThis.setImmediate = currentSetImmediate;
|
|
96
|
+
globalThis.clearImmediate = currentClearImmediate;
|
|
97
|
+
if (globalThis.process && nextTick) nextTick(() => {
|
|
98
|
+
globalThis.process.nextTick = currentNextTick;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const promises = /* @__PURE__ */ new Set();
|
|
103
|
+
async function rpcDone() {
|
|
104
|
+
if (!promises.size) return;
|
|
105
|
+
const awaitable = Array.from(promises);
|
|
106
|
+
return Promise.all(awaitable);
|
|
107
|
+
}
|
|
108
|
+
const onCancelCallbacks = [];
|
|
109
|
+
function onCancel(callback) {
|
|
110
|
+
onCancelCallbacks.push(callback);
|
|
111
|
+
}
|
|
112
|
+
function createRuntimeRpc(options) {
|
|
113
|
+
return createSafeRpc(createBirpc({ async onCancel(reason) {
|
|
114
|
+
await Promise.all(onCancelCallbacks.map((fn) => fn(reason)));
|
|
115
|
+
} }, {
|
|
116
|
+
eventNames: [
|
|
117
|
+
"onUserConsoleLog",
|
|
118
|
+
"onCollected",
|
|
119
|
+
"onCancel"
|
|
120
|
+
],
|
|
121
|
+
timeout: -1,
|
|
122
|
+
...options
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
function createSafeRpc(rpc) {
|
|
126
|
+
return new Proxy(rpc, { get(target, p, handler) {
|
|
127
|
+
// keep $rejectPendingCalls as sync function
|
|
128
|
+
if (p === "$rejectPendingCalls") return rpc.$rejectPendingCalls;
|
|
129
|
+
const sendCall = get(target, p, handler);
|
|
130
|
+
const safeSendCall = (...args) => withSafeTimers(async () => {
|
|
131
|
+
const result = sendCall(...args);
|
|
132
|
+
promises.add(result);
|
|
133
|
+
try {
|
|
134
|
+
return await result;
|
|
135
|
+
} finally {
|
|
136
|
+
promises.delete(result);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
safeSendCall.asEvent = sendCall.asEvent;
|
|
140
|
+
return safeSendCall;
|
|
141
|
+
} });
|
|
142
|
+
}
|
|
143
|
+
function rpc() {
|
|
144
|
+
const { rpc } = getWorkerState();
|
|
145
|
+
return rpc;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export { RealDate as R, rpcDone as a, resetDate as b, createRuntimeRpc as c, mockDate as m, onCancel as o, rpc as r };
|
|
@@ -26,7 +26,7 @@ async function setupCommonEnv(config) {
|
|
|
26
26
|
if (globalSetup) return;
|
|
27
27
|
globalSetup = true;
|
|
28
28
|
setSafeTimers();
|
|
29
|
-
if (config.globals) (await import('./globals.
|
|
29
|
+
if (config.globals) (await import('./globals.DjuGMoMc.js')).registerApiGlobally();
|
|
30
30
|
}
|
|
31
31
|
function setupDefines(config) {
|
|
32
32
|
for (const key in config.defines) globalThis[key] = config.defines[key];
|