vitest 4.0.10 → 4.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.d.ts +4 -3
- package/dist/browser.js +1 -1
- package/dist/chunks/{base.BFVArrYW.js → base.DiCUKpyF.js} +46 -39
- package/dist/chunks/{browser.d.DnU_kh8a.d.ts → browser.d.D-d8eZY4.d.ts} +1 -1
- package/dist/chunks/{cac.D9CYcNPM.js → cac.aVhqBj0-.js} +21 -7
- package/dist/chunks/{cli-api.RnIE1JbW.js → cli-api.-bIZD4XU.js} +910 -297
- package/dist/chunks/{coverage.BUlIqJrL.js → coverage.CtyeYmKM.js} +7 -1
- package/dist/chunks/{creator.DU9qFjsW.js → creator.DAmOKTvJ.js} +3 -3
- package/dist/chunks/{global.d.BQDgW9Pr.d.ts → global.d.uY4Q0M5z.d.ts} +1 -1
- package/dist/chunks/{globals.NLOzC_A5.js → globals.C0izxiX3.js} +1 -1
- package/dist/chunks/{index.B8lJfb0J.js → index.CMvpbrsJ.js} +1 -1
- package/dist/chunks/{index.Dua7TZg_.js → index.CQwQ_SLL.js} +16 -4
- package/dist/chunks/{index.DZ-mI_Nm.js → index.DBx1AtPJ.js} +2 -1
- package/dist/chunks/{index.BYek7GgP.js → index.DWDW6mLz.js} +10 -1
- package/dist/chunks/{init-forks.BZSlxfwV.js → init-forks.DIuGPyId.js} +5 -5
- package/dist/chunks/{init-threads.CwE2n-Bv.js → init-threads.jC_8JdoN.js} +3 -3
- package/dist/chunks/{init.Cz2kTB9a.js → init.B3IeC_yW.js} +59 -21
- package/dist/chunks/{moduleRunner.d.BxT-OjLR.d.ts → moduleRunner.d.B5SW5pMI.d.ts} +9 -1
- package/dist/chunks/plugin.d.N8khPRFb.d.ts +38 -0
- package/dist/chunks/{reporters.d.keG-yFSu.d.ts → reporters.d.DgZLBdyd.d.ts} +107 -47
- package/dist/chunks/{setup-common.BOzbXE3x.js → setup-common.DGHc_BUK.js} +1 -1
- package/dist/chunks/{startModuleRunner.DLjmA_wU.js → startModuleRunner.DaBMy1JT.js} +97 -49
- package/dist/chunks/{test.BPErLMrw.js → test.DqQZzsWf.js} +14 -4
- package/dist/chunks/traces.BVPrsYso.js +151 -0
- package/dist/chunks/{config.d.BTfZNUu9.d.ts → traces.d.B8ukBJqA.d.ts} +36 -1
- package/dist/chunks/{vm.wSHjz-et.js → vm.BKyGp1KW.js} +12 -8
- package/dist/chunks/{worker.d.ZGohxCEd.d.ts → worker.d.B_PZTrCQ.d.ts} +5 -4
- package/dist/cli.js +2 -2
- package/dist/config.d.ts +8 -7
- package/dist/coverage.d.ts +6 -5
- package/dist/coverage.js +2 -2
- package/dist/index.d.ts +12 -10
- package/dist/index.js +2 -2
- package/dist/module-evaluator.d.ts +7 -6
- package/dist/module-evaluator.js +14 -1
- package/dist/module-runner.js +2 -1
- package/dist/node.d.ts +11 -10
- package/dist/node.js +8 -7
- package/dist/reporters.d.ts +6 -5
- package/dist/reporters.js +2 -2
- package/dist/runners.d.ts +5 -1
- package/dist/runners.js +1 -1
- package/dist/worker.d.ts +8 -7
- package/dist/worker.js +8 -7
- package/dist/workers/forks.js +9 -8
- package/dist/workers/runVmTests.js +22 -20
- package/dist/workers/threads.js +9 -8
- package/dist/workers/vmForks.js +5 -4
- package/dist/workers/vmThreads.js +5 -4
- package/package.json +17 -12
- package/dist/chunks/plugin.d.C6KrdvNG.d.ts +0 -9
|
@@ -7,10 +7,10 @@ import { glob } from 'tinyglobby';
|
|
|
7
7
|
import c from 'tinyrainbow';
|
|
8
8
|
import { c as configDefaults, e as benchmarkConfigDefaults, a as coverageConfigDefaults } from './defaults.BOqNVLsY.js';
|
|
9
9
|
import crypto from 'node:crypto';
|
|
10
|
+
import { fileURLToPath as fileURLToPath$1, pathToFileURL as pathToFileURL$1, URL as URL$1 } from 'node:url';
|
|
10
11
|
import { builtinModules, createRequire } from 'node:module';
|
|
11
12
|
import process$1 from 'node:process';
|
|
12
13
|
import fs$1 from 'node:fs/promises';
|
|
13
|
-
import { fileURLToPath as fileURLToPath$1, pathToFileURL as pathToFileURL$1, URL as URL$1 } from 'node:url';
|
|
14
14
|
import assert from 'node:assert';
|
|
15
15
|
import v8 from 'node:v8';
|
|
16
16
|
import { format, inspect } from 'node:util';
|
|
@@ -2792,6 +2792,12 @@ function resolveConfig$1(vitest, options, viteConfig) {
|
|
|
2792
2792
|
}
|
|
2793
2793
|
resolved.testTimeout ??= resolved.browser.enabled ? 3e4 : 5e3;
|
|
2794
2794
|
resolved.hookTimeout ??= resolved.browser.enabled ? 3e4 : 1e4;
|
|
2795
|
+
resolved.experimental ??= {};
|
|
2796
|
+
if (resolved.experimental.openTelemetry?.sdkPath) {
|
|
2797
|
+
const sdkPath = resolve(resolved.root, resolved.experimental.openTelemetry.sdkPath);
|
|
2798
|
+
resolved.experimental.openTelemetry.sdkPath = pathToFileURL$1(sdkPath).toString();
|
|
2799
|
+
}
|
|
2800
|
+
if (resolved.experimental.fsModuleCachePath) resolved.experimental.fsModuleCachePath = resolve(resolved.root, resolved.experimental.fsModuleCachePath);
|
|
2795
2801
|
return resolved;
|
|
2796
2802
|
}
|
|
2797
2803
|
function isBrowserEnabled(config) {
|
|
@@ -470,8 +470,8 @@ function getPossibleProvider(dependencies) {
|
|
|
470
470
|
}
|
|
471
471
|
function getProviderDocsLink(provider) {
|
|
472
472
|
switch (provider) {
|
|
473
|
-
case "playwright": return "https://vitest.dev/
|
|
474
|
-
case "webdriverio": return "https://vitest.dev/
|
|
473
|
+
case "playwright": return "https://vitest.dev/config/browser/playwright";
|
|
474
|
+
case "webdriverio": return "https://vitest.dev/config/browser/webdriverio";
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
function sort(choices, value) {
|
|
@@ -514,7 +514,7 @@ async function generateFrameworkConfigFile(options) {
|
|
|
514
514
|
` provider: ${options.provider}(),`,
|
|
515
515
|
options.provider !== "preview" && ` // ${getProviderDocsLink(options.provider)}`,
|
|
516
516
|
` instances: [`,
|
|
517
|
-
...options.browsers.map((browser) => `
|
|
517
|
+
...options.browsers.map((browser) => ` { browser: '${browser}' },`),
|
|
518
518
|
` ],`,
|
|
519
519
|
` },`,
|
|
520
520
|
` },`,
|
|
@@ -2,7 +2,7 @@ import { PromisifyAssertion, Tester, ExpectStatic } from '@vitest/expect';
|
|
|
2
2
|
import { Plugin } from '@vitest/pretty-format';
|
|
3
3
|
import { SnapshotState } from '@vitest/snapshot';
|
|
4
4
|
import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
|
|
5
|
-
import { U as UserConsoleLog } from './worker.d.
|
|
5
|
+
import { U as UserConsoleLog } from './worker.d.B_PZTrCQ.js';
|
|
6
6
|
|
|
7
7
|
interface SnapshotMatcher<T> {
|
|
8
8
|
<U extends { [P in keyof T] : any }>(snapshot: Partial<U>, hint?: string): void;
|
|
@@ -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.DWDW6mLz.js';
|
|
6
6
|
import { stripVTControlCharacters } from 'node:util';
|
|
7
7
|
import { notNullish } from '@vitest/utils/helpers';
|
|
8
8
|
|
|
@@ -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.
|
|
2
|
+
import { l as loadDiffConfig, b as loadSnapshotSerializers, t as takeCoverageInsideWorker } from './setup-common.DGHc_BUK.js';
|
|
3
3
|
import { r as rpc } from './rpc.BytlcPfC.js';
|
|
4
4
|
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
5
|
-
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.
|
|
5
|
+
import { V as VitestTestRunner, N as NodeBenchmarkRunner } from './test.DqQZzsWf.js';
|
|
6
6
|
|
|
7
7
|
function setupChaiConfig(config) {
|
|
8
8
|
Object.assign(chai.config, config);
|
|
@@ -24,7 +24,7 @@ async function getTestRunnerConstructor(config, moduleRunner) {
|
|
|
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;
|
|
26
26
|
}
|
|
27
|
-
async function resolveTestRunner(config, moduleRunner) {
|
|
27
|
+
async function resolveTestRunner(config, moduleRunner, traces) {
|
|
28
28
|
const testRunner = new (await (getTestRunnerConstructor(config, moduleRunner)))(config);
|
|
29
29
|
// inject private executor to every runner
|
|
30
30
|
Object.defineProperty(testRunner, "moduleRunner", {
|
|
@@ -34,6 +34,7 @@ async function resolveTestRunner(config, moduleRunner) {
|
|
|
34
34
|
});
|
|
35
35
|
if (!testRunner.config) testRunner.config = config;
|
|
36
36
|
if (!testRunner.importFile) throw new Error("Runner must implement \"importFile\" method.");
|
|
37
|
+
if ("__setTraces" in testRunner) testRunner.__setTraces(traces);
|
|
37
38
|
const [diffOptions] = await Promise.all([loadDiffConfig(config, moduleRunner), loadSnapshotSerializers(config, moduleRunner)]);
|
|
38
39
|
testRunner.config.diffOptions = diffOptions;
|
|
39
40
|
// patch some methods, so custom runners don't need to call RPC
|
|
@@ -46,9 +47,20 @@ async function resolveTestRunner(config, moduleRunner) {
|
|
|
46
47
|
// patch some methods, so custom runners don't need to call RPC
|
|
47
48
|
const originalOnTestAnnotate = testRunner.onTestAnnotate;
|
|
48
49
|
testRunner.onTestAnnotate = async (test, annotation) => {
|
|
49
|
-
const p = rpc().
|
|
50
|
+
const p = rpc().onTaskArtifactRecord(test.id, {
|
|
51
|
+
type: "internal:annotation",
|
|
52
|
+
location: annotation.location,
|
|
53
|
+
annotation
|
|
54
|
+
});
|
|
50
55
|
const overriddenResult = await originalOnTestAnnotate?.call(testRunner, test, annotation);
|
|
51
56
|
const vitestResult = await p;
|
|
57
|
+
return overriddenResult || vitestResult.annotation;
|
|
58
|
+
};
|
|
59
|
+
const originalOnTestArtifactRecord = testRunner.onTestArtifactRecord;
|
|
60
|
+
testRunner.onTestArtifactRecord = async (test, artifact) => {
|
|
61
|
+
const p = rpc().onTaskArtifactRecord(test.id, artifact);
|
|
62
|
+
const overriddenResult = await originalOnTestArtifactRecord?.call(testRunner, test, artifact);
|
|
63
|
+
const vitestResult = await p;
|
|
52
64
|
return overriddenResult || vitestResult;
|
|
53
65
|
};
|
|
54
66
|
const originalOnCollectStart = testRunner.onCollectStart;
|
|
@@ -2,7 +2,7 @@ import { b as assert, c as createExpect, g as globalExpect, i as inject, s as sh
|
|
|
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';
|
|
5
|
-
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, suite, test } from '@vitest/runner';
|
|
5
|
+
import { afterAll, afterEach, beforeAll, beforeEach, describe, it, onTestFailed, onTestFinished, recordArtifact, suite, test } from '@vitest/runner';
|
|
6
6
|
import { chai } from '@vitest/expect';
|
|
7
7
|
|
|
8
8
|
const assertType = function assertType() {};
|
|
@@ -26,6 +26,7 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
26
26
|
it: it,
|
|
27
27
|
onTestFailed: onTestFailed,
|
|
28
28
|
onTestFinished: onTestFinished,
|
|
29
|
+
recordArtifact: recordArtifact,
|
|
29
30
|
should: should,
|
|
30
31
|
suite: suite,
|
|
31
32
|
test: test,
|
|
@@ -327,6 +327,13 @@ function convertTasksToEvents(file, onTask) {
|
|
|
327
327
|
{ annotation }
|
|
328
328
|
]);
|
|
329
329
|
});
|
|
330
|
+
task.artifacts.forEach((artifact) => {
|
|
331
|
+
events.push([
|
|
332
|
+
task.id,
|
|
333
|
+
"test-artifact",
|
|
334
|
+
{ artifact }
|
|
335
|
+
]);
|
|
336
|
+
});
|
|
330
337
|
events.push([
|
|
331
338
|
task.id,
|
|
332
339
|
"test-finished",
|
|
@@ -2456,6 +2463,7 @@ async function collectTests(ctx, filepath) {
|
|
|
2456
2463
|
end: definition.end,
|
|
2457
2464
|
start: definition.start,
|
|
2458
2465
|
annotations: [],
|
|
2466
|
+
artifacts: [],
|
|
2459
2467
|
meta: { typecheck: true }
|
|
2460
2468
|
};
|
|
2461
2469
|
definition.task = task;
|
|
@@ -3499,7 +3507,8 @@ class JUnitReporter {
|
|
|
3499
3507
|
context: null,
|
|
3500
3508
|
suite: null,
|
|
3501
3509
|
file: null,
|
|
3502
|
-
annotations: []
|
|
3510
|
+
annotations: [],
|
|
3511
|
+
artifacts: []
|
|
3503
3512
|
});
|
|
3504
3513
|
}
|
|
3505
3514
|
return {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as init } from './init.
|
|
1
|
+
import { i as init } from './init.B3IeC_yW.js';
|
|
2
2
|
|
|
3
3
|
if (!process.send) throw new Error("Expected worker to be run in node:child_process");
|
|
4
4
|
// Store globals in case tests overwrite them
|
|
@@ -16,13 +16,13 @@ function workerInit(options) {
|
|
|
16
16
|
on: (cb) => processOn("message", cb),
|
|
17
17
|
off: (cb) => processOff("message", cb),
|
|
18
18
|
teardown: () => processRemoveAllListeners("message"),
|
|
19
|
-
runTests: (state) => executeTests("run", state),
|
|
20
|
-
collectTests: (state) => executeTests("collect", state),
|
|
19
|
+
runTests: (state, traces) => executeTests("run", state, traces),
|
|
20
|
+
collectTests: (state, traces) => executeTests("collect", state, traces),
|
|
21
21
|
setup: options.setup
|
|
22
22
|
});
|
|
23
|
-
async function executeTests(method, state) {
|
|
23
|
+
async function executeTests(method, state, traces) {
|
|
24
24
|
try {
|
|
25
|
-
await runTests(method, state);
|
|
25
|
+
await runTests(method, state, traces);
|
|
26
26
|
} finally {
|
|
27
27
|
process.exit = processExit;
|
|
28
28
|
}
|
|
@@ -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.B3IeC_yW.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) {
|
|
@@ -9,8 +9,8 @@ function workerInit(options) {
|
|
|
9
9
|
on: (callback) => parentPort.on("message", callback),
|
|
10
10
|
off: (callback) => parentPort.off("message", callback),
|
|
11
11
|
teardown: () => parentPort.removeAllListeners("message"),
|
|
12
|
-
runTests: async (state) => runTests("run", state),
|
|
13
|
-
collectTests: async (state) => runTests("collect", state),
|
|
12
|
+
runTests: async (state, traces) => runTests("run", state, traces),
|
|
13
|
+
collectTests: async (state, traces) => runTests("collect", state, traces),
|
|
14
14
|
setup: options.setup
|
|
15
15
|
});
|
|
16
16
|
}
|
|
@@ -3,9 +3,10 @@ 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.DaBMy1JT.js';
|
|
7
7
|
import { e as environments } from './index.QWbK7rHY.js';
|
|
8
8
|
import { serializeError } from '@vitest/utils/error';
|
|
9
|
+
import { T as Traces } from './traces.BVPrsYso.js';
|
|
9
10
|
import { o as onCancel, a as rpcDone, c as createRuntimeRpc } from './rpc.BytlcPfC.js';
|
|
10
11
|
import { createStackString, parseStacktrace } from '@vitest/utils/source-map';
|
|
11
12
|
import { s as setupInspect } from './inspector.CvyFGlXm.js';
|
|
@@ -16,7 +17,7 @@ function isBuiltinEnvironment(env) {
|
|
|
16
17
|
}
|
|
17
18
|
const isWindows = process.platform === "win32";
|
|
18
19
|
const _loaders = /* @__PURE__ */ new Map();
|
|
19
|
-
|
|
20
|
+
function createEnvironmentLoader(root, rpc) {
|
|
20
21
|
const cachedLoader = _loaders.get(root);
|
|
21
22
|
if (!cachedLoader || cachedLoader.isClosed()) {
|
|
22
23
|
_loaders.delete(root);
|
|
@@ -42,15 +43,14 @@ async function createEnvironmentLoader(root, rpc) {
|
|
|
42
43
|
})
|
|
43
44
|
});
|
|
44
45
|
_loaders.set(root, moduleRunner);
|
|
45
|
-
await moduleRunner.import("/@vite/env");
|
|
46
46
|
}
|
|
47
47
|
return _loaders.get(root);
|
|
48
48
|
}
|
|
49
|
-
async function loadEnvironment(name, root, rpc) {
|
|
49
|
+
async function loadEnvironment(name, root, rpc, traces) {
|
|
50
50
|
if (isBuiltinEnvironment(name)) return { environment: environments[name] };
|
|
51
|
-
const loader =
|
|
52
|
-
const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : (await rpc.resolve(`vitest-environment-${name}`, void 0, "__vitest__"))?.id ?? resolve(root, name);
|
|
53
|
-
const pkg = await loader.import(packageId);
|
|
51
|
+
const loader = createEnvironmentLoader(root, rpc);
|
|
52
|
+
const packageId = name[0] === "." || name[0] === "/" ? resolve(root, name) : (await traces.$("vitest.runtime.environment.resolve", () => rpc.resolve(`vitest-environment-${name}`, void 0, "__vitest__")))?.id ?? resolve(root, name);
|
|
53
|
+
const pkg = await traces.$("vitest.runtime.environment.import", () => loader.import(packageId));
|
|
54
54
|
if (!pkg || !pkg.default || typeof pkg.default !== "object") throw new TypeError(`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "setup" or/and "setupVM" method.`);
|
|
55
55
|
const environment = pkg.default;
|
|
56
56
|
if (environment.transformMode != null && environment.transformMode !== "web" && environment.transformMode !== "ssr") throw new TypeError(`Environment "${name}" is not a valid environment. Path "${packageId}" should export default object with a "transformMode" method equal to "ssr" or "web", received "${environment.transformMode}".`);
|
|
@@ -67,7 +67,7 @@ async function loadEnvironment(name, root, rpc) {
|
|
|
67
67
|
|
|
68
68
|
const resolvingModules = /* @__PURE__ */ new Set();
|
|
69
69
|
const globalListeners = /* @__PURE__ */ new Set();
|
|
70
|
-
async function execute(method, ctx, worker) {
|
|
70
|
+
async function execute(method, ctx, worker, traces) {
|
|
71
71
|
const prepareStart = performance.now();
|
|
72
72
|
const cleanups = [setupInspect(ctx)];
|
|
73
73
|
// RPC is used to communicate between worker (be it a thread worker or child process or a custom implementation) and the main thread
|
|
@@ -101,17 +101,17 @@ async function execute(method, ctx, worker) {
|
|
|
101
101
|
};
|
|
102
102
|
const methodName = method === "collect" ? "collectTests" : "runTests";
|
|
103
103
|
if (!worker[methodName] || typeof worker[methodName] !== "function") throw new TypeError(`Test worker should expose "runTests" method. Received "${typeof worker.runTests}".`);
|
|
104
|
-
await worker[methodName](state);
|
|
104
|
+
await worker[methodName](state, traces);
|
|
105
105
|
} finally {
|
|
106
106
|
await rpcDone().catch(() => {});
|
|
107
107
|
await Promise.all(cleanups.map((fn) => fn())).catch(() => {});
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
-
function run(ctx, worker) {
|
|
111
|
-
return execute("run", ctx, worker);
|
|
110
|
+
function run(ctx, worker, traces) {
|
|
111
|
+
return execute("run", ctx, worker, traces);
|
|
112
112
|
}
|
|
113
|
-
function collect(ctx, worker) {
|
|
114
|
-
return execute("collect", ctx, worker);
|
|
113
|
+
function collect(ctx, worker, traces) {
|
|
114
|
+
return execute("collect", ctx, worker, traces);
|
|
115
115
|
}
|
|
116
116
|
async function teardown() {
|
|
117
117
|
await Promise.all([...globalListeners].map((l) => l()));
|
|
@@ -142,6 +142,7 @@ function createImportMetaEnvProxy() {
|
|
|
142
142
|
const __vitest_worker_response__ = true;
|
|
143
143
|
const memoryUsage = process.memoryUsage.bind(process);
|
|
144
144
|
let reportMemory = false;
|
|
145
|
+
let traces;
|
|
145
146
|
/** @experimental */
|
|
146
147
|
function init(worker) {
|
|
147
148
|
worker.on(onMessage);
|
|
@@ -158,16 +159,26 @@ function init(worker) {
|
|
|
158
159
|
switch (message.type) {
|
|
159
160
|
case "start": {
|
|
160
161
|
reportMemory = message.options.reportMemory;
|
|
162
|
+
const tracesStart = performance.now();
|
|
163
|
+
traces ??= await new Traces({
|
|
164
|
+
enabled: message.traces.enabled,
|
|
165
|
+
sdkPath: message.traces.sdkPath
|
|
166
|
+
}).waitInit();
|
|
167
|
+
const tracesEnd = performance.now();
|
|
161
168
|
const { environment, config, pool } = message.context;
|
|
169
|
+
const context = traces.getContextFromCarrier(message.traces.otelCarrier);
|
|
170
|
+
// record telemetry as part of "start"
|
|
171
|
+
traces.startSpan("vitest.runtime.traces", { startTime: tracesStart }, context).end(tracesEnd);
|
|
162
172
|
try {
|
|
163
173
|
setupContext = {
|
|
164
174
|
environment,
|
|
165
175
|
config,
|
|
166
176
|
pool,
|
|
167
177
|
rpc: createRuntimeRpc(worker),
|
|
168
|
-
projectName: config.name || ""
|
|
178
|
+
projectName: config.name || "",
|
|
179
|
+
traces
|
|
169
180
|
};
|
|
170
|
-
workerTeardown = await worker.setup?.(setupContext);
|
|
181
|
+
workerTeardown = await traces.$("vitest.runtime.setup", { context }, () => worker.setup?.(setupContext));
|
|
171
182
|
send({
|
|
172
183
|
type: "started",
|
|
173
184
|
__vitest_worker_response__
|
|
@@ -204,10 +215,17 @@ function init(worker) {
|
|
|
204
215
|
}
|
|
205
216
|
isRunning = true;
|
|
206
217
|
try {
|
|
207
|
-
|
|
218
|
+
const tracesContext = traces.getContextFromCarrier(message.otelCarrier);
|
|
219
|
+
runPromise = traces.$("vitest.runtime.run", {
|
|
220
|
+
context: tracesContext,
|
|
221
|
+
attributes: {
|
|
222
|
+
"vitest.worker.specifications": traces.isEnabled() ? getFilesWithLocations(message.context.files) : [],
|
|
223
|
+
"vitest.worker.id": message.context.workerId
|
|
224
|
+
}
|
|
225
|
+
}, () => run({
|
|
208
226
|
...setupContext,
|
|
209
227
|
...message.context
|
|
210
|
-
}, worker).catch((error) => serializeError(error));
|
|
228
|
+
}, worker, traces).catch((error) => serializeError(error)));
|
|
211
229
|
send({
|
|
212
230
|
type: "testfileFinished",
|
|
213
231
|
__vitest_worker_response__,
|
|
@@ -242,10 +260,17 @@ function init(worker) {
|
|
|
242
260
|
}
|
|
243
261
|
isRunning = true;
|
|
244
262
|
try {
|
|
245
|
-
|
|
263
|
+
const tracesContext = traces.getContextFromCarrier(message.otelCarrier);
|
|
264
|
+
runPromise = traces.$("vitest.runtime.collect", {
|
|
265
|
+
context: tracesContext,
|
|
266
|
+
attributes: {
|
|
267
|
+
"vitest.worker.specifications": traces.isEnabled() ? getFilesWithLocations(message.context.files) : [],
|
|
268
|
+
"vitest.worker.id": message.context.workerId
|
|
269
|
+
}
|
|
270
|
+
}, () => collect({
|
|
246
271
|
...setupContext,
|
|
247
272
|
...message.context
|
|
248
|
-
}, worker).catch((error) => serializeError(error));
|
|
273
|
+
}, worker, traces).catch((error) => serializeError(error)));
|
|
249
274
|
send({
|
|
250
275
|
type: "testfileFinished",
|
|
251
276
|
__vitest_worker_response__,
|
|
@@ -260,8 +285,13 @@ function init(worker) {
|
|
|
260
285
|
case "stop":
|
|
261
286
|
await runPromise;
|
|
262
287
|
try {
|
|
263
|
-
const
|
|
264
|
-
await
|
|
288
|
+
const context = traces.getContextFromCarrier(message.otelCarrier);
|
|
289
|
+
const error = await traces.$("vitest.runtime.teardown", { context }, async () => {
|
|
290
|
+
const error = await teardown().catch((error) => serializeError(error));
|
|
291
|
+
await workerTeardown?.();
|
|
292
|
+
return error;
|
|
293
|
+
});
|
|
294
|
+
await traces.finish();
|
|
265
295
|
send({
|
|
266
296
|
type: "stopped",
|
|
267
297
|
error,
|
|
@@ -279,5 +309,13 @@ function init(worker) {
|
|
|
279
309
|
}
|
|
280
310
|
}
|
|
281
311
|
}
|
|
312
|
+
function getFilesWithLocations(files) {
|
|
313
|
+
return files.flatMap((file) => {
|
|
314
|
+
if (!file.testLocations) return file.filepath;
|
|
315
|
+
return file.testLocations.map((location) => {
|
|
316
|
+
return `${file}:${location}`;
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
}
|
|
282
320
|
|
|
283
321
|
export { init as i, loadEnvironment as l };
|
|
@@ -2,7 +2,8 @@ import * as _vitest_spy from '@vitest/spy';
|
|
|
2
2
|
import vm from 'node:vm';
|
|
3
3
|
import * as viteModuleRunner from 'vite/module-runner';
|
|
4
4
|
import { ModuleEvaluator, ModuleRunnerImportMeta, ModuleRunnerContext, EvaluatedModuleNode, FetchFunction, EvaluatedModules } from 'vite/module-runner';
|
|
5
|
-
import { R as RuntimeRPC, e as ResolveFunctionResult, W as WorkerGlobalState } from './worker.d.
|
|
5
|
+
import { R as RuntimeRPC, e as ResolveFunctionResult, W as WorkerGlobalState } from './worker.d.B_PZTrCQ.js';
|
|
6
|
+
import { T as Traces } from './traces.d.B8ukBJqA.js';
|
|
6
7
|
import { MockedModule, MockedModuleType } from '@vitest/mocker';
|
|
7
8
|
import { P as PendingSuiteMock, b as MockFactory, a as MockOptions } from './mocker.d.BE_2ls6u.js';
|
|
8
9
|
|
|
@@ -77,6 +78,7 @@ interface VitestModuleEvaluatorOptions {
|
|
|
77
78
|
getCurrentTestFilepath?: () => string | undefined;
|
|
78
79
|
compiledFunctionArgumentsNames?: string[];
|
|
79
80
|
compiledFunctionArgumentsValues?: unknown[];
|
|
81
|
+
traces?: Traces;
|
|
80
82
|
}
|
|
81
83
|
declare class VitestModuleEvaluator implements ModuleEvaluator {
|
|
82
84
|
private options;
|
|
@@ -87,10 +89,12 @@ declare class VitestModuleEvaluator implements ModuleEvaluator {
|
|
|
87
89
|
private compiledFunctionArgumentsValues;
|
|
88
90
|
private primitives;
|
|
89
91
|
private debug;
|
|
92
|
+
private _otel;
|
|
90
93
|
constructor(vmOptions?: VitestVmOptions | undefined, options?: VitestModuleEvaluatorOptions);
|
|
91
94
|
private convertIdToImportUrl;
|
|
92
95
|
runExternalModule(id: string): Promise<any>;
|
|
93
96
|
runInlinedModule(context: ModuleRunnerContext, code: string, module: Readonly<EvaluatedModuleNode>): Promise<any>;
|
|
97
|
+
private _runInlinedModule;
|
|
94
98
|
private createRequire;
|
|
95
99
|
private shouldInterop;
|
|
96
100
|
}
|
|
@@ -113,6 +117,7 @@ interface MockContext {
|
|
|
113
117
|
}
|
|
114
118
|
interface VitestMockerOptions {
|
|
115
119
|
context?: vm.Context;
|
|
120
|
+
traces: Traces;
|
|
116
121
|
spyModule?: typeof _vitest_spy;
|
|
117
122
|
root: string;
|
|
118
123
|
moduleDirectories: string[];
|
|
@@ -132,6 +137,7 @@ declare class VitestMocker {
|
|
|
132
137
|
private filterPublicKeys;
|
|
133
138
|
private registries;
|
|
134
139
|
private mockContext;
|
|
140
|
+
private _otel;
|
|
135
141
|
constructor(moduleRunner: VitestModuleRunner, options: VitestMockerOptions);
|
|
136
142
|
private get root();
|
|
137
143
|
private get evaluatedModules();
|
|
@@ -176,6 +182,7 @@ declare class VitestModuleRunner extends viteModuleRunner.ModuleRunner {
|
|
|
176
182
|
private vitestOptions;
|
|
177
183
|
mocker: VitestMocker;
|
|
178
184
|
moduleExecutionInfo: ModuleExecutionInfo;
|
|
185
|
+
private _otel;
|
|
179
186
|
constructor(vitestOptions: VitestModuleRunnerOptions);
|
|
180
187
|
import(rawId: string): Promise<any>;
|
|
181
188
|
fetchModule(url: string, importer?: string): Promise<EvaluatedModuleNode>;
|
|
@@ -188,6 +195,7 @@ interface VitestModuleRunnerOptions {
|
|
|
188
195
|
getWorkerState: () => WorkerGlobalState;
|
|
189
196
|
mocker?: VitestMocker;
|
|
190
197
|
vm?: VitestVmOptions;
|
|
198
|
+
traces?: Traces;
|
|
191
199
|
spyModule?: typeof _vitest_spy;
|
|
192
200
|
createImportMeta?: CreateImportMeta;
|
|
193
201
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { DevEnvironment } from 'vite';
|
|
2
|
+
import { V as Vitest, T as TestProject, b as TestProjectConfiguration } from './reporters.d.DgZLBdyd.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Generate a unique cache identifier.
|
|
6
|
+
*
|
|
7
|
+
* Return `false` to disable caching of the file.
|
|
8
|
+
* @experimental
|
|
9
|
+
*/
|
|
10
|
+
interface CacheKeyIdGenerator {
|
|
11
|
+
(context: CacheKeyIdGeneratorContext): string | undefined | null | false;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* @experimental
|
|
15
|
+
*/
|
|
16
|
+
interface CacheKeyIdGeneratorContext {
|
|
17
|
+
environment: DevEnvironment;
|
|
18
|
+
id: string;
|
|
19
|
+
sourceCode: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface VitestPluginContext {
|
|
23
|
+
vitest: Vitest;
|
|
24
|
+
project: TestProject;
|
|
25
|
+
injectTestProjects: (config: TestProjectConfiguration | TestProjectConfiguration[]) => Promise<TestProject[]>;
|
|
26
|
+
/**
|
|
27
|
+
* Define a generator that will be applied before hashing the cache key.
|
|
28
|
+
*
|
|
29
|
+
* Use this to make sure Vitest generates correct hash. It is a good idea
|
|
30
|
+
* to define this function if your plugin can be registered with different options.
|
|
31
|
+
*
|
|
32
|
+
* This is called only if `experimental.fsModuleCache` is defined.
|
|
33
|
+
* @experimental
|
|
34
|
+
*/
|
|
35
|
+
experimental_defineCacheKeyGenerator: (callback: CacheKeyIdGenerator) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type { CacheKeyIdGenerator as C, VitestPluginContext as V, CacheKeyIdGeneratorContext as a };
|