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, ) }