@vitest/runner 4.0.15 → 4.0.17

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.
@@ -38,9 +38,12 @@ function interpretTaskModes(file, namePattern, testLocations, onlyMode, parentIs
38
38
  const matchedLocations = [];
39
39
  const traverseSuite = (suite, parentIsOnly, parentMatchedWithLocation) => {
40
40
  const suiteIsOnly = parentIsOnly || suite.mode === "only";
41
+ // Check if any tasks in this suite have `.only` - if so, only those should run
42
+ const hasSomeTasksOnly = onlyMode && suite.tasks.some((t) => t.mode === "only" || t.type === "suite" && someTasksAreOnly(t));
41
43
  suite.tasks.forEach((t) => {
42
44
  // Check if either the parent suite or the task itself are marked as included
43
- const includeTask = suiteIsOnly || t.mode === "only";
45
+ // If there are tasks with `.only` in this suite, only include those (not all tasks from describe.only)
46
+ const includeTask = hasSomeTasksOnly ? t.mode === "only" || t.type === "suite" && someTasksAreOnly(t) : suiteIsOnly || t.mode === "only";
44
47
  if (onlyMode) {
45
48
  if (t.type === "suite" && (includeTask || someTasksAreOnly(t))) {
46
49
  // Don't skip this suite
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { b as TestArtifact, a as Test, S as Suite, d as SuiteHooks, F as File, e as TaskUpdateEvent, T as Task, f as TestAPI, g as SuiteAPI, h as SuiteCollector } from './tasks.d-Xu8VaPgy.js';
2
- export { A as AfterAllListener, n as AfterEachListener, B as BeforeAllListener, p as BeforeEachListener, q as Fixture, r as FixtureFn, s as FixtureOptions, t as Fixtures, I as ImportDuration, u as InferFixturesTypes, O as OnTestFailedHandler, v as OnTestFinishedHandler, R as RunMode, w as RuntimeContext, x as SequenceHooks, y as SequenceSetupFiles, z as SuiteFactory, D as TaskBase, E as TaskCustomOptions, G as TaskEventPack, H as TaskHook, J as TaskMeta, K as TaskPopulated, L as TaskResult, M as TaskResultPack, N as TaskState, P as TestAnnotation, Q as TestAnnotationArtifact, U as TestAnnotationLocation, V as TestArtifactBase, W as TestArtifactLocation, X as TestArtifactRegistry, Y as TestAttachment, Z as TestContext, _ as TestFunction, $ as TestOptions, a0 as Use, a1 as VisualRegressionArtifact, i as afterAll, j as afterEach, k as beforeAll, l as beforeEach, o as onTestFailed, m as onTestFinished } from './tasks.d-Xu8VaPgy.js';
1
+ import { b as TestArtifact, a as Test, S as Suite, d as SuiteHooks, F as File, e as TaskUpdateEvent, T as Task, f as TestAPI, g as SuiteAPI, h as SuiteCollector } from './tasks.d-C7UxawJ9.js';
2
+ export { A as AfterAllListener, n as AfterEachListener, B as BeforeAllListener, p as BeforeEachListener, q as Fixture, r as FixtureFn, s as FixtureOptions, t as Fixtures, I as ImportDuration, u as InferFixturesTypes, O as OnTestFailedHandler, v as OnTestFinishedHandler, R as RunMode, w as RuntimeContext, x as SequenceHooks, y as SequenceSetupFiles, z as SuiteFactory, D as TaskBase, E as TaskCustomOptions, G as TaskEventPack, H as TaskHook, J as TaskMeta, K as TaskPopulated, L as TaskResult, M as TaskResultPack, N as TaskState, P as TestAnnotation, Q as TestAnnotationArtifact, U as TestAnnotationLocation, V as TestArtifactBase, W as TestArtifactLocation, X as TestArtifactRegistry, Y as TestAttachment, Z as TestContext, _ as TestFunction, $ as TestOptions, a0 as Use, a1 as VisualRegressionArtifact, i as afterAll, j as afterEach, k as beforeAll, l as beforeEach, o as onTestFailed, m as onTestFinished } from './tasks.d-C7UxawJ9.js';
3
3
  import { Awaitable } from '@vitest/utils';
4
4
  import { FileSpecification, VitestRunner } from './types.js';
5
5
  export { CancelReason, VitestRunnerConfig, VitestRunnerConstructor, VitestRunnerImportSource } from './types.js';
package/dist/index.js CHANGED
@@ -680,7 +680,7 @@ let defaultSuite;
680
680
  let currentTestFilepath;
681
681
  function assert(condition, message) {
682
682
  if (!condition) {
683
- throw new Error(`Vitest failed to find ${message}. This is a bug in Vitest. Please, open an issue with reproduction.`);
683
+ throw new Error(`Vitest failed to find ${message}. One of the following is possible:` + "\n- \"vitest\" is imported directly without running \"vitest\" command" + "\n- \"vitest\" is imported inside \"globalSetup\" (to fix this, use \"setupFiles\" instead, because \"globalSetup\" runs in a different context)" + "\n- \"vitest\" is imported inside Vite / Vitest config file" + "\n- Otherwise, it might be a Vitest bug. Please report it to https://github.com/vitest-dev/vitest/issues\n");
684
684
  }
685
685
  }
686
686
  function getDefaultSuite() {
@@ -927,6 +927,9 @@ function withAwaitAsyncAssertions(fn, task) {
927
927
  function createSuite() {
928
928
  function suiteFn(name, factoryOrOptions, optionsOrFactory) {
929
929
  var _currentSuite$options;
930
+ if (getCurrentTest()) {
931
+ throw new Error("Calling the suite function inside test function is not allowed. It can be only called at the top level or inside another suite function.");
932
+ }
930
933
  let mode = this.only ? "only" : this.skip ? "skip" : this.todo ? "todo" : "run";
931
934
  const currentSuite = collectorContext.currentSuite || defaultSuite;
932
935
  let { options, handler: factory } = parseArguments(factoryOrOptions, optionsOrFactory);
@@ -510,7 +510,7 @@ interface Hooks<ExtraContext> {
510
510
  }
511
511
  type TestAPI<ExtraContext = object> = ChainableTestAPI<ExtraContext> & ExtendedAPI<ExtraContext> & Hooks<ExtraContext> & {
512
512
  extend: <T extends Record<string, any> = object>(fixtures: Fixtures<T, ExtraContext>) => TestAPI<{ [K in keyof T | keyof ExtraContext] : K extends keyof T ? T[K] : K extends keyof ExtraContext ? ExtraContext[K] : never }>;
513
- scoped: (fixtures: Fixtures<Partial<ExtraContext>>) => void;
513
+ scoped: (fixtures: Partial<Fixtures<ExtraContext>>) => void;
514
514
  };
515
515
  interface FixtureOptions {
516
516
  /**
@@ -545,7 +545,7 @@ type Fixture<
545
545
  ExtraContext = object
546
546
  > = ((...args: any) => any) extends T[K] ? T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never : T[K] | (T[K] extends any ? FixtureFn<T, K, Omit<ExtraContext, Exclude<keyof T, K>>> : never);
547
547
  type Fixtures<
548
- T extends Record<string, any>,
548
+ T,
549
549
  ExtraContext = object
550
550
  > = { [K in keyof T] : Fixture<T, K, ExtraContext & TestContext> | [Fixture<T, K, ExtraContext & TestContext>, FixtureOptions?] };
551
551
  type InferFixturesTypes<T> = T extends TestAPI<infer C> ? C : T;
@@ -635,12 +635,14 @@ interface TestContext {
635
635
  */
636
636
  readonly signal: AbortSignal;
637
637
  /**
638
- * Extract hooks on test failed
638
+ * Register a callback to run when this specific test fails.
639
+ * Useful when tests run concurrently.
639
640
  * @see {@link https://vitest.dev/guide/test-context#ontestfailed}
640
641
  */
641
642
  readonly onTestFailed: (fn: OnTestFailedHandler, timeout?: number) => void;
642
643
  /**
643
- * Extract hooks on test failed
644
+ * Register a callback to run when this specific test finishes.
645
+ * Useful when tests run concurrently.
644
646
  * @see {@link https://vitest.dev/guide/test-context#ontestfinished}
645
647
  */
646
648
  readonly onTestFinished: (fn: OnTestFinishedHandler, timeout?: number) => void;
@@ -730,13 +732,11 @@ interface TestAnnotationArtifact extends TestArtifactBase {
730
732
  type: "internal:annotation";
731
733
  annotation: TestAnnotation;
732
734
  }
733
- type VisualRegressionArtifactAttachment = TestAttachment & ({
734
- name: "reference" | "actual";
735
+ interface VisualRegressionArtifactAttachment extends TestAttachment {
736
+ name: "reference" | "actual" | "diff";
735
737
  width: number;
736
738
  height: number;
737
- } | {
738
- name: "diff";
739
- });
739
+ }
740
740
  /**
741
741
  * @experimental
742
742
  *
package/dist/types.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DiffOptions } from '@vitest/utils/diff';
2
- import { F as File, a as Test, S as Suite, M as TaskResultPack, G as TaskEventPack, P as TestAnnotation, b as TestArtifact, Z as TestContext, I as ImportDuration, x as SequenceHooks, y as SequenceSetupFiles } from './tasks.d-Xu8VaPgy.js';
3
- export { A as AfterAllListener, n as AfterEachListener, B as BeforeAllListener, p as BeforeEachListener, q as Fixture, r as FixtureFn, s as FixtureOptions, t as Fixtures, u as InferFixturesTypes, O as OnTestFailedHandler, v as OnTestFinishedHandler, R as RunMode, w as RuntimeContext, g as SuiteAPI, h as SuiteCollector, z as SuiteFactory, d as SuiteHooks, T as Task, D as TaskBase, E as TaskCustomOptions, H as TaskHook, J as TaskMeta, K as TaskPopulated, L as TaskResult, N as TaskState, e as TaskUpdateEvent, f as TestAPI, Q as TestAnnotationArtifact, U as TestAnnotationLocation, V as TestArtifactBase, W as TestArtifactLocation, X as TestArtifactRegistry, Y as TestAttachment, _ as TestFunction, $ as TestOptions, a0 as Use, a1 as VisualRegressionArtifact } from './tasks.d-Xu8VaPgy.js';
2
+ import { F as File, a as Test, S as Suite, M as TaskResultPack, G as TaskEventPack, P as TestAnnotation, b as TestArtifact, Z as TestContext, I as ImportDuration, x as SequenceHooks, y as SequenceSetupFiles } from './tasks.d-C7UxawJ9.js';
3
+ export { A as AfterAllListener, n as AfterEachListener, B as BeforeAllListener, p as BeforeEachListener, q as Fixture, r as FixtureFn, s as FixtureOptions, t as Fixtures, u as InferFixturesTypes, O as OnTestFailedHandler, v as OnTestFinishedHandler, R as RunMode, w as RuntimeContext, g as SuiteAPI, h as SuiteCollector, z as SuiteFactory, d as SuiteHooks, T as Task, D as TaskBase, E as TaskCustomOptions, H as TaskHook, J as TaskMeta, K as TaskPopulated, L as TaskResult, N as TaskState, e as TaskUpdateEvent, f as TestAPI, Q as TestAnnotationArtifact, U as TestAnnotationLocation, V as TestArtifactBase, W as TestArtifactLocation, X as TestArtifactRegistry, Y as TestAttachment, _ as TestFunction, $ as TestOptions, a0 as Use, a1 as VisualRegressionArtifact } from './tasks.d-C7UxawJ9.js';
4
4
  import '@vitest/utils';
5
5
 
6
6
  /**
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { S as Suite, F as File, T as Task, a as Test } from './tasks.d-Xu8VaPgy.js';
2
- export { C as ChainableFunction, c as createChainable } from './tasks.d-Xu8VaPgy.js';
1
+ import { S as Suite, F as File, T as Task, a as Test } from './tasks.d-C7UxawJ9.js';
2
+ export { C as ChainableFunction, c as createChainable } from './tasks.d-C7UxawJ9.js';
3
3
  import { ParsedStack, Arrayable } from '@vitest/utils';
4
4
 
5
5
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/runner",
3
3
  "type": "module",
4
- "version": "4.0.15",
4
+ "version": "4.0.17",
5
5
  "description": "Vitest test runner",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -39,7 +39,7 @@
39
39
  ],
40
40
  "dependencies": {
41
41
  "pathe": "^2.0.3",
42
- "@vitest/utils": "4.0.15"
42
+ "@vitest/utils": "4.0.17"
43
43
  },
44
44
  "scripts": {
45
45
  "build": "premove dist && rollup -c",