diff --git a/packages/vitest/src/node/core.ts b/packages/vitest/src/node/core.ts index 6f90f2df7bf8..a5a82926346f 100644 --- a/packages/vitest/src/node/core.ts +++ b/packages/vitest/src/node/core.ts @@ -797,8 +797,11 @@ export class Vitest { async close() { if (!this.closingPromise) { this.closingPromise = (async () => { + const teardownProjects = [...this.projects] + if (!teardownProjects.includes(this.coreWorkspaceProject)) + teardownProjects.push(this.coreWorkspaceProject) // do teardown before closing the server - for await (const project of [...this.projects].reverse()) + for await (const project of teardownProjects.reverse()) await project.teardownGlobalSetup() const closePromises: unknown[] = this.projects.map(w => w.close().then(() => w.server = undefined as any)) diff --git a/test/workspaces/globalTest.ts b/test/workspaces/globalTest.ts index f42631c2a19e..58d9233401cc 100644 --- a/test/workspaces/globalTest.ts +++ b/test/workspaces/globalTest.ts @@ -24,14 +24,17 @@ export function setup({ provide }: GlobalSetupContext) { } } +let teardownCalled = false + export async function teardown() { + teardownCalled = true const results = JSON.parse(await readFile('./results.json', 'utf-8')) try { assert.ok(results.success) - assert.equal(results.numTotalTestSuites, 11) - assert.equal(results.numTotalTests, 12) - assert.equal(results.numPassedTests, 12) + assert.equal(results.numTotalTestSuites, 28) + assert.equal(results.numTotalTests, 29) + assert.equal(results.numPassedTests, 29) const shared = results.testResults.filter((r: any) => r.name.includes('space_shared/test.spec.ts')) @@ -42,3 +45,10 @@ export async function teardown() { process.exit(1) } } + +process.on('beforeExit', () => { + if (!teardownCalled) { + console.error('teardown was not called') + process.exitCode = 1 + } +})