From 6f17d5ddf511028cf8c24f8584110b5f2384fb6d Mon Sep 17 00:00:00 2001 From: Vladimir Date: Tue, 10 Feb 2026 12:15:49 +0100 Subject: [PATCH] feat(api): allow passing down test cases to `toTestSpecification` (#9627) --- docs/api/advanced/test-module.md | 4 +++- packages/vitest/src/node/reporters/reported-tasks.ts | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/api/advanced/test-module.md b/docs/api/advanced/test-module.md index 15f15ad95..a9c2feb5b 100644 --- a/docs/api/advanced/test-module.md +++ b/docs/api/advanced/test-module.md @@ -132,7 +132,9 @@ This is a Vite's [`DevEnvironment`](https://vite.dev/guide/api-environment) that ## toTestSpecification 4.1.0 {#totestspecification} ```ts -function toTestSpecification(): TestSpecification +function toTestSpecification(testCases?: TestCase[]): TestSpecification ``` Returns a new [test specification](/api/advanced/test-specification) that can be used to filter or run this specific test module. + +It accepts an optional array of test cases that should be filtered. diff --git a/packages/vitest/src/node/reporters/reported-tasks.ts b/packages/vitest/src/node/reporters/reported-tasks.ts index 06f62e54f..65b48cd3b 100644 --- a/packages/vitest/src/node/reporters/reported-tasks.ts +++ b/packages/vitest/src/node/reporters/reported-tasks.ts @@ -509,11 +509,11 @@ export class TestModule extends SuiteImplementation { /** * Returns a new test specification that can be used to filter or run this specific test module. */ - public toTestSpecification(): TestSpecification { + public toTestSpecification(testCases?: TestCase[]): TestSpecification { const isTypecheck = this.task.meta.typecheck === true return this.project.createSpecification( this.moduleId, - undefined, + testCases?.length ? { testIds: testCases.map(t => t.id) } : undefined, isTypecheck ? 'typecheck' : undefined, ) } -- 2.51.2