diff --git a/packages/vitest/src/node/reporters/reported-tasks.ts b/packages/vitest/src/node/reporters/reported-tasks.ts index bd1234500..6cdac5d63 100644 --- a/packages/vitest/src/node/reporters/reported-tasks.ts +++ b/packages/vitest/src/node/reporters/reported-tasks.ts @@ -246,11 +246,11 @@ export class TestCase extends ReportedTaskImplementation { * Returns a new test specification that can be used to filter or run this specific test case. */ public toTestSpecification(): TestSpecification { - const isTypecheck = this.task.meta.typecheck === true + const isTypecheck = this.module.task.meta.typecheck === true return this.project.createSpecification( this.module.moduleId, { testIds: [this.id] }, - isTypecheck ? 'typecheck' : undefined, + isTypecheck ? 'typescript' : undefined, ) } } @@ -458,12 +458,12 @@ export class TestSuite extends SuiteImplementation { * Returns a new test specification that can be used to filter or run this specific test suite. */ public toTestSpecification(): TestSpecification { - const isTypecheck = this.task.meta.typecheck === true + const isTypecheck = this.module.task.meta.typecheck === true const testIds = Array.from(this.children.allTests(), (test) => test.id) return this.project.createSpecification( this.module.moduleId, { testIds }, - isTypecheck ? 'typecheck' : undefined, + isTypecheck ? 'typescript' : undefined, ) } @@ -525,7 +525,7 @@ export class TestModule extends SuiteImplementation { return this.project.createSpecification( this.moduleId, testCases?.length ? { testIds: testCases.map((t) => t.id) } : undefined, - isTypecheck ? 'typecheck' : undefined, + isTypecheck ? 'typescript' : undefined, ) } diff --git a/test/typescript/test/specification.test.ts b/test/typescript/test/specification.test.ts new file mode 100644 index 000000000..15a3971f4 --- /dev/null +++ b/test/typescript/test/specification.test.ts @@ -0,0 +1,45 @@ +import { expect, test } from 'vitest' +import { runInlineTests } from '../../test-utils' + +test('typecheck tasks create specifications for the typescript pool', async () => { + const { ctx } = await runInlineTests( + { + 'basic.check.ts': /* ts */ ` + import { describe, expectTypeOf, test } from 'vitest' + describe('suite', () => { + test('number is a number', () => { + expectTypeOf(1).toBeNumber() + }) + }) + `, + 'tsconfig.json': JSON.stringify({ + compilerOptions: { + strict: true, + noEmit: true, + target: 'esnext', + module: 'esnext', + moduleResolution: 'bundler', + skipLibCheck: true, + }, + include: ['*.check.ts'], + }), + }, + { typecheck: { enabled: true, only: true, include: ['*.check.ts'] } }, + ) + + const [testModule] = ctx!.state.getTestModules() + const [testSuite] = testModule.children.suites() + const [testCase] = testSuite.children.tests() + + const moduleSpecification = testModule.toTestSpecification() + expect(moduleSpecification.pool).toBe('typescript') + expect(moduleSpecification.testModule).toBe(testModule) + + const suiteSpecification = testSuite.toTestSpecification() + expect(suiteSpecification.pool).toBe('typescript') + expect(suiteSpecification.testModule).toBe(testModule) + + const caseSpecification = testCase.toTestSpecification() + expect(caseSpecification.pool).toBe('typescript') + expect(caseSpecification.testModule).toBe(testModule) +})