Skip to content

Commit

Permalink
fix(typecheck): correctly run both runtime and typecheck tests if typ…
Browse files Browse the repository at this point in the history
…echeck.include overlaps with include
  • Loading branch information
sheremet-va committed Aug 1, 2024
1 parent af2b813 commit 66fbed3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
23 changes: 13 additions & 10 deletions packages/vitest/src/node/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ export const builtinPools: BuiltinPool[] = [
'typescript',
]

function getDefaultPoolName(project: WorkspaceProject, file: string): Pool {
if (project.config.typecheck.enabled) {
for (const glob of project.config.typecheck.include) {
if (mm.isMatch(file, glob, { cwd: project.config.root })) {
return 'typescript'
}
}
}
function getDefaultPoolName(project: WorkspaceProject): Pool {
if (project.config.browser.enabled) {
return 'browser'
}
Expand All @@ -64,7 +57,7 @@ export function getFilePoolName(project: WorkspaceProject, file: string) {
return pool as Pool
}
}
return getDefaultPoolName(project, file)
return getDefaultPoolName(project)
}

export function createPool(ctx: Vitest): ProcessPool {
Expand Down Expand Up @@ -174,9 +167,19 @@ export function createPool(ctx: Vitest): ProcessPool {
}

for (const spec of files) {
const pool = getFilePoolName(spec[0], spec[1])
const [project, file] = spec
const pool = getFilePoolName(project, file)
filesByPool[pool] ??= []
filesByPool[pool].push(spec)

if (project.config.typecheck.enabled) {
for (const glob of project.config.typecheck.include) {
if (mm.isMatch(file, glob, { cwd: project.config.root })) {
filesByPool.typescript ??= []
filesByPool.typescript.push(spec)
}
}
}
}

const Sequencer = ctx.config.sequence.sequencer
Expand Down
6 changes: 4 additions & 2 deletions packages/vitest/src/typecheck/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,18 @@ export async function collectTests(
}
const ast = await parseAstAsync(request.code)
const testFilepath = relative(ctx.config.root, filepath)
const projectName = ctx.getName()
const typecheckSubprojectName = projectName ? `${projectName}:typecheck` : 'typecheck'
const file: ParsedFile = {
filepath,
type: 'suite',
id: generateHash(`${testFilepath}${ctx.config.name || ''}`),
id: generateHash(`${testFilepath}${typecheckSubprojectName}`),
name: testFilepath,
mode: 'run',
tasks: [],
start: ast.start,
end: ast.end,
projectName: ctx.getName(),
projectName,
meta: { typecheck: true },
file: null!,
}
Expand Down

0 comments on commit 66fbed3

Please sign in to comment.