Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: correctly resolve config in a workspace #3947

Merged
merged 5 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/browser/src/client/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export function createBrowserRunner(original: any, coverageModule: CoverageHandl
async onAfterRun() {
await super.onAfterRun?.()
const coverage = await coverageModule?.takeCoverage?.()
await rpc().onAfterSuiteRun({ coverage })
if (coverage)
await rpc().onAfterSuiteRun({ coverage })
}

onCollected(files: File[]): unknown {
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/api/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function setup(vitestOrWorkspace: Vitest | WorkspaceProject, server?: Vit
await ctx.rerunFiles(files)
},
getConfig() {
return ctx.config
return vitestOrWorkspace.config
},
async getTransformResult(id) {
const result: TransformResultWithSource | null | undefined = await ctx.vitenode.transformRequest(id)
Expand Down
28 changes: 22 additions & 6 deletions packages/vitest/src/node/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Vitest {
restartsCount = 0
runner: ViteNodeRunner = undefined!

private coreWorkspace!: WorkspaceProject
private coreWorkspaceProject!: WorkspaceProject

public projects: WorkspaceProject[] = []
private projectsTestFiles = new Map<string, Set<WorkspaceProject>>()
Expand Down Expand Up @@ -145,12 +145,12 @@ export class Vitest {
runner: this.runner,
server: this.vitenode,
})
this.coreWorkspace = coreWorkspace
this.coreWorkspaceProject = coreWorkspace
return coreWorkspace
}

public getCoreWorkspaceProject(): WorkspaceProject | null {
return this.coreWorkspace || null
return this.coreWorkspaceProject || null
}

public getProjectByTaskId(taskId: string): WorkspaceProject {
Expand Down Expand Up @@ -198,7 +198,7 @@ export class Vitest {
onlyFiles: false,
markDirectories: true,
cwd: this.config.root,
ignore: ['**/node_modules/**'],
ignore: ['**/node_modules/**', '**/*.timestamp-*'],
}

const workspacesFs = await fg(workspaceGlobMatches, globOptions)
Expand All @@ -221,6 +221,21 @@ export class Vitest {
return filepath
}))

const workspacesByFolder = resolvedWorkspacesPaths
.reduce((configByFolder, filepath) => {
const dir = dirname(filepath)
configByFolder[dir] ??= []
configByFolder[dir].push(filepath)
return configByFolder
}, {} as Record<string, string[]>)

const filteredWorkspaces = Object.values(workspacesByFolder).map((configFiles) => {
if (configFiles.length === 1)
return configFiles[0]
const vitestConfig = configFiles.find(configFile => basename(configFile).startsWith('vitest.config'))
return vitestConfig || configFiles[0]
})

const overridesOptions = [
'logHeapUsage',
'allowOnly',
Expand All @@ -239,7 +254,7 @@ export class Vitest {
return acc
}, {} as UserConfig)

const projects = resolvedWorkspacesPaths.map(async (workspacePath) => {
const projects = filteredWorkspaces.map(async (workspacePath) => {
// don't start a new server, but reuse existing one
if (
this.server.config.configFile === workspacePath
Expand Down Expand Up @@ -725,7 +740,8 @@ export class Vitest {
if (!this.closingPromise) {
const closePromises = this.projects.map(w => w.close().then(() => w.server = undefined as any))
// close the core workspace server only once
if (this.coreWorkspace && !this.projects.includes(this.coreWorkspace))
// it's possible that it's not initialized at all because it's not running any tests
if (!this.coreWorkspaceProject || !this.projects.includes(this.coreWorkspaceProject))
closePromises.push(this.server.close().then(() => this.server = undefined as any))

if (this.pool)
Expand Down
Loading
Loading