Skip to content

Commit 5f2739e

Browse files
authored
fix(typecheck): use typescript pool in toTestSpecification (#11451)
1 parent 9673c49 commit 5f2739e

2 files changed

Lines changed: 50 additions & 5 deletions

File tree

‎packages/vitest/src/node/reporters/reported-tasks.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ export class TestCase extends ReportedTaskImplementation {
246246
* Returns a new test specification that can be used to filter or run this specific test case.
247247
*/
248248
public toTestSpecification(): TestSpecification {
249-
const isTypecheck = this.task.meta.typecheck === true
249+
const isTypecheck = this.module.task.meta.typecheck === true
250250
return this.project.createSpecification(
251251
this.module.moduleId,
252252
{ testIds: [this.id] },
253-
isTypecheck ? 'typecheck' : undefined,
253+
isTypecheck ? 'typescript' : undefined,
254254
)
255255
}
256256
}
@@ -458,12 +458,12 @@ export class TestSuite extends SuiteImplementation {
458458
* Returns a new test specification that can be used to filter or run this specific test suite.
459459
*/
460460
public toTestSpecification(): TestSpecification {
461-
const isTypecheck = this.task.meta.typecheck === true
461+
const isTypecheck = this.module.task.meta.typecheck === true
462462
const testIds = Array.from(this.children.allTests(), (test) => test.id)
463463
return this.project.createSpecification(
464464
this.module.moduleId,
465465
{ testIds },
466-
isTypecheck ? 'typecheck' : undefined,
466+
isTypecheck ? 'typescript' : undefined,
467467
)
468468
}
469469

@@ -525,7 +525,7 @@ export class TestModule extends SuiteImplementation {
525525
return this.project.createSpecification(
526526
this.moduleId,
527527
testCases?.length ? { testIds: testCases.map((t) => t.id) } : undefined,
528-
isTypecheck ? 'typecheck' : undefined,
528+
isTypecheck ? 'typescript' : undefined,
529529
)
530530
}
531531

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { expect, test } from 'vitest'
2+
import { runInlineTests } from '../../test-utils'
3+
4+
test('typecheck tasks create specifications for the typescript pool', async () => {
5+
const { ctx } = await runInlineTests(
6+
{
7+
'basic.check.ts': /* ts */ `
8+
import { describe, expectTypeOf, test } from 'vitest'
9+
describe('suite', () => {
10+
test('number is a number', () => {
11+
expectTypeOf(1).toBeNumber()
12+
})
13+
})
14+
`,
15+
'tsconfig.json': JSON.stringify({
16+
compilerOptions: {
17+
strict: true,
18+
noEmit: true,
19+
target: 'esnext',
20+
module: 'esnext',
21+
moduleResolution: 'bundler',
22+
skipLibCheck: true,
23+
},
24+
include: ['*.check.ts'],
25+
}),
26+
},
27+
{ typecheck: { enabled: true, only: true, include: ['*.check.ts'] } },
28+
)
29+
30+
const [testModule] = ctx!.state.getTestModules()
31+
const [testSuite] = testModule.children.suites()
32+
const [testCase] = testSuite.children.tests()
33+
34+
const moduleSpecification = testModule.toTestSpecification()
35+
expect(moduleSpecification.pool).toBe('typescript')
36+
expect(moduleSpecification.testModule).toBe(testModule)
37+
38+
const suiteSpecification = testSuite.toTestSpecification()
39+
expect(suiteSpecification.pool).toBe('typescript')
40+
expect(suiteSpecification.testModule).toBe(testModule)
41+
42+
const caseSpecification = testCase.toTestSpecification()
43+
expect(caseSpecification.pool).toBe('typescript')
44+
expect(caseSpecification.testModule).toBe(testModule)
45+
})

0 commit comments

Comments
 (0)