vitest 4.0.0-beta.13 → 4.0.0-beta.14

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.
Files changed (31) hide show
  1. package/browser/context.d.ts +6 -0
  2. package/browser/context.js +20 -0
  3. package/dist/browser.d.ts +3 -3
  4. package/dist/browser.js +7 -0
  5. package/dist/chunks/{browser.d.D9YV3JvA.d.ts → browser.d.CM1rjKAX.d.ts} +1 -2
  6. package/dist/chunks/{cac.BBtYKH7y.js → cac.DOq1v3N-.js} +7 -7
  7. package/dist/chunks/{cli-api.CeakdBUN.js → cli-api.CD_0qYMh.js} +33 -64
  8. package/dist/chunks/{coverage.DabP7UTQ.js → coverage.3htTSxXZ.js} +201 -20
  9. package/dist/chunks/{creator.DfXDsUyL.js → creator.Daoa5_gR.js} +2 -28
  10. package/dist/chunks/environment.d.CrsxCzP1.d.ts +29 -0
  11. package/dist/chunks/{global.d.BcFPD2LN.d.ts → global.d.YxmikCHu.d.ts} +1 -1
  12. package/dist/chunks/{index.uLUz1RDt.js → index.01uBqPwR.js} +1 -1
  13. package/dist/chunks/{index.CHrBLuEH.js → index.DehVUBn4.js} +2 -109
  14. package/dist/chunks/{moduleRunner.d.CeYc7nZ0.d.ts → moduleRunner.d.CTZUg34g.d.ts} +1 -2
  15. package/dist/chunks/{plugin.d.COyglhiI.d.ts → plugin.d.DvkMsuLk.d.ts} +1 -1
  16. package/dist/chunks/{reporters.d.xGvTJYG3.d.ts → reporters.d.DhY37FSs.d.ts} +71 -37
  17. package/dist/chunks/{typechecker.BfOQ86_a.js → typechecker.DsKAhua5.js} +108 -1
  18. package/dist/chunks/{worker.d.buwuBpBt.d.ts → worker.d.B8jq7m7O.d.ts} +38 -2
  19. package/dist/cli.js +3 -3
  20. package/dist/config.d.ts +9 -8
  21. package/dist/coverage.d.ts +6 -5
  22. package/dist/coverage.js +6 -5
  23. package/dist/environments.d.ts +3 -2
  24. package/dist/index.d.ts +8 -8
  25. package/dist/module-evaluator.d.ts +4 -3
  26. package/dist/node.d.ts +9 -8
  27. package/dist/node.js +20 -20
  28. package/dist/reporters.d.ts +10 -9
  29. package/dist/reporters.js +4 -4
  30. package/package.json +26 -12
  31. package/dist/chunks/environment.d.BsToaxti.d.ts +0 -65
@@ -330,23 +330,6 @@ function getBrowserNames(provider) {
330
330
  ];
331
331
  }
332
332
  }
333
- function getProviderPackageNames(provider) {
334
- switch (provider) {
335
- case "webdriverio": return {
336
- types: "@vitest/browser/providers/webdriverio",
337
- pkg: "webdriverio"
338
- };
339
- case "playwright": return {
340
- types: "@vitest/browser/providers/playwright",
341
- pkg: "playwright"
342
- };
343
- case "preview": return {
344
- types: "@vitest/browser/matchers",
345
- pkg: null
346
- };
347
- }
348
- throw new Error(`Unsupported provider: ${provider}`);
349
- }
350
333
  function getFramework() {
351
334
  return [
352
335
  {
@@ -422,11 +405,6 @@ function getFrameworkPluginPackage(framework) {
422
405
  }
423
406
  return null;
424
407
  }
425
- async function updateTsConfig(type) {
426
- if (type == null) return;
427
- const msg = `Add "${c.bold(type)}" to your tsconfig.json "${c.bold("compilerOptions.types")}" field to have better intellisense support.`;
428
- log(), log(c.yellow("◼"), c.yellow(msg));
429
- }
430
408
  function getLanguageOptions() {
431
409
  return [{
432
410
  title: "TypeScript",
@@ -500,7 +478,7 @@ function getFrameworkImportInfo(framework) {
500
478
  async function generateFrameworkConfigFile(options) {
501
479
  const { importName, isNamedExport } = getFrameworkImportInfo(options.framework), frameworkImport = isNamedExport ? `import { ${importName} } from '${options.frameworkPlugin}'` : `import ${importName} from '${options.frameworkPlugin}'`, configContent = [
502
480
  `import { defineConfig } from 'vitest/config'`,
503
- `import { ${options.provider} } from '@vitest/browser/providers/${options.provider}'`,
481
+ `import { ${options.provider} } from '@vitest/browser-${options.provider}'`,
504
482
  options.frameworkPlugin ? frameworkImport : null,
505
483
  ``,
506
484
  "export default defineConfig({",
@@ -593,10 +571,8 @@ async function create() {
593
571
  message: `Install Playwright browsers (can be done manually via 'pnpm exec playwright install')?`
594
572
  }));
595
573
  if (installPlaywright == null) return fail();
596
- const dependenciesToInstall = ["@vitest/browser"], frameworkPackage = getFrameworkTestPackage(framework);
574
+ const dependenciesToInstall = [`@vitest/browser-${provider}`], frameworkPackage = getFrameworkTestPackage(framework);
597
575
  if (frameworkPackage) dependenciesToInstall.push(frameworkPackage);
598
- const providerPkg = getProviderPackageNames(provider);
599
- if (providerPkg.pkg) dependenciesToInstall.push(providerPkg.pkg);
600
576
  const frameworkPlugin = getFrameworkPluginPackage(framework);
601
577
  if (frameworkPlugin) dependenciesToInstall.push(frameworkPlugin);
602
578
  const pkgManager = await detectPackageManager();
@@ -644,8 +620,6 @@ async function create() {
644
620
  "inherit"
645
621
  ] } });
646
622
  }
647
- // TODO: can we do this ourselves?
648
- if (lang === "ts") await updateTsConfig(providerPkg?.types);
649
623
  log();
650
624
  const exampleTestFile = await generateExampleFiles(framework, lang);
651
625
  log(c.green("✔"), "Created example test file in", c.bold(relative(process.cwd(), exampleTestFile))), log(c.dim(" You can safely delete this file once you have written your own tests.")), log(), log(c.cyan("◼"), "All done! Run your tests with", c.bold(getRunScript(pkgManager)));
@@ -0,0 +1,29 @@
1
+ import { Awaitable } from '@vitest/utils';
2
+
3
+ interface EnvironmentReturn {
4
+ teardown: (global: any) => Awaitable<void>;
5
+ }
6
+ interface VmEnvironmentReturn {
7
+ getVmContext: () => {
8
+ [key: string]: any;
9
+ };
10
+ teardown: () => Awaitable<void>;
11
+ }
12
+ interface Environment {
13
+ name: string;
14
+ /**
15
+ * @deprecated use `viteEnvironment` instead. Uses `name` by default
16
+ */
17
+ transformMode?: "web" | "ssr";
18
+ /**
19
+ * Environment initiated by the Vite server. It is usually available
20
+ * as `vite.server.environments.${name}`.
21
+ *
22
+ * By default, fallbacks to `name`.
23
+ */
24
+ viteEnvironment?: "client" | "ssr" | ({} & string);
25
+ setupVM?: (options: Record<string, any>) => Awaitable<VmEnvironmentReturn>;
26
+ setup: (global: any, options: Record<string, any>) => Awaitable<EnvironmentReturn>;
27
+ }
28
+
29
+ export type { Environment as E, VmEnvironmentReturn as V, EnvironmentReturn as a };
@@ -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 './environment.d.BsToaxti.js';
5
+ import { U as UserConsoleLog } from './worker.d.B8jq7m7O.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.CHrBLuEH.js';
5
+ import { g as getStateSymbol, t as truncateString, F as F_RIGHT, D as DefaultReporter, f as formatProjectName, s as separator } from './index.DehVUBn4.js';
6
6
  import { stripVTControlCharacters } from 'node:util';
7
7
  import { notNullish } from '@vitest/utils/helpers';
8
8
 
@@ -1,7 +1,7 @@
1
1
  import { existsSync, readFileSync, promises } from 'node:fs';
2
2
  import { mkdir, writeFile, readdir, stat, readFile } from 'node:fs/promises';
3
+ import { g as getOutputFile, s as stringify, p as parse, h as hasFailedSnapshot, T as TypeCheckError } from './typechecker.DsKAhua5.js';
3
4
  import { resolve, dirname, isAbsolute, relative, basename, normalize } from 'pathe';
4
- import { g as getOutputFile, h as hasFailedSnapshot, T as TypeCheckError } from './typechecker.BfOQ86_a.js';
5
5
  import { performance as performance$1 } from 'node:perf_hooks';
6
6
  import { getTestName, hasFailed, getTests, getSuites, getTasks, getFullName } from '@vitest/runner/utils';
7
7
  import { slash, toArray, isPrimitive } from '@vitest/utils/helpers';
@@ -16,113 +16,6 @@ import { positionToOffset, lineSplitRE } from '@vitest/utils/offset';
16
16
  import { createRequire } from 'node:module';
17
17
  import { hostname } from 'node:os';
18
18
 
19
- /// <reference types="../types/index.d.ts" />
20
-
21
- // (c) 2020-present Andrea Giammarchi
22
-
23
- const {parse: $parse, stringify: $stringify} = JSON;
24
- const {keys} = Object;
25
-
26
- const Primitive = String; // it could be Number
27
- const primitive = 'string'; // it could be 'number'
28
-
29
- const ignore = {};
30
- const object = 'object';
31
-
32
- const noop = (_, value) => value;
33
-
34
- const primitives = value => (
35
- value instanceof Primitive ? Primitive(value) : value
36
- );
37
-
38
- const Primitives = (_, value) => (
39
- typeof value === primitive ? new Primitive(value) : value
40
- );
41
-
42
- const revive = (input, parsed, output, $) => {
43
- const lazy = [];
44
- for (let ke = keys(output), {length} = ke, y = 0; y < length; y++) {
45
- const k = ke[y];
46
- const value = output[k];
47
- if (value instanceof Primitive) {
48
- const tmp = input[value];
49
- if (typeof tmp === object && !parsed.has(tmp)) {
50
- parsed.add(tmp);
51
- output[k] = ignore;
52
- lazy.push({k, a: [input, parsed, tmp, $]});
53
- }
54
- else
55
- output[k] = $.call(output, k, tmp);
56
- }
57
- else if (output[k] !== ignore)
58
- output[k] = $.call(output, k, value);
59
- }
60
- for (let {length} = lazy, i = 0; i < length; i++) {
61
- const {k, a} = lazy[i];
62
- output[k] = $.call(output, k, revive.apply(null, a));
63
- }
64
- return output;
65
- };
66
-
67
- const set = (known, input, value) => {
68
- const index = Primitive(input.push(value) - 1);
69
- known.set(value, index);
70
- return index;
71
- };
72
-
73
- /**
74
- * Converts a specialized flatted string into a JS value.
75
- * @param {string} text
76
- * @param {(this: any, key: string, value: any) => any} [reviver]
77
- * @returns {any}
78
- */
79
- const parse = (text, reviver) => {
80
- const input = $parse(text, Primitives).map(primitives);
81
- const value = input[0];
82
- const $ = reviver || noop;
83
- const tmp = typeof value === object && value ?
84
- revive(input, new Set, value, $) :
85
- value;
86
- return $.call({'': tmp}, '', tmp);
87
- };
88
-
89
- /**
90
- * Converts a JS value into a specialized flatted string.
91
- * @param {any} value
92
- * @param {((this: any, key: string, value: any) => any) | (string | number)[] | null | undefined} [replacer]
93
- * @param {string | number | undefined} [space]
94
- * @returns {string}
95
- */
96
- const stringify = (value, replacer, space) => {
97
- const $ = replacer && typeof replacer === object ?
98
- (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
99
- (replacer || noop);
100
- const known = new Map;
101
- const input = [];
102
- const output = [];
103
- let i = +set(known, input, $.call({'': value}, '', value));
104
- let firstRun = !i;
105
- while (i < input.length) {
106
- firstRun = true;
107
- output[i] = $stringify(input[i++], replace, space);
108
- }
109
- return '[' + output.join(',') + ']';
110
- function replace(key, value) {
111
- if (firstRun) {
112
- firstRun = !firstRun;
113
- return value;
114
- }
115
- const after = $.call(this, key, value);
116
- switch (typeof after) {
117
- case object:
118
- if (after === null) return after;
119
- case primitive:
120
- return known.get(after) || set(known, input, after);
121
- }
122
- return after;
123
- }
124
- };
125
-
126
19
  class BlobReporter {
127
20
  start = 0;
128
21
  ctx;
@@ -1840,4 +1733,4 @@ const ReportersMap = {
1840
1733
  "github-actions": GithubActionsReporter
1841
1734
  };
1842
1735
 
1843
- export { BlobReporter as B, DefaultReporter as D, F_RIGHT as F, GithubActionsReporter as G, HangingProcessReporter as H, JsonReporter as J, ReportersMap as R, TapFlatReporter as T, VerboseReporter as V, DotReporter as a, JUnitReporter as b, TapReporter as c, stringify as d, printError as e, formatProjectName as f, getStateSymbol as g, errorBanner as h, divider as i, generateCodeFrame as j, parse as p, readBlobs as r, separator as s, truncateString as t, utils as u, withLabel as w };
1736
+ export { BlobReporter as B, DefaultReporter as D, F_RIGHT as F, GithubActionsReporter as G, HangingProcessReporter as H, JsonReporter as J, ReportersMap as R, TapFlatReporter as T, VerboseReporter as V, DotReporter as a, JUnitReporter as b, TapReporter as c, divider as d, errorBanner as e, formatProjectName as f, getStateSymbol as g, generateCodeFrame as h, printError as p, readBlobs as r, separator as s, truncateString as t, utils as u, withLabel as w };
@@ -2,8 +2,7 @@ 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 { a as RuntimeRPC, W as WorkerGlobalState } from './worker.d.buwuBpBt.js';
6
- import { R as ResolveFunctionResult } from './environment.d.BsToaxti.js';
5
+ import { a as RuntimeRPC, c as ResolveFunctionResult, W as WorkerGlobalState } from './worker.d.B8jq7m7O.js';
7
6
  import { MockedModule, MockedModuleType } from '@vitest/mocker';
8
7
  import { P as PendingSuiteMock, b as MockFactory, a as MockOptions } from './mocker.d.BE_2ls6u.js';
9
8
 
@@ -1,4 +1,4 @@
1
- import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.xGvTJYG3.js';
1
+ import { V as Vitest, T as TestProject, a as TestProjectConfiguration } from './reporters.d.DhY37FSs.js';
2
2
 
3
3
  interface VitestPluginContext {
4
4
  vitest: Vitest;
@@ -1,12 +1,13 @@
1
1
  import { CancelReason, TaskMeta, Suite, File, TestAnnotation, ImportDuration, Test, Task, TaskResultPack, SequenceSetupFiles, SequenceHooks } from '@vitest/runner';
2
- import { Awaitable, ParsedStack, TestError, SerializedError, Arrayable as Arrayable$1 } from '@vitest/utils';
3
- import { P as ProvidedContext, c as Arrayable, A as AfterSuiteRunMeta, U as UserConsoleLog, b as Awaitable$1, L as LabelColor } from './environment.d.BsToaxti.js';
2
+ import { Awaitable, ParsedStack, TestError, SerializedError, Arrayable } from '@vitest/utils';
3
+ import { P as ProvidedContext, A as AfterSuiteRunMeta, U as UserConsoleLog, L as LabelColor } from './worker.d.B8jq7m7O.js';
4
4
  import { Writable } from 'node:stream';
5
- import { ViteDevServer, TransformResult as TransformResult$1, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
5
+ import { Plugin, ViteDevServer, TransformResult as TransformResult$1, UserConfig as UserConfig$1, DepOptimizationConfig, ServerOptions, ConfigEnv, AliasOptions } from 'vite';
6
6
  import { MockedModule } from '@vitest/mocker';
7
7
  import { StackTraceParserOptions } from '@vitest/utils/source-map';
8
+ import { BrowserCommands } from 'vitest/browser';
8
9
  import { B as BrowserTraceViewMode, a as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.DGazh2r6.js';
9
- import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.D9YV3JvA.js';
10
+ import { B as BrowserTesterOptions, S as SerializedTestSpecification } from './browser.d.CM1rjKAX.js';
10
11
  import { PrettyFormatOptions } from '@vitest/pretty-format';
11
12
  import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
12
13
  import { SerializedDiffOptions } from '@vitest/utils/diff';
@@ -84,11 +85,24 @@ interface BrowserProviderOption<Options extends object = object> {
84
85
  name: string;
85
86
  supportedBrowser?: ReadonlyArray<string>;
86
87
  options: Options;
87
- factory: (project: TestProject) => BrowserProvider;
88
+ providerFactory: (project: TestProject) => BrowserProvider;
89
+ serverFactory: BrowserServerFactory;
90
+ }
91
+ interface BrowserServerOptions {
92
+ project: TestProject;
93
+ coveragePlugin: () => Plugin;
94
+ mocksPlugins: (options: {
95
+ filter: (id: string) => boolean;
96
+ }) => Plugin[];
97
+ metaEnvReplacer: () => Plugin;
98
+ }
99
+ interface BrowserServerFactory {
100
+ (otpions: BrowserServerOptions): Promise<ParentProjectBrowser>;
88
101
  }
89
102
  interface BrowserProvider {
90
103
  name: string;
91
104
  mocker?: BrowserModuleMocker;
105
+ readonly initScripts?: string[];
92
106
  /**
93
107
  * @experimental opt-in into file parallelisation
94
108
  */
@@ -99,13 +113,15 @@ interface BrowserProvider {
99
113
  close: () => Awaitable<void>;
100
114
  }
101
115
  type BrowserBuiltinProvider = "webdriverio" | "playwright" | "preview";
116
+ interface _BrowserNames {}
102
117
  type UnsupportedProperties = "browser" | "typecheck" | "alias" | "sequence" | "root" | "pool" | "poolOptions" | "runner" | "api" | "deps" | "environment" | "environmentOptions" | "server" | "benchmark" | "name";
103
- interface BrowserInstanceOption extends Omit<ProjectConfig, UnsupportedProperties>, Pick<BrowserConfigOptions, "headless" | "locators" | "viewport" | "testerHtmlPath" | "screenshotDirectory" | "screenshotFailures" | "provider"> {
118
+ interface BrowserInstanceOption extends Omit<ProjectConfig, UnsupportedProperties>, Pick<BrowserConfigOptions, "headless" | "locators" | "viewport" | "testerHtmlPath" | "screenshotDirectory" | "screenshotFailures"> {
104
119
  /**
105
120
  * Name of the browser
106
121
  */
107
- browser: string;
122
+ browser: keyof _BrowserNames extends never ? string : _BrowserNames[keyof _BrowserNames];
108
123
  name?: string;
124
+ provider?: BrowserProviderOption;
109
125
  }
110
126
  interface BrowserConfigOptions {
111
127
  /**
@@ -117,9 +133,20 @@ interface BrowserConfigOptions {
117
133
  /**
118
134
  * Configurations for different browser setups
119
135
  */
120
- instances: BrowserInstanceOption[];
136
+ instances?: BrowserInstanceOption[];
121
137
  /**
122
138
  * Browser provider
139
+ * @example
140
+ * ```ts
141
+ * import { playwright } from '@vitest/browser-playwright'
142
+ * export default defineConfig({
143
+ * test: {
144
+ * browser: {
145
+ * provider: playwright(),
146
+ * },
147
+ * },
148
+ * })
149
+ * ```
123
150
  */
124
151
  provider?: BrowserProviderOption;
125
152
  /**
@@ -225,7 +252,7 @@ interface BrowserConfigOptions {
225
252
  orchestratorScripts?: BrowserScript[];
226
253
  /**
227
254
  * Commands that will be executed on the server
228
- * via the browser `import("@vitest/browser/context").commands` API.
255
+ * via the browser `import("vitest/browser").commands` API.
229
256
  * @see {@link https://vitest.dev/guide/browser/commands}
230
257
  */
231
258
  commands?: Record<string, BrowserCommand<any>>;
@@ -260,6 +287,7 @@ interface BrowserCommandContext {
260
287
  provider: BrowserProvider;
261
288
  project: TestProject;
262
289
  sessionId: string;
290
+ triggerCommand: <K extends keyof BrowserCommands>(name: K, ...args: Parameters<BrowserCommands[K]>) => ReturnType<BrowserCommands[K]>;
263
291
  }
264
292
  interface BrowserServerStateSession {
265
293
  project: TestProject;
@@ -277,6 +305,7 @@ interface BrowserServerState {
277
305
  }
278
306
  interface ParentProjectBrowser {
279
307
  spawn: (project: TestProject) => ProjectBrowser;
308
+ vite: ViteDevServer;
280
309
  }
281
310
  interface ProjectBrowser {
282
311
  vite: ViteDevServer;
@@ -286,9 +315,14 @@ interface ProjectBrowser {
286
315
  initBrowserProvider: (project: TestProject) => Promise<void>;
287
316
  parseStacktrace: (stack: string) => ParsedStack[];
288
317
  parseErrorStacktrace: (error: TestError, options?: StackTraceParserOptions) => ParsedStack[];
318
+ registerCommand: <K extends keyof BrowserCommands>(name: K, cb: BrowserCommand<Parameters<BrowserCommands[K]>, ReturnType<BrowserCommands[K]>>) => void;
319
+ triggerCommand: <K extends keyof BrowserCommands>(name: K, context: BrowserCommandContext, ...args: Parameters<BrowserCommands[K]>) => ReturnType<BrowserCommands[K]>;
289
320
  }
290
- interface BrowserCommand<Payload extends unknown[] = []> {
291
- (context: BrowserCommandContext, ...payload: Payload): Awaitable<any>;
321
+ interface BrowserCommand<
322
+ Payload extends unknown[] = [],
323
+ ReturnValue = any
324
+ > {
325
+ (context: BrowserCommandContext, ...payload: Payload): Awaitable<ReturnValue>;
292
326
  }
293
327
  interface BrowserScript {
294
328
  /**
@@ -1866,70 +1900,70 @@ interface Reporter {
1866
1900
  * project.browser will always be defined.
1867
1901
  * @experimental
1868
1902
  */
1869
- onBrowserInit?: (project: TestProject) => Awaitable$1<void>;
1870
- onTestRemoved?: (trigger?: string) => Awaitable$1<void>;
1871
- onWatcherStart?: (files?: File[], errors?: unknown[]) => Awaitable$1<void>;
1872
- onWatcherRerun?: (files: string[], trigger?: string) => Awaitable$1<void>;
1873
- onServerRestart?: (reason?: string) => Awaitable$1<void>;
1874
- onUserConsoleLog?: (log: UserConsoleLog) => Awaitable$1<void>;
1875
- onProcessTimeout?: () => Awaitable$1<void>;
1903
+ onBrowserInit?: (project: TestProject) => Awaitable<void>;
1904
+ onTestRemoved?: (trigger?: string) => Awaitable<void>;
1905
+ onWatcherStart?: (files?: File[], errors?: unknown[]) => Awaitable<void>;
1906
+ onWatcherRerun?: (files: string[], trigger?: string) => Awaitable<void>;
1907
+ onServerRestart?: (reason?: string) => Awaitable<void>;
1908
+ onUserConsoleLog?: (log: UserConsoleLog) => Awaitable<void>;
1909
+ onProcessTimeout?: () => Awaitable<void>;
1876
1910
  /**
1877
1911
  * Called when the new test run starts.
1878
1912
  */
1879
- onTestRunStart?: (specifications: ReadonlyArray<TestSpecification>) => Awaitable$1<void>;
1913
+ onTestRunStart?: (specifications: ReadonlyArray<TestSpecification>) => Awaitable<void>;
1880
1914
  /**
1881
1915
  * Called when the test run is finished.
1882
1916
  */
1883
- onTestRunEnd?: (testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason) => Awaitable$1<void>;
1917
+ onTestRunEnd?: (testModules: ReadonlyArray<TestModule>, unhandledErrors: ReadonlyArray<SerializedError>, reason: TestRunEndReason) => Awaitable<void>;
1884
1918
  /**
1885
1919
  * Called when the module is enqueued for testing. The file itself is not loaded yet.
1886
1920
  */
1887
- onTestModuleQueued?: (testModule: TestModule) => Awaitable$1<void>;
1921
+ onTestModuleQueued?: (testModule: TestModule) => Awaitable<void>;
1888
1922
  /**
1889
1923
  * Called when the test file is loaded and the module is ready to run tests.
1890
1924
  */
1891
- onTestModuleCollected?: (testModule: TestModule) => Awaitable$1<void>;
1925
+ onTestModuleCollected?: (testModule: TestModule) => Awaitable<void>;
1892
1926
  /**
1893
1927
  * Called when starting to run tests of the test file
1894
1928
  */
1895
- onTestModuleStart?: (testModule: TestModule) => Awaitable$1<void>;
1929
+ onTestModuleStart?: (testModule: TestModule) => Awaitable<void>;
1896
1930
  /**
1897
1931
  * Called when all tests of the test file have finished running.
1898
1932
  */
1899
- onTestModuleEnd?: (testModule: TestModule) => Awaitable$1<void>;
1933
+ onTestModuleEnd?: (testModule: TestModule) => Awaitable<void>;
1900
1934
  /**
1901
1935
  * Called when test case is ready to run.
1902
1936
  * Called before the `beforeEach` hooks for the test are run.
1903
1937
  */
1904
- onTestCaseReady?: (testCase: TestCase) => Awaitable$1<void>;
1938
+ onTestCaseReady?: (testCase: TestCase) => Awaitable<void>;
1905
1939
  /**
1906
1940
  * Called after the test and its hooks are finished running.
1907
1941
  * The `result()` cannot be `pending`.
1908
1942
  */
1909
- onTestCaseResult?: (testCase: TestCase) => Awaitable$1<void>;
1943
+ onTestCaseResult?: (testCase: TestCase) => Awaitable<void>;
1910
1944
  /**
1911
1945
  * Called when annotation is added via the `task.annotate` API.
1912
1946
  */
1913
- onTestCaseAnnotate?: (testCase: TestCase, annotation: TestAnnotation) => Awaitable$1<void>;
1947
+ onTestCaseAnnotate?: (testCase: TestCase, annotation: TestAnnotation) => Awaitable<void>;
1914
1948
  /**
1915
1949
  * Called when test suite is ready to run.
1916
1950
  * Called before the `beforeAll` hooks for the test are run.
1917
1951
  */
1918
- onTestSuiteReady?: (testSuite: TestSuite) => Awaitable$1<void>;
1952
+ onTestSuiteReady?: (testSuite: TestSuite) => Awaitable<void>;
1919
1953
  /**
1920
1954
  * Called after the test suite and its hooks are finished running.
1921
1955
  * The `state` cannot be `pending`.
1922
1956
  */
1923
- onTestSuiteResult?: (testSuite: TestSuite) => Awaitable$1<void>;
1957
+ onTestSuiteResult?: (testSuite: TestSuite) => Awaitable<void>;
1924
1958
  /**
1925
1959
  * Called before the hook starts to run.
1926
1960
  */
1927
- onHookStart?: (hook: ReportedHookContext) => Awaitable$1<void>;
1961
+ onHookStart?: (hook: ReportedHookContext) => Awaitable<void>;
1928
1962
  /**
1929
1963
  * Called after the hook finished running.
1930
1964
  */
1931
- onHookEnd?: (hook: ReportedHookContext) => Awaitable$1<void>;
1932
- onCoverage?: (coverage: unknown) => Awaitable$1<void>;
1965
+ onHookEnd?: (hook: ReportedHookContext) => Awaitable<void>;
1966
+ onCoverage?: (coverage: unknown) => Awaitable<void>;
1933
1967
  }
1934
1968
 
1935
1969
  interface BaseOptions {
@@ -2229,8 +2263,8 @@ interface TestSequencer {
2229
2263
  * Slicing tests into shards. Will be run before `sort`.
2230
2264
  * Only run, if `shard` is defined.
2231
2265
  */
2232
- shard: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
2233
- sort: (files: TestSpecification[]) => Awaitable$1<TestSpecification[]>;
2266
+ shard: (files: TestSpecification[]) => Awaitable<TestSpecification[]>;
2267
+ sort: (files: TestSpecification[]) => Awaitable<TestSpecification[]>;
2234
2268
  }
2235
2269
  interface TestSequencerConstructor {
2236
2270
  new (ctx: Vitest): TestSequencer;
@@ -2260,7 +2294,7 @@ interface BenchmarkUserOptions {
2260
2294
  *
2261
2295
  * @default ['default']
2262
2296
  */
2263
- reporters?: Arrayable$1<BenchmarkBuiltinReporters | Reporter>;
2297
+ reporters?: Arrayable<BenchmarkBuiltinReporters | Reporter>;
2264
2298
  /**
2265
2299
  * @deprecated Use `benchmark.outputJson` instead
2266
2300
  */
@@ -3133,5 +3167,5 @@ type TestProjectInlineConfiguration = (UserWorkspaceConfig & {
3133
3167
  });
3134
3168
  type TestProjectConfiguration = string | TestProjectInlineConfiguration | Promise<UserWorkspaceConfig> | UserProjectConfigFn;
3135
3169
 
3136
- export { TestSuite as B, CoverageMap as C, experimental_getRunnerTask as E, Logger as L, TestProject as T, Vitest as V, GithubActionsReporter as aA, HangingProcessReporter as aB, JsonReporter as aC, JUnitReporter as aD, ReportersMap as aE, TapFlatReporter as aF, TapReporter as aG, VerboseBenchmarkReporter as aH, VerboseReporter as aI, BaseReporter as aJ, BenchmarkReporter as aw, BenchmarkReportsMap as ax, DefaultReporter as ay, DotReporter as az, TestSpecification as k, VitestPackageInstaller as n, TestCase as q, TestCollection as r, TestModule as t };
3137
- export type { BrowserProvider as $, ApiConfig as A, TestSuiteState as D, TestSequencerConstructor as F, BenchmarkUserOptions as G, HTMLOptions as H, InlineConfig as I, JsonOptions as J, BrowserBuiltinProvider as K, ModuleDiagnostic as M, BrowserCommand as N, OnServerRestartHandler as O, Pool as P, BrowserCommandContext as Q, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, BrowserConfigOptions as X, BrowserInstanceOption as Y, BrowserModuleMocker as Z, BrowserOrchestrator as _, TestProjectConfiguration as a, BrowserProviderOption as a0, BrowserScript as a1, BrowserServerState as a2, BrowserServerStateSession as a3, CDPSession as a4, ParentProjectBrowser as a5, ProjectBrowser as a6, ResolvedBrowserOptions as a7, ToMatchScreenshotComparators as a8, ToMatchScreenshotOptions as a9, BenchmarkBuiltinReporters as aK, BuiltinReporterOptions as aL, BuiltinReporters as aM, JsonAssertionResult as aN, JsonTestResult as aO, JsonTestResults as aP, BuiltinEnvironment as aa, CSSModuleScopeStrategy as ab, DepsOptimizationOptions as ac, EnvironmentOptions as ad, PoolOptions as ae, ProjectConfig as af, ResolvedProjectConfig as ag, ResolveSnapshotPathHandler as ah, ResolveSnapshotPathHandlerContext as ai, TypecheckConfig as aj, VitestEnvironment as ak, BaseCoverageOptions as al, CoverageIstanbulOptions as am, CoverageOptions as an, CoverageProvider as ao, CoverageProviderModule as ap, CoverageReporter as aq, CustomProviderOptions as ar, TestRunResult as as, ReportedHookContext as at, Reporter as au, TestRunEndReason as av, ReportContext as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, UserConfig as f, TestProjectInlineConfiguration as g, ResolvedConfig as h, VitestRunMode as i, VitestOptions as j, TestSequencer as l, OnTestsRerunHandler as m, JUnitOptions as o, TaskOptions as p, TestDiagnostic as s, TestModuleState as u, TestResult as v, TestResultFailed as w, TestResultPassed as x, TestResultSkipped as y, TestState as z };
3170
+ export { TestSuite as B, CoverageMap as C, experimental_getRunnerTask as E, Logger as L, TestProject as T, Vitest as V, BenchmarkReportsMap as aA, DefaultReporter as aB, DotReporter as aC, GithubActionsReporter as aD, HangingProcessReporter as aE, JsonReporter as aF, JUnitReporter as aG, ReportersMap as aH, TapFlatReporter as aI, TapReporter as aJ, VerboseBenchmarkReporter as aK, VerboseReporter as aL, BaseReporter as aM, BenchmarkReporter as az, TestSpecification as k, VitestPackageInstaller as n, TestCase as q, TestCollection as r, TestModule as t };
3171
+ export type { BrowserOrchestrator as $, ApiConfig as A, TestSuiteState as D, TestSequencerConstructor as F, BenchmarkUserOptions as G, HTMLOptions as H, InlineConfig as I, JsonOptions as J, BrowserBuiltinProvider as K, ModuleDiagnostic as M, BrowserCommand as N, OnServerRestartHandler as O, Pool as P, BrowserCommandContext as Q, ResolvedCoverageOptions as R, SerializedTestProject as S, UserWorkspaceConfig as U, WatcherTriggerPattern as W, BrowserConfigOptions as X, BrowserInstanceOption as Y, BrowserModuleMocker as Z, _BrowserNames as _, TestProjectConfiguration as a, BrowserProvider as a0, BrowserProviderOption as a1, BrowserScript as a2, BrowserServerFactory as a3, BrowserServerOptions as a4, BrowserServerState as a5, BrowserServerStateSession as a6, CDPSession as a7, ParentProjectBrowser as a8, ProjectBrowser as a9, BenchmarkBuiltinReporters as aN, BuiltinReporterOptions as aO, BuiltinReporters as aP, JsonAssertionResult as aQ, JsonTestResult as aR, JsonTestResults as aS, ResolvedBrowserOptions as aa, ToMatchScreenshotComparators as ab, ToMatchScreenshotOptions as ac, BuiltinEnvironment as ad, CSSModuleScopeStrategy as ae, DepsOptimizationOptions as af, EnvironmentOptions as ag, PoolOptions as ah, ProjectConfig as ai, ResolvedProjectConfig as aj, ResolveSnapshotPathHandler as ak, ResolveSnapshotPathHandlerContext as al, TypecheckConfig as am, VitestEnvironment as an, BaseCoverageOptions as ao, CoverageIstanbulOptions as ap, CoverageOptions as aq, CoverageProvider as ar, CoverageProviderModule as as, CoverageReporter as at, CustomProviderOptions as au, TestRunResult as av, ReportedHookContext as aw, Reporter as ax, TestRunEndReason as ay, ReportContext as b, CoverageV8Options as c, UserProjectConfigFn as d, UserProjectConfigExport as e, UserConfig as f, TestProjectInlineConfiguration as g, ResolvedConfig as h, VitestRunMode as i, VitestOptions as j, TestSequencer as l, OnTestsRerunHandler as m, JUnitOptions as o, TaskOptions as p, TestDiagnostic as s, TestModuleState as u, TestResult as v, TestResultFailed as w, TestResultPassed as x, TestResultSkipped as y, TestState as z };
@@ -7,6 +7,113 @@ import { getTests, generateHash, calculateSuiteHash, someTasksAreOnly, interpret
7
7
  import '@vitest/utils/helpers';
8
8
  import { parseAstAsync } from 'vite';
9
9
 
10
+ /// <reference types="../types/index.d.ts" />
11
+
12
+ // (c) 2020-present Andrea Giammarchi
13
+
14
+ const {parse: $parse, stringify: $stringify} = JSON;
15
+ const {keys} = Object;
16
+
17
+ const Primitive = String; // it could be Number
18
+ const primitive = 'string'; // it could be 'number'
19
+
20
+ const ignore$1 = {};
21
+ const object = 'object';
22
+
23
+ const noop = (_, value) => value;
24
+
25
+ const primitives = value => (
26
+ value instanceof Primitive ? Primitive(value) : value
27
+ );
28
+
29
+ const Primitives = (_, value) => (
30
+ typeof value === primitive ? new Primitive(value) : value
31
+ );
32
+
33
+ const revive = (input, parsed, output, $) => {
34
+ const lazy = [];
35
+ for (let ke = keys(output), {length} = ke, y = 0; y < length; y++) {
36
+ const k = ke[y];
37
+ const value = output[k];
38
+ if (value instanceof Primitive) {
39
+ const tmp = input[value];
40
+ if (typeof tmp === object && !parsed.has(tmp)) {
41
+ parsed.add(tmp);
42
+ output[k] = ignore$1;
43
+ lazy.push({k, a: [input, parsed, tmp, $]});
44
+ }
45
+ else
46
+ output[k] = $.call(output, k, tmp);
47
+ }
48
+ else if (output[k] !== ignore$1)
49
+ output[k] = $.call(output, k, value);
50
+ }
51
+ for (let {length} = lazy, i = 0; i < length; i++) {
52
+ const {k, a} = lazy[i];
53
+ output[k] = $.call(output, k, revive.apply(null, a));
54
+ }
55
+ return output;
56
+ };
57
+
58
+ const set = (known, input, value) => {
59
+ const index = Primitive(input.push(value) - 1);
60
+ known.set(value, index);
61
+ return index;
62
+ };
63
+
64
+ /**
65
+ * Converts a specialized flatted string into a JS value.
66
+ * @param {string} text
67
+ * @param {(this: any, key: string, value: any) => any} [reviver]
68
+ * @returns {any}
69
+ */
70
+ const parse$1 = (text, reviver) => {
71
+ const input = $parse(text, Primitives).map(primitives);
72
+ const value = input[0];
73
+ const $ = reviver || noop;
74
+ const tmp = typeof value === object && value ?
75
+ revive(input, new Set, value, $) :
76
+ value;
77
+ return $.call({'': tmp}, '', tmp);
78
+ };
79
+
80
+ /**
81
+ * Converts a JS value into a specialized flatted string.
82
+ * @param {any} value
83
+ * @param {((this: any, key: string, value: any) => any) | (string | number)[] | null | undefined} [replacer]
84
+ * @param {string | number | undefined} [space]
85
+ * @returns {string}
86
+ */
87
+ const stringify = (value, replacer, space) => {
88
+ const $ = replacer && typeof replacer === object ?
89
+ (k, v) => (k === '' || -1 < replacer.indexOf(k) ? v : void 0) :
90
+ (replacer || noop);
91
+ const known = new Map;
92
+ const input = [];
93
+ const output = [];
94
+ let i = +set(known, input, $.call({'': value}, '', value));
95
+ let firstRun = !i;
96
+ while (i < input.length) {
97
+ firstRun = true;
98
+ output[i] = $stringify(input[i++], replace, space);
99
+ }
100
+ return '[' + output.join(',') + ']';
101
+ function replace(key, value) {
102
+ if (firstRun) {
103
+ firstRun = !firstRun;
104
+ return value;
105
+ }
106
+ const after = $.call(this, key, value);
107
+ switch (typeof after) {
108
+ case object:
109
+ if (after === null) return after;
110
+ case primitive:
111
+ return known.get(after) || set(known, input, after);
112
+ }
113
+ return after;
114
+ }
115
+ };
116
+
10
117
  const REGEXP_WRAP_PREFIX = "$$vitest:";
11
118
  function getOutputFile(config, reporter) {
12
119
  if (config?.outputFile) return typeof config.outputFile === "string" ? config.outputFile : config.outputFile[reporter];
@@ -1412,4 +1519,4 @@ function findGeneratedPosition(traceMap, { line, column, source }) {
1412
1519
  };
1413
1520
  }
1414
1521
 
1415
- export { TypeCheckError as T, Typechecker as a, TraceMap as b, ancestor as c, createDefinesScript as d, convertTasksToEvents as e, getOutputFile as g, hasFailedSnapshot as h, originalPositionFor as o, wrapSerializableConfig as w };
1522
+ export { TypeCheckError as T, Typechecker as a, TraceMap as b, ancestor as c, createDefinesScript as d, convertTasksToEvents as e, getOutputFile as g, hasFailedSnapshot as h, originalPositionFor as o, parse$1 as p, stringify as s, wrapSerializableConfig as w };