@depup/vitest 4.0.18-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +691 -0
- package/README.md +7 -0
- package/browser/context.d.ts +7 -0
- package/browser/context.js +20 -0
- package/config.d.ts +3 -0
- package/coverage.d.ts +1 -0
- package/dist/browser.d.ts +46 -0
- package/dist/browser.js +20 -0
- package/dist/chunks/_commonjsHelpers.D26ty3Ew.js +6 -0
- package/dist/chunks/base.CJ0Y4ePK.js +165 -0
- package/dist/chunks/benchmark.B3N2zMcH.js +40 -0
- package/dist/chunks/benchmark.d.DAaHLpsq.d.ts +24 -0
- package/dist/chunks/browser.d.ChKACdzH.d.ts +59 -0
- package/dist/chunks/cac.DVeoLl0M.js +1409 -0
- package/dist/chunks/cli-api.B7PN_QUv.js +13657 -0
- package/dist/chunks/config.d.Cy95HiCx.d.ts +210 -0
- package/dist/chunks/console.Cf-YriPC.js +146 -0
- package/dist/chunks/constants.D_Q9UYh-.js +36 -0
- package/dist/chunks/coverage.AVPTjMgw.js +3292 -0
- package/dist/chunks/coverage.D_JHT54q.js +25 -0
- package/dist/chunks/coverage.d.BZtK59WP.d.ts +37 -0
- package/dist/chunks/creator.DAmOKTvJ.js +673 -0
- package/dist/chunks/date.Bq6ZW5rf.js +73 -0
- package/dist/chunks/defaults.BOqNVLsY.js +74 -0
- package/dist/chunks/env.D4Lgay0q.js +8 -0
- package/dist/chunks/environment.d.CrsxCzP1.d.ts +29 -0
- package/dist/chunks/evaluatedModules.Dg1zASAC.js +17 -0
- package/dist/chunks/evaluatedModules.d.BxJ5omdx.d.ts +7 -0
- package/dist/chunks/git.Bm2pzPAa.js +71 -0
- package/dist/chunks/global.d.B15mdLcR.d.ts +99 -0
- package/dist/chunks/globals.DOayXfHP.js +30 -0
- package/dist/chunks/index.6Qv1eEA6.js +109 -0
- package/dist/chunks/index.C5r1PdPD.js +231 -0
- package/dist/chunks/index.Chj8NDwU.js +206 -0
- package/dist/chunks/index.CyBMJtT7.js +727 -0
- package/dist/chunks/index.D3XRDfWc.js +213 -0
- package/dist/chunks/index.D4KonVSU.js +6343 -0
- package/dist/chunks/index.M8mOzt4Y.js +3839 -0
- package/dist/chunks/index.Z5E_ObnR.js +37 -0
- package/dist/chunks/init-forks._y3TW739.js +41 -0
- package/dist/chunks/init-threads.DBO2kn-p.js +18 -0
- package/dist/chunks/init.B6MLFIaN.js +334 -0
- package/dist/chunks/inspector.CvyFGlXm.js +53 -0
- package/dist/chunks/modules.BJuCwlRJ.js +36 -0
- package/dist/chunks/node.Ce0vMQM7.js +14 -0
- package/dist/chunks/plugin.d.CtqpEehP.d.ts +38 -0
- package/dist/chunks/reporters.d.CWXNI2jG.d.ts +3271 -0
- package/dist/chunks/rpc.BoxB0q7B.js +76 -0
- package/dist/chunks/rpc.d.RH3apGEf.d.ts +64 -0
- package/dist/chunks/setup-common.Cm-kSBVi.js +60 -0
- package/dist/chunks/startModuleRunner.DEj0jb3e.js +861 -0
- package/dist/chunks/suite.d.BJWk38HB.d.ts +10 -0
- package/dist/chunks/test.B8ej_ZHS.js +254 -0
- package/dist/chunks/traces.CCmnQaNT.js +217 -0
- package/dist/chunks/traces.d.402V_yFI.d.ts +18 -0
- package/dist/chunks/utils.DvEY5TfP.js +52 -0
- package/dist/chunks/vi.2VT5v0um.js +3919 -0
- package/dist/chunks/vm.D3epNOPZ.js +744 -0
- package/dist/chunks/worker.d.Dyxm8DEL.d.ts +255 -0
- package/dist/cli.js +28 -0
- package/dist/config.cjs +94 -0
- package/dist/config.d.ts +104 -0
- package/dist/config.js +15 -0
- package/dist/coverage.d.ts +118 -0
- package/dist/coverage.js +23 -0
- package/dist/environments.d.ts +22 -0
- package/dist/environments.js +3 -0
- package/dist/index.d.ts +510 -0
- package/dist/index.js +20 -0
- package/dist/mocker.d.ts +1 -0
- package/dist/mocker.js +1 -0
- package/dist/module-evaluator.d.ts +124 -0
- package/dist/module-evaluator.js +343 -0
- package/dist/module-runner.js +17 -0
- package/dist/node.d.ts +251 -0
- package/dist/node.js +98 -0
- package/dist/path.js +7 -0
- package/dist/reporters.d.ts +27 -0
- package/dist/reporters.js +24 -0
- package/dist/runners.d.ts +50 -0
- package/dist/runners.js +19 -0
- package/dist/snapshot.d.ts +9 -0
- package/dist/snapshot.js +4 -0
- package/dist/spy.js +1 -0
- package/dist/suite.d.ts +5 -0
- package/dist/suite.js +6 -0
- package/dist/worker.d.ts +32 -0
- package/dist/worker.js +48 -0
- package/dist/workers/forks.js +54 -0
- package/dist/workers/runVmTests.js +95 -0
- package/dist/workers/threads.js +55 -0
- package/dist/workers/vmForks.js +36 -0
- package/dist/workers/vmThreads.js +37 -0
- package/environments.d.ts +1 -0
- package/globals.d.ts +20 -0
- package/import-meta.d.ts +5 -0
- package/importMeta.d.ts +4 -0
- package/index.cjs +5 -0
- package/index.d.cts +1 -0
- package/jsdom.d.ts +6 -0
- package/mocker.d.ts +1 -0
- package/node.d.ts +1 -0
- package/optional-types.d.ts +7 -0
- package/package.json +224 -0
- package/reporters.d.ts +1 -0
- package/runners.d.ts +1 -0
- package/snapshot.d.ts +1 -0
- package/suite.d.ts +1 -0
- package/suppress-warnings.cjs +21 -0
- package/vitest.mjs +2 -0
- package/worker.d.ts +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# vitest
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/vitest)
|
|
4
|
+
|
|
5
|
+
Next generation testing framework powered by Vite.
|
|
6
|
+
|
|
7
|
+
[GitHub](https://github.com/vitest-dev/vitest) | [Documentation](https://vitest.dev/)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// @ts-ignore -- @vitest/browser-playwright might not be installed
|
|
2
|
+
export * from '@vitest/browser-playwright/context'
|
|
3
|
+
// @ts-ignore -- @vitest/browser-webdriverio might not be installed
|
|
4
|
+
export * from '@vitest/browser-webdriverio/context'
|
|
5
|
+
// @ts-ignore -- @vitest/browser-preview might not be installed
|
|
6
|
+
export * from '@vitest/browser-preview/context'
|
|
7
|
+
export { BrowserCommands, FsOptions } from 'vitest/internal/browser'
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Vitest resolves "vitest/browser" as a virtual module instead
|
|
2
|
+
|
|
3
|
+
// fake exports for static analysis
|
|
4
|
+
export const page = null
|
|
5
|
+
export const server = null
|
|
6
|
+
export const userEvent = null
|
|
7
|
+
export const cdp = null
|
|
8
|
+
export const commands = null
|
|
9
|
+
export const locators = null
|
|
10
|
+
export const utils = null
|
|
11
|
+
|
|
12
|
+
const pool = globalThis.__vitest_worker__?.ctx?.pool
|
|
13
|
+
|
|
14
|
+
throw new Error(
|
|
15
|
+
// eslint-disable-next-line prefer-template
|
|
16
|
+
'vitest/browser can be imported only inside the Browser Mode. '
|
|
17
|
+
+ (pool
|
|
18
|
+
? `Your test is running in ${pool} pool. Make sure your regular tests are excluded from the "test.include" glob pattern.`
|
|
19
|
+
: 'Instead, it was imported outside of Vitest.'),
|
|
20
|
+
)
|
package/config.d.ts
ADDED
package/coverage.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/coverage.js'
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { a as SerializedCoverageConfig, S as SerializedConfig } from './chunks/config.d.Cy95HiCx.js';
|
|
2
|
+
import { R as RuntimeCoverageModuleLoader } from './chunks/coverage.d.BZtK59WP.js';
|
|
3
|
+
import { SerializedDiffOptions } from '@vitest/utils/diff';
|
|
4
|
+
export { O as OTELCarrier, T as Traces } from './chunks/traces.d.402V_yFI.js';
|
|
5
|
+
export { collectTests, startTests } from '@vitest/runner';
|
|
6
|
+
import * as _vitest_spy from '@vitest/spy';
|
|
7
|
+
export { _vitest_spy as SpyModule };
|
|
8
|
+
export { LoupeOptions, ParsedStack, StringifyOptions } from '@vitest/utils';
|
|
9
|
+
export { browserFormat, format, inspect, stringify } from '@vitest/utils/display';
|
|
10
|
+
export { processError } from '@vitest/utils/error';
|
|
11
|
+
export { getType } from '@vitest/utils/helpers';
|
|
12
|
+
export { DecodedMap, getOriginalPosition } from '@vitest/utils/source-map';
|
|
13
|
+
export { getSafeTimers, setSafeTimers } from '@vitest/utils/timers';
|
|
14
|
+
import '@vitest/pretty-format';
|
|
15
|
+
import '@vitest/snapshot';
|
|
16
|
+
|
|
17
|
+
declare function startCoverageInsideWorker(options: SerializedCoverageConfig | undefined, loader: RuntimeCoverageModuleLoader, runtimeOptions: {
|
|
18
|
+
isolate: boolean;
|
|
19
|
+
}): Promise<unknown>;
|
|
20
|
+
declare function takeCoverageInsideWorker(options: SerializedCoverageConfig | undefined, loader: RuntimeCoverageModuleLoader): Promise<unknown>;
|
|
21
|
+
declare function stopCoverageInsideWorker(options: SerializedCoverageConfig | undefined, loader: RuntimeCoverageModuleLoader, runtimeOptions: {
|
|
22
|
+
isolate: boolean;
|
|
23
|
+
}): Promise<unknown>;
|
|
24
|
+
|
|
25
|
+
interface PublicModuleRunner {
|
|
26
|
+
import: (id: string) => Promise<any>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare function setupCommonEnv(config: SerializedConfig): Promise<void>;
|
|
30
|
+
declare function loadDiffConfig(config: SerializedConfig, moduleRunner: PublicModuleRunner): Promise<SerializedDiffOptions | undefined>;
|
|
31
|
+
declare function loadSnapshotSerializers(config: SerializedConfig, moduleRunner: PublicModuleRunner): Promise<void>;
|
|
32
|
+
|
|
33
|
+
interface FsOptions {
|
|
34
|
+
encoding?: BufferEncoding;
|
|
35
|
+
flag?: string | number;
|
|
36
|
+
}
|
|
37
|
+
interface BrowserCommands {
|
|
38
|
+
readFile: (path: string, options?: BufferEncoding | FsOptions) => Promise<string>;
|
|
39
|
+
writeFile: (path: string, content: string, options?: BufferEncoding | (FsOptions & {
|
|
40
|
+
mode?: number | string;
|
|
41
|
+
})) => Promise<void>;
|
|
42
|
+
removeFile: (path: string) => Promise<void>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { loadDiffConfig, loadSnapshotSerializers, setupCommonEnv, startCoverageInsideWorker, stopCoverageInsideWorker, takeCoverageInsideWorker };
|
|
46
|
+
export type { BrowserCommands, FsOptions };
|
package/dist/browser.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export { l as loadDiffConfig, b as loadSnapshotSerializers, c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker, t as takeCoverageInsideWorker } from './chunks/setup-common.Cm-kSBVi.js';
|
|
2
|
+
export { T as Traces } from './chunks/traces.CCmnQaNT.js';
|
|
3
|
+
export { collectTests, startTests } from '@vitest/runner';
|
|
4
|
+
import * as spyModule from '@vitest/spy';
|
|
5
|
+
export { spyModule as SpyModule };
|
|
6
|
+
export { browserFormat, format, inspect, stringify } from '@vitest/utils/display';
|
|
7
|
+
export { processError } from '@vitest/utils/error';
|
|
8
|
+
export { getType } from '@vitest/utils/helpers';
|
|
9
|
+
export { DecodedMap, getOriginalPosition } from '@vitest/utils/source-map';
|
|
10
|
+
export { getSafeTimers, setSafeTimers } from '@vitest/utils/timers';
|
|
11
|
+
import './chunks/coverage.D_JHT54q.js';
|
|
12
|
+
import '@vitest/snapshot';
|
|
13
|
+
import './chunks/utils.DvEY5TfP.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
const __INTERNAL = { _extendedMethods: /* @__PURE__ */ new Set() };
|
|
19
|
+
|
|
20
|
+
export { __INTERNAL };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
2
|
+
function getDefaultExportFromCjs(x) {
|
|
3
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export { commonjsGlobal as c, getDefaultExportFromCjs as g };
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { runInThisContext } from 'node:vm';
|
|
2
|
+
import * as spyModule from '@vitest/spy';
|
|
3
|
+
import { r as resolveTestRunner, a as resolveSnapshotEnvironment, s as setupChaiConfig } from './index.6Qv1eEA6.js';
|
|
4
|
+
import { l as loadEnvironment, e as emitModuleRunner } from './init.B6MLFIaN.js';
|
|
5
|
+
import { V as VitestEvaluatedModules } from './evaluatedModules.Dg1zASAC.js';
|
|
6
|
+
import { s as startVitestModuleRunner, c as createNodeImportMeta } from './startModuleRunner.DEj0jb3e.js';
|
|
7
|
+
import { performance as performance$1 } from 'node:perf_hooks';
|
|
8
|
+
import { startTests, collectTests } from '@vitest/runner';
|
|
9
|
+
import { c as setupCommonEnv, s as startCoverageInsideWorker, a as stopCoverageInsideWorker } from './setup-common.Cm-kSBVi.js';
|
|
10
|
+
import { g as globalExpect, v as vi } from './vi.2VT5v0um.js';
|
|
11
|
+
import { c as closeInspector } from './inspector.CvyFGlXm.js';
|
|
12
|
+
import { createRequire } from 'node:module';
|
|
13
|
+
import timers from 'node:timers';
|
|
14
|
+
import timersPromises from 'node:timers/promises';
|
|
15
|
+
import util from 'node:util';
|
|
16
|
+
import { KNOWN_ASSET_TYPES } from '@vitest/utils/constants';
|
|
17
|
+
import { i as index } from './index.Z5E_ObnR.js';
|
|
18
|
+
import { g as getWorkerState, r as resetModules, p as provideWorkerState } from './utils.DvEY5TfP.js';
|
|
19
|
+
|
|
20
|
+
// this should only be used in Node
|
|
21
|
+
let globalSetup = false;
|
|
22
|
+
async function setupGlobalEnv(config, environment) {
|
|
23
|
+
await setupCommonEnv(config);
|
|
24
|
+
Object.defineProperty(globalThis, "__vitest_index__", {
|
|
25
|
+
value: index,
|
|
26
|
+
enumerable: false
|
|
27
|
+
});
|
|
28
|
+
globalExpect.setState({ environment: environment.name });
|
|
29
|
+
if (globalSetup) return;
|
|
30
|
+
globalSetup = true;
|
|
31
|
+
if ((environment.viteEnvironment || environment.name) === "client") {
|
|
32
|
+
const _require = createRequire(import.meta.url);
|
|
33
|
+
// always mock "required" `css` files, because we cannot process them
|
|
34
|
+
_require.extensions[".css"] = resolveCss;
|
|
35
|
+
_require.extensions[".scss"] = resolveCss;
|
|
36
|
+
_require.extensions[".sass"] = resolveCss;
|
|
37
|
+
_require.extensions[".less"] = resolveCss;
|
|
38
|
+
// since we are using Vite, we can assume how these will be resolved
|
|
39
|
+
KNOWN_ASSET_TYPES.forEach((type) => {
|
|
40
|
+
_require.extensions[`.${type}`] = resolveAsset;
|
|
41
|
+
});
|
|
42
|
+
process.env.SSR = "";
|
|
43
|
+
} else process.env.SSR = "1";
|
|
44
|
+
// @ts-expect-error not typed global for patched timers
|
|
45
|
+
globalThis.__vitest_required__ = {
|
|
46
|
+
util,
|
|
47
|
+
timers,
|
|
48
|
+
timersPromises
|
|
49
|
+
};
|
|
50
|
+
if (!config.disableConsoleIntercept) await setupConsoleLogSpy();
|
|
51
|
+
}
|
|
52
|
+
function resolveCss(mod) {
|
|
53
|
+
mod.exports = "";
|
|
54
|
+
}
|
|
55
|
+
function resolveAsset(mod, url) {
|
|
56
|
+
mod.exports = url;
|
|
57
|
+
}
|
|
58
|
+
async function setupConsoleLogSpy() {
|
|
59
|
+
const { createCustomConsole } = await import('./console.Cf-YriPC.js');
|
|
60
|
+
globalThis.console = createCustomConsole();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// browser shouldn't call this!
|
|
64
|
+
async function run(method, files, config, moduleRunner, environment, traces) {
|
|
65
|
+
const workerState = getWorkerState();
|
|
66
|
+
const [testRunner] = await Promise.all([
|
|
67
|
+
traces.$("vitest.runtime.runner", () => resolveTestRunner(config, moduleRunner, traces)),
|
|
68
|
+
traces.$("vitest.runtime.global_env", () => setupGlobalEnv(config, environment)),
|
|
69
|
+
traces.$("vitest.runtime.coverage.start", () => startCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate })),
|
|
70
|
+
traces.$("vitest.runtime.snapshot.environment", async () => {
|
|
71
|
+
if (!workerState.config.snapshotOptions.snapshotEnvironment) workerState.config.snapshotOptions.snapshotEnvironment = await resolveSnapshotEnvironment(config, moduleRunner);
|
|
72
|
+
})
|
|
73
|
+
]);
|
|
74
|
+
workerState.onCancel((reason) => {
|
|
75
|
+
closeInspector(config);
|
|
76
|
+
testRunner.cancel?.(reason);
|
|
77
|
+
});
|
|
78
|
+
workerState.durations.prepare = performance$1.now() - workerState.durations.prepare;
|
|
79
|
+
await traces.$(`vitest.test.runner.${method}`, async () => {
|
|
80
|
+
for (const file of files) {
|
|
81
|
+
if (config.isolate) {
|
|
82
|
+
moduleRunner.mocker.reset();
|
|
83
|
+
resetModules(workerState.evaluatedModules, true);
|
|
84
|
+
}
|
|
85
|
+
workerState.filepath = file.filepath;
|
|
86
|
+
if (method === "run") await traces.$(`vitest.test.runner.${method}.module`, { attributes: { "code.file.path": file.filepath } }, () => startTests([file], testRunner));
|
|
87
|
+
else await traces.$(`vitest.test.runner.${method}.module`, { attributes: { "code.file.path": file.filepath } }, () => collectTests([file], testRunner));
|
|
88
|
+
// reset after tests, because user might call `vi.setConfig` in setupFile
|
|
89
|
+
vi.resetConfig();
|
|
90
|
+
// mocks should not affect different files
|
|
91
|
+
vi.restoreAllMocks();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
await traces.$("vitest.runtime.coverage.stop", () => stopCoverageInsideWorker(config.coverage, moduleRunner, { isolate: config.isolate }));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
let _moduleRunner;
|
|
98
|
+
const evaluatedModules = new VitestEvaluatedModules();
|
|
99
|
+
const moduleExecutionInfo = /* @__PURE__ */ new Map();
|
|
100
|
+
function startModuleRunner(options) {
|
|
101
|
+
if (_moduleRunner) return _moduleRunner;
|
|
102
|
+
_moduleRunner = startVitestModuleRunner(options);
|
|
103
|
+
return _moduleRunner;
|
|
104
|
+
}
|
|
105
|
+
let _currentEnvironment;
|
|
106
|
+
let _environmentTime;
|
|
107
|
+
/** @experimental */
|
|
108
|
+
async function setupEnvironment(context) {
|
|
109
|
+
const startTime = performance.now();
|
|
110
|
+
const { environment: { name: environmentName, options: environmentOptions }, rpc, config } = context;
|
|
111
|
+
// we could load @vite/env, but it would take ~8ms, while this takes ~0,02ms
|
|
112
|
+
if (context.config.serializedDefines) try {
|
|
113
|
+
runInThisContext(`(() =>{\n${context.config.serializedDefines}})()`, {
|
|
114
|
+
lineOffset: 1,
|
|
115
|
+
filename: "virtual:load-defines.js"
|
|
116
|
+
});
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw new Error(`Failed to load custom "defines": ${error.message}`);
|
|
119
|
+
}
|
|
120
|
+
const otel = context.traces;
|
|
121
|
+
const { environment, loader } = await loadEnvironment(environmentName, config.root, rpc, otel);
|
|
122
|
+
_currentEnvironment = environment;
|
|
123
|
+
const env = await otel.$("vitest.runtime.environment.setup", { attributes: {
|
|
124
|
+
"vitest.environment": environment.name,
|
|
125
|
+
"vitest.environment.vite_environment": environment.viteEnvironment || environment.name
|
|
126
|
+
} }, () => environment.setup(globalThis, environmentOptions || config.environmentOptions || {}));
|
|
127
|
+
_environmentTime = performance.now() - startTime;
|
|
128
|
+
if (config.chaiConfig) setupChaiConfig(config.chaiConfig);
|
|
129
|
+
return async () => {
|
|
130
|
+
await otel.$("vitest.runtime.environment.teardown", () => env.teardown(globalThis));
|
|
131
|
+
await loader?.close();
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/** @experimental */
|
|
135
|
+
async function runBaseTests(method, state, traces) {
|
|
136
|
+
const { ctx } = state;
|
|
137
|
+
state.environment = _currentEnvironment;
|
|
138
|
+
state.durations.environment = _environmentTime;
|
|
139
|
+
// state has new context, but we want to reuse existing ones
|
|
140
|
+
state.evaluatedModules = evaluatedModules;
|
|
141
|
+
state.moduleExecutionInfo = moduleExecutionInfo;
|
|
142
|
+
provideWorkerState(globalThis, state);
|
|
143
|
+
if (ctx.invalidates) ctx.invalidates.forEach((filepath) => {
|
|
144
|
+
(state.evaluatedModules.fileToModulesMap.get(filepath) || []).forEach((module) => {
|
|
145
|
+
state.evaluatedModules.invalidateModule(module);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
ctx.files.forEach((i) => {
|
|
149
|
+
const filepath = i.filepath;
|
|
150
|
+
(state.evaluatedModules.fileToModulesMap.get(filepath) || []).forEach((module) => {
|
|
151
|
+
state.evaluatedModules.invalidateModule(module);
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
const moduleRunner = startModuleRunner({
|
|
155
|
+
state,
|
|
156
|
+
evaluatedModules: state.evaluatedModules,
|
|
157
|
+
spyModule,
|
|
158
|
+
createImportMeta: createNodeImportMeta,
|
|
159
|
+
traces
|
|
160
|
+
});
|
|
161
|
+
emitModuleRunner(moduleRunner);
|
|
162
|
+
await run(method, ctx.files, ctx.config, moduleRunner, _currentEnvironment, traces);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export { runBaseTests as r, setupEnvironment as s };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { getCurrentSuite } from '@vitest/runner';
|
|
2
|
+
import { createChainable } from '@vitest/runner/utils';
|
|
3
|
+
import { noop } from '@vitest/utils/helpers';
|
|
4
|
+
import { g as getWorkerState } from './utils.DvEY5TfP.js';
|
|
5
|
+
|
|
6
|
+
const benchFns = /* @__PURE__ */ new WeakMap();
|
|
7
|
+
const benchOptsMap = /* @__PURE__ */ new WeakMap();
|
|
8
|
+
function getBenchOptions(key) {
|
|
9
|
+
return benchOptsMap.get(key);
|
|
10
|
+
}
|
|
11
|
+
function getBenchFn(key) {
|
|
12
|
+
return benchFns.get(key);
|
|
13
|
+
}
|
|
14
|
+
const bench = createBenchmark(function(name, fn = noop, options = {}) {
|
|
15
|
+
if (getWorkerState().config.mode !== "benchmark") throw new Error("`bench()` is only available in benchmark mode.");
|
|
16
|
+
const task = getCurrentSuite().task(formatName(name), {
|
|
17
|
+
...this,
|
|
18
|
+
meta: { benchmark: true }
|
|
19
|
+
});
|
|
20
|
+
benchFns.set(task, fn);
|
|
21
|
+
benchOptsMap.set(task, options);
|
|
22
|
+
// vitest runner sets mode to `todo` if handler is not passed down
|
|
23
|
+
// but we store handler separetly
|
|
24
|
+
if (!this.todo && task.mode === "todo") task.mode = "run";
|
|
25
|
+
});
|
|
26
|
+
function createBenchmark(fn) {
|
|
27
|
+
const benchmark = createChainable([
|
|
28
|
+
"skip",
|
|
29
|
+
"only",
|
|
30
|
+
"todo"
|
|
31
|
+
], fn);
|
|
32
|
+
benchmark.skipIf = (condition) => condition ? benchmark.skip : benchmark;
|
|
33
|
+
benchmark.runIf = (condition) => condition ? benchmark : benchmark.skip;
|
|
34
|
+
return benchmark;
|
|
35
|
+
}
|
|
36
|
+
function formatName(name) {
|
|
37
|
+
return typeof name === "string" ? name : typeof name === "function" ? name.name || "<anonymous>" : String(name);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { getBenchOptions as a, bench as b, getBenchFn as g };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Test } from '@vitest/runner';
|
|
2
|
+
import { ChainableFunction } from '@vitest/runner/utils';
|
|
3
|
+
import { TaskResult, Bench, Options } from 'tinybench';
|
|
4
|
+
|
|
5
|
+
interface Benchmark extends Test {
|
|
6
|
+
meta: {
|
|
7
|
+
benchmark: true;
|
|
8
|
+
result?: TaskResult;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
interface BenchmarkResult extends TaskResult {
|
|
12
|
+
name: string;
|
|
13
|
+
rank: number;
|
|
14
|
+
sampleCount: number;
|
|
15
|
+
median: number;
|
|
16
|
+
}
|
|
17
|
+
type BenchFunction = (this: Bench) => Promise<void> | void;
|
|
18
|
+
type ChainableBenchmarkAPI = ChainableFunction<"skip" | "only" | "todo", (name: string | Function, fn?: BenchFunction, options?: Options) => void>;
|
|
19
|
+
type BenchmarkAPI = ChainableBenchmarkAPI & {
|
|
20
|
+
skipIf: (condition: any) => ChainableBenchmarkAPI;
|
|
21
|
+
runIf: (condition: any) => ChainableBenchmarkAPI;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type { BenchmarkResult as B, BenchFunction as a, Benchmark as b, BenchmarkAPI as c };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { FileSpecification } from '@vitest/runner';
|
|
2
|
+
import { O as OTELCarrier } from './traces.d.402V_yFI.js';
|
|
3
|
+
import { T as TestExecutionMethod } from './worker.d.Dyxm8DEL.js';
|
|
4
|
+
|
|
5
|
+
type SerializedTestSpecification = [project: {
|
|
6
|
+
name: string | undefined;
|
|
7
|
+
root: string;
|
|
8
|
+
}, file: string, options: {
|
|
9
|
+
pool: string;
|
|
10
|
+
testLines?: number[] | undefined;
|
|
11
|
+
}];
|
|
12
|
+
|
|
13
|
+
interface ModuleDefinitionLocation {
|
|
14
|
+
line: number;
|
|
15
|
+
column: number;
|
|
16
|
+
}
|
|
17
|
+
interface SourceModuleLocations {
|
|
18
|
+
modules: ModuleDefinitionDiagnostic[];
|
|
19
|
+
untracked: ModuleDefinitionDiagnostic[];
|
|
20
|
+
}
|
|
21
|
+
interface ModuleDefinitionDiagnostic {
|
|
22
|
+
start: ModuleDefinitionLocation;
|
|
23
|
+
end: ModuleDefinitionLocation;
|
|
24
|
+
startIndex: number;
|
|
25
|
+
endIndex: number;
|
|
26
|
+
rawUrl: string;
|
|
27
|
+
resolvedUrl: string;
|
|
28
|
+
resolvedId: string;
|
|
29
|
+
}
|
|
30
|
+
interface ModuleDefinitionDurationsDiagnostic extends ModuleDefinitionDiagnostic {
|
|
31
|
+
selfTime: number;
|
|
32
|
+
totalTime: number;
|
|
33
|
+
transformTime?: number;
|
|
34
|
+
external?: boolean;
|
|
35
|
+
importer?: string;
|
|
36
|
+
}
|
|
37
|
+
interface UntrackedModuleDefinitionDiagnostic {
|
|
38
|
+
url: string;
|
|
39
|
+
resolvedId: string;
|
|
40
|
+
resolvedUrl: string;
|
|
41
|
+
selfTime: number;
|
|
42
|
+
totalTime: number;
|
|
43
|
+
transformTime?: number;
|
|
44
|
+
external?: boolean;
|
|
45
|
+
importer?: string;
|
|
46
|
+
}
|
|
47
|
+
interface SourceModuleDiagnostic {
|
|
48
|
+
modules: ModuleDefinitionDurationsDiagnostic[];
|
|
49
|
+
untrackedModules: UntrackedModuleDefinitionDiagnostic[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface BrowserTesterOptions {
|
|
53
|
+
method: TestExecutionMethod;
|
|
54
|
+
files: FileSpecification[];
|
|
55
|
+
providedContext: string;
|
|
56
|
+
otelCarrier?: OTELCarrier;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export type { BrowserTesterOptions as B, ModuleDefinitionDurationsDiagnostic as M, SerializedTestSpecification as S, UntrackedModuleDefinitionDiagnostic as U, ModuleDefinitionDiagnostic as a, ModuleDefinitionLocation as b, SourceModuleDiagnostic as c, SourceModuleLocations as d };
|