vitest 4.1.0-beta.1 → 4.1.0-beta.2

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 (65) hide show
  1. package/LICENSE.md +36 -0
  2. package/dist/browser.d.ts +1 -1
  3. package/dist/browser.js +2 -2
  4. package/dist/chunks/acorn.B2iPLyUM.js +5958 -0
  5. package/dist/chunks/{base.CBRNZa3k.js → base.DiopZV8F.js} +48 -14
  6. package/dist/chunks/{benchmark.B3N2zMcH.js → benchmark.BoqSLF53.js} +1 -1
  7. package/dist/chunks/{browser.d.8hOapKZr.d.ts → browser.d.BE4kbYok.d.ts} +2 -1
  8. package/dist/chunks/{cac.B1v3xxoC.js → cac.C4jjt2RX.js} +797 -13
  9. package/dist/chunks/{cli-api.B4CqEpI6.js → cli-api.ChbI1JU9.js} +322 -124
  10. package/dist/chunks/{config.d.idH22YSr.d.ts → config.d.Cr1Ep39N.d.ts} +6 -1
  11. package/dist/chunks/{console.uGgdMhyZ.js → console.CNlG1KsP.js} +2 -2
  12. package/dist/chunks/{constants.D_Q9UYh-.js → constants.B63TT-Bl.js} +1 -1
  13. package/dist/chunks/coverage.tyqbzn4W.js +1001 -0
  14. package/dist/chunks/{creator.C7WwjkuR.js → creator.yyCHuw5R.js} +1 -1
  15. package/dist/chunks/{global.d.B15mdLcR.d.ts → global.d.JeWMqlOm.d.ts} +1 -1
  16. package/dist/chunks/{globals.DjuGMoMc.js → globals.C6Ecf1TO.js} +6 -6
  17. package/dist/chunks/{index.Dm4xqZ0s.js → index.B-iBE_Gx.js} +20 -4
  18. package/dist/chunks/{coverage.BMlOMIWl.js → index.BCY_7LL2.js} +5 -969
  19. package/dist/chunks/{index.BiOAd_ki.js → index.CAN630q3.js} +7 -7
  20. package/dist/chunks/{index.DyBZXrH3.js → index.CFulQRmC.js} +1 -1
  21. package/dist/chunks/{index.BEFi2-_3.js → index.CouFDptX.js} +2 -2
  22. package/dist/chunks/{init-forks.CHeQ9Moq.js → init-forks.BnCXPazU.js} +1 -1
  23. package/dist/chunks/{init-threads.uZiNAuPk.js → init-threads.Cyh2PqXi.js} +1 -1
  24. package/dist/chunks/{init.DVtKdFty.js → init.B95Mm0Iz.js} +47 -9
  25. package/dist/chunks/native.mV0-490A.js +148 -0
  26. package/dist/chunks/nativeModuleMocker.D_q5sFv6.js +206 -0
  27. package/dist/chunks/nativeModuleRunner.BIakptoF.js +36 -0
  28. package/dist/chunks/{node.Ce0vMQM7.js → node.CrSEwhm4.js} +1 -1
  29. package/dist/chunks/{plugin.d.D8KU2PY_.d.ts → plugin.d.C9o5bttz.d.ts} +1 -1
  30. package/dist/chunks/{reporters.d.Db3MiIWX.d.ts → reporters.d.7faYdkxy.d.ts} +120 -51
  31. package/dist/chunks/{rpc.HLmECnw_.js → rpc.DcRWTy5G.js} +1 -1
  32. package/dist/chunks/{rpc.d.RH3apGEf.d.ts → rpc.d.CM7x9-sm.d.ts} +1 -0
  33. package/dist/chunks/{setup-common.BcqLPsn5.js → setup-common.cvFp-ao9.js} +2 -2
  34. package/dist/chunks/{startModuleRunner.C5CcWyXW.js → startVitestModuleRunner.BK-u7y4N.js} +163 -372
  35. package/dist/chunks/{test.prxIahgM.js → test.G82XYNFk.js} +9 -4
  36. package/dist/chunks/{utils.DvEY5TfP.js → utils.DT4VyRyl.js} +5 -1
  37. package/dist/chunks/{vm.CrifS09m.js → vm.BdLtzhnj.js} +13 -6
  38. package/dist/chunks/{worker.d.Bji1eq5g.d.ts → worker.d.CPzI2ZzJ.d.ts} +2 -2
  39. package/dist/cli.js +4 -3
  40. package/dist/config.d.ts +8 -8
  41. package/dist/config.js +1 -1
  42. package/dist/coverage.d.ts +7 -5
  43. package/dist/coverage.js +5 -4
  44. package/dist/index.d.ts +18 -23
  45. package/dist/index.js +5 -5
  46. package/dist/module-evaluator.d.ts +10 -1
  47. package/dist/node.d.ts +9 -9
  48. package/dist/node.js +18 -16
  49. package/dist/nodejs-worker-loader.js +41 -0
  50. package/dist/reporters.d.ts +5 -5
  51. package/dist/reporters.js +2 -2
  52. package/dist/runners.d.ts +2 -1
  53. package/dist/runners.js +4 -4
  54. package/dist/runtime.js +4 -5
  55. package/dist/snapshot.js +2 -2
  56. package/dist/suite.js +2 -2
  57. package/dist/worker.d.ts +6 -6
  58. package/dist/worker.js +25 -18
  59. package/dist/workers/forks.js +21 -14
  60. package/dist/workers/runVmTests.js +7 -7
  61. package/dist/workers/threads.js +21 -14
  62. package/dist/workers/vmForks.js +14 -10
  63. package/dist/workers/vmThreads.js +14 -10
  64. package/package.json +17 -14
  65. package/suppress-warnings.cjs +1 -0
@@ -1,16 +1,16 @@
1
- import { TaskMeta, Suite, File, SerializableRetry, 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, TestTagDefinition } from '@vitest/runner';
2
2
  import { TestError, SerializedError, Arrayable, ParsedStack, Awaitable } from '@vitest/utils';
3
- import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, L as LabelColor } from './rpc.d.RH3apGEf.js';
3
+ import { A as AfterSuiteRunMeta, U as UserConsoleLog, P as ProvidedContext, L as LabelColor } from './rpc.d.CM7x9-sm.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.8hOapKZr.js';
7
- import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.idH22YSr.js';
6
+ import { S as SerializedTestSpecification, c as SourceModuleDiagnostic, B as BrowserTesterOptions } from './browser.d.BE4kbYok.js';
7
+ import { B as BrowserTraceViewMode, S as SerializedConfig, F as FakeTimerInstallOpts } from './config.d.Cr1Ep39N.js';
8
8
  import { PrettyFormatOptions } from '@vitest/pretty-format';
9
9
  import { SnapshotSummary, SnapshotStateOptions } from '@vitest/snapshot';
10
10
  import { SerializedDiffOptions } from '@vitest/utils/diff';
11
11
  import { chai } from '@vitest/expect';
12
12
  import { happyDomTypes, jsdomTypes } from 'vitest/optional-types.js';
13
- import { c as ContextTestEnvironment, d as WorkerExecuteContext, e as WorkerTestEnvironment } from './worker.d.Bji1eq5g.js';
13
+ import { c as ContextTestEnvironment, d as WorkerExecuteContext, e as WorkerTestEnvironment } from './worker.d.CPzI2ZzJ.js';
14
14
  import { O as OTELCarrier } from './traces.d.402V_yFI.js';
15
15
  import { B as BenchmarkResult } from './benchmark.d.DAaHLpsq.js';
16
16
  import { MockedModule } from '@vitest/mocker';
@@ -72,6 +72,53 @@ interface ConstructorOptionsOverride {
72
72
  resources?: "usable";
73
73
  }
74
74
 
75
+ interface TestSpecificationOptions {
76
+ testNamePattern?: RegExp;
77
+ testIds?: string[];
78
+ testLines?: number[];
79
+ testTagsFilter?: string[];
80
+ }
81
+ declare class TestSpecification {
82
+ /**
83
+ * The task id associated with the test module.
84
+ */
85
+ readonly taskId: string;
86
+ /**
87
+ * The test project that the module belongs to.
88
+ */
89
+ readonly project: TestProject;
90
+ /**
91
+ * The id of the module in the Vite module graph. It is usually an absolute file path.
92
+ */
93
+ readonly moduleId: string;
94
+ /**
95
+ * The current test pool. It's possible to have multiple pools in a single test project with `typecheck.enabled`.
96
+ * @experimental In later versions, the project will only support a single pool.
97
+ */
98
+ readonly pool: Pool;
99
+ /**
100
+ * Line numbers of the test locations to run.
101
+ */
102
+ readonly testLines: number[] | undefined;
103
+ /**
104
+ * Regular expression pattern to filter test names.
105
+ */
106
+ readonly testNamePattern: RegExp | undefined;
107
+ /**
108
+ * The ids of tasks inside of this specification to run.
109
+ */
110
+ readonly testIds: string[] | undefined;
111
+ /**
112
+ * The tags of tests to run.
113
+ */
114
+ readonly testTagsFilter: string[] | undefined;
115
+ /**
116
+ * Test module associated with the specification. This will be `undefined` if tests have not been run yet.
117
+ */
118
+ get testModule(): TestModule | undefined;
119
+ toJSON(): SerializedTestSpecification;
120
+ }
121
+
75
122
  declare class ReportedTaskImplementation {
76
123
  /**
77
124
  * The project associated with the test or suite.
@@ -120,6 +167,10 @@ declare class TestCase extends ReportedTaskImplementation {
120
167
  */
121
168
  readonly parent: TestSuite | TestModule;
122
169
  /**
170
+ * Tags associated with the test.
171
+ */
172
+ readonly tags: string[];
173
+ /**
123
174
  * Full name of the test including all parent suites separated with `>`.
124
175
  */
125
176
  get fullName(): string;
@@ -146,6 +197,10 @@ declare class TestCase extends ReportedTaskImplementation {
146
197
  * Diagnostic is only available after the test has finished.
147
198
  */
148
199
  diagnostic(): TestDiagnostic | undefined;
200
+ /**
201
+ * Returns a new test specification that can be used to filter or run this specific test case.
202
+ */
203
+ toTestSpecification(): TestSpecification;
149
204
  }
150
205
  declare class TestCollection {
151
206
  #private;
@@ -231,6 +286,10 @@ declare class TestSuite extends SuiteImplementation {
231
286
  */
232
287
  state(): TestSuiteState;
233
288
  /**
289
+ * Returns a new test specification that can be used to filter or run this specific test suite.
290
+ */
291
+ toTestSpecification(): TestSpecification;
292
+ /**
234
293
  * Full name of the suite including all parent suites separated with `>`.
235
294
  */
236
295
  get fullName(): string;
@@ -255,6 +314,10 @@ declare class TestModule extends SuiteImplementation {
255
314
  */
256
315
  readonly relativeModuleId: string;
257
316
  /**
317
+ * Returns a new test specification that can be used to filter or run this specific test module.
318
+ */
319
+ toTestSpecification(): TestSpecification;
320
+ /**
258
321
  * Checks the running state of the test file.
259
322
  */
260
323
  state(): TestModuleState;
@@ -280,6 +343,11 @@ interface TaskOptions {
280
343
  readonly shuffle: boolean | undefined;
281
344
  readonly retry: SerializableRetry | undefined;
282
345
  readonly repeats: number | undefined;
346
+ readonly tags: string[] | undefined;
347
+ /**
348
+ * Only tests have a `timeout` option.
349
+ */
350
+ readonly timeout: number | undefined;
283
351
  readonly mode: "run" | "only" | "skip" | "todo";
284
352
  }
285
353
  type TestSuiteState = "skipped" | "pending" | "failed" | "passed";
@@ -402,48 +470,6 @@ declare function experimental_getRunnerTask(entity: TestSuite): Suite;
402
470
  declare function experimental_getRunnerTask(entity: TestModule): File;
403
471
  declare function experimental_getRunnerTask(entity: TestCase | TestSuite | TestModule): Suite | File | Test;
404
472
 
405
- interface TestSpecificationOptions {
406
- testNamePattern?: RegExp;
407
- testIds?: string[];
408
- testLines?: number[];
409
- }
410
- declare class TestSpecification {
411
- /**
412
- * The task id associated with the test module.
413
- */
414
- readonly taskId: string;
415
- /**
416
- * The test project that the module belongs to.
417
- */
418
- readonly project: TestProject;
419
- /**
420
- * The id of the module in the Vite module graph. It is usually an absolute file path.
421
- */
422
- readonly moduleId: string;
423
- /**
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.
426
- */
427
- readonly pool: Pool;
428
- /**
429
- * Line numbers of the test locations to run.
430
- */
431
- readonly testLines: number[] | undefined;
432
- /**
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.
442
- */
443
- get testModule(): TestModule | undefined;
444
- toJSON(): SerializedTestSpecification;
445
- }
446
-
447
473
  interface CoverageSummaryData {
448
474
  lines: Totals;
449
475
  statements: Totals;
@@ -877,6 +903,8 @@ declare class Logger {
877
903
  deprecate(message: string): void;
878
904
  clearHighlightCache(filename?: string): void;
879
905
  highlight(filename: string, source: string): string;
906
+ printNoTestTagsFound(): void;
907
+ printTags(): void;
880
908
  printNoTestFound(filters?: string[]): void;
881
909
  printBanner(): void;
882
910
  printBrowserBanner(project: TestProject): void;
@@ -1093,6 +1121,7 @@ declare class VitestWatcher {
1093
1121
  readonly changedTests: Set<string>;
1094
1122
  private readonly _onRerun;
1095
1123
  constructor(vitest: Vitest);
1124
+ close(): void;
1096
1125
  unregisterWatcher: () => void;
1097
1126
  registerWatcher(): this;
1098
1127
  private scheduleRerun;
@@ -1161,7 +1190,6 @@ declare class Vitest {
1161
1190
  private restartsCount;
1162
1191
  private readonly specifications;
1163
1192
  private pool;
1164
- private _config?;
1165
1193
  private _vite?;
1166
1194
  private _state?;
1167
1195
  private _cache?;
@@ -1195,6 +1223,7 @@ declare class Vitest {
1195
1223
  * Test results and test file stats cache. Primarily used by the sequencer to sort tests.
1196
1224
  */
1197
1225
  get cache(): VitestCache;
1226
+ listTags(): Promise<void>;
1198
1227
  enableCoverage(): Promise<void>;
1199
1228
  disableCoverage(): void;
1200
1229
  private clearAllCachePaths;
@@ -1446,7 +1475,9 @@ interface BrowserProvider {
1446
1475
  */
1447
1476
  supportsParallelism: boolean;
1448
1477
  getCommandsContext: (sessionId: string) => Record<string, unknown>;
1449
- openPage: (sessionId: string, url: string) => Promise<void>;
1478
+ openPage: (sessionId: string, url: string, options: {
1479
+ parallel: boolean;
1480
+ }) => Promise<void>;
1450
1481
  getCDPSession?: (sessionId: string) => Promise<CDPSession>;
1451
1482
  close: () => Awaitable<void>;
1452
1483
  }
@@ -2118,6 +2149,7 @@ interface JsonAssertionResult {
2118
2149
  duration?: Milliseconds | null;
2119
2150
  failureMessages: Array<string> | null;
2120
2151
  location?: Callsite | null;
2152
+ tags: string[];
2121
2153
  }
2122
2154
  interface JsonTestResult {
2123
2155
  message: string;
@@ -3070,7 +3102,34 @@ interface InlineConfig {
3070
3102
  * Enabling this will also show a breakdown by default in UI, but you can always press a button to toggle it.
3071
3103
  */
3072
3104
  printImportBreakdown?: boolean;
3105
+ /**
3106
+ * Controls whether Vitest uses Vite's module runner to run the code or fallback to the native `import`.
3107
+ *
3108
+ * If Node.js cannot process the code, consider registering [module loader](https://nodejs.org/api/module.html#customization-hooks) via `execArgv`.
3109
+ * @default true
3110
+ */
3111
+ viteModuleRunner?: boolean;
3112
+ /**
3113
+ * If module runner is disabled, Vitest uses a module loader to transform files to support
3114
+ * `import.meta.vitest` and `vi.mock`.
3115
+ *
3116
+ * If you don't use these features, you can disable this.
3117
+ *
3118
+ * This option only affects `loader.load` method, Vitest always defines a `loader.resolve` to populate the module graph.
3119
+ */
3120
+ nodeLoader?: boolean;
3073
3121
  };
3122
+ /**
3123
+ * Define tags available in your test files.
3124
+ *
3125
+ * If test defines a tag that is not listed here, an error will be thrown.
3126
+ */
3127
+ tags?: TestTagDefinition[];
3128
+ /**
3129
+ * Should Vitest throw an error if test has a tag that is not defined in the config.
3130
+ * @default true
3131
+ */
3132
+ strictTags?: boolean;
3074
3133
  }
3075
3134
  interface TypecheckConfig {
3076
3135
  /**
@@ -3191,11 +3250,20 @@ interface UserConfig extends InlineConfig {
3191
3250
  * @experimental
3192
3251
  */
3193
3252
  clearCache?: boolean;
3253
+ /**
3254
+ * Tags expression to filter tests to run. Multiple filters will be applied using AND logic.
3255
+ * @see {@link https://vitest.dev/guide/test-tags#syntax}
3256
+ */
3257
+ tagsFilter?: string[];
3258
+ /**
3259
+ * Log all available tags instead of running tests.
3260
+ */
3261
+ listTags?: boolean | "json";
3194
3262
  }
3195
3263
  type OnUnhandledErrorCallback = (error: (TestError | Error) & {
3196
3264
  type: string;
3197
3265
  }) => boolean | void;
3198
- interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config" | "filters" | "browser" | "coverage" | "testNamePattern" | "related" | "api" | "reporters" | "resolveSnapshotPath" | "benchmark" | "shard" | "cache" | "sequence" | "typecheck" | "runner" | "pool" | "cliExclude" | "diff" | "setupFiles" | "snapshotEnvironment" | "bail" | "name" | "vmMemoryLimit" | "fileParallelism"> {
3266
+ interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config" | "filters" | "browser" | "coverage" | "testNamePattern" | "related" | "api" | "reporters" | "resolveSnapshotPath" | "benchmark" | "shard" | "cache" | "sequence" | "typecheck" | "runner" | "pool" | "cliExclude" | "diff" | "setupFiles" | "snapshotEnvironment" | "bail" | "name" | "vmMemoryLimit" | "fileParallelism" | "tagsFilter"> {
3199
3267
  mode: VitestRunMode;
3200
3268
  name: ProjectName["label"];
3201
3269
  color?: ProjectName["color"];
@@ -3248,8 +3316,9 @@ interface ResolvedConfig extends Omit<Required<UserConfig>, "project" | "config"
3248
3316
  maxWorkers: number;
3249
3317
  vmMemoryLimit?: UserConfig["vmMemoryLimit"];
3250
3318
  dumpDir?: string;
3319
+ tagsFilter?: string[];
3251
3320
  }
3252
- type NonProjectOptions = "shard" | "watch" | "run" | "cache" | "update" | "reporters" | "outputFile" | "teardownTimeout" | "silent" | "forceRerunTriggers" | "testNamePattern" | "ui" | "open" | "uiBase" | "snapshotFormat" | "resolveSnapshotPath" | "passWithNoTests" | "onConsoleLog" | "onStackTrace" | "dangerouslyIgnoreUnhandledErrors" | "slowTestThreshold" | "inspect" | "inspectBrk" | "coverage" | "watchTriggerPatterns";
3321
+ type NonProjectOptions = "shard" | "watch" | "run" | "cache" | "update" | "reporters" | "outputFile" | "teardownTimeout" | "silent" | "forceRerunTriggers" | "testNamePattern" | "ui" | "open" | "uiBase" | "snapshotFormat" | "resolveSnapshotPath" | "passWithNoTests" | "onConsoleLog" | "onStackTrace" | "dangerouslyIgnoreUnhandledErrors" | "slowTestThreshold" | "inspect" | "inspectBrk" | "coverage" | "watchTriggerPatterns" | "tagsFilter";
3253
3322
  interface ServerDepsOptions {
3254
3323
  /**
3255
3324
  * Externalize means that Vite will bpass the package to native Node.
@@ -1,6 +1,6 @@
1
1
  import { getSafeTimers } from '@vitest/utils/timers';
2
2
  import { c as createBirpc } from './index.Chj8NDwU.js';
3
- import { g as getWorkerState } from './utils.DvEY5TfP.js';
3
+ import { g as getWorkerState } from './utils.DT4VyRyl.js';
4
4
 
5
5
  /* Ported from https://github.com/boblauer/MockDate/blob/master/src/mockdate.ts */
6
6
  /*
@@ -56,6 +56,7 @@ interface RuntimeRPC {
56
56
  getCountOfFailedTests: () => number;
57
57
  snapshotSaved: (snapshot: SnapshotResult) => void;
58
58
  resolveSnapshotPath: (testPath: string) => string;
59
+ ensureModuleGraphEntry: (id: string, importer: string) => void;
59
60
  }
60
61
  interface RunnerRPC {
61
62
  onCancel: (reason: CancelReason) => void;
@@ -1,7 +1,7 @@
1
1
  import { r as resolveCoverageProviderModule } from './coverage.D_JHT54q.js';
2
2
  import { addSerializer } from '@vitest/snapshot';
3
3
  import { setSafeTimers } from '@vitest/utils/timers';
4
- import { g as getWorkerState } from './utils.DvEY5TfP.js';
4
+ import { g as getWorkerState } from './utils.DT4VyRyl.js';
5
5
 
6
6
  async function startCoverageInsideWorker(options, loader, runtimeOptions) {
7
7
  const coverageModule = await resolveCoverageProviderModule(options, loader);
@@ -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.DjuGMoMc.js')).registerApiGlobally();
29
+ if (config.globals) (await import('./globals.C6Ecf1TO.js')).registerApiGlobally();
30
30
  }
31
31
  function setupDefines(config) {
32
32
  for (const key in config.defines) globalThis[key] = config.defines[key];