Skip to content

Commit cc3cf03

Browse files
committed
chore: flaky tests, seems setup was running per file causing it to remove dist mid run of other tests
1 parent e1f6bff commit cc3cf03

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/test-setup.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
/**
22
* Test setup file for vitest
3-
*
4-
* Configures the test environment before running tests
3+
*
4+
* Global setup that runs ONCE before all tests
55
*/
66

7-
// Make sure to build the project before running tests
8-
// We rely on the dist files to spawn our CLI in integration tests
97
import { spawnSync } from 'node:child_process'
108

11-
// Extend test timeout for integration tests
12-
process.env.VITEST_POOL_TIMEOUT = '60000'
9+
export function setup() {
10+
// Extend test timeout for integration tests
11+
process.env.VITEST_POOL_TIMEOUT = '60000'
1312

14-
const buildResult = spawnSync('yarn', ['build'], { stdio: 'pipe' })
15-
if (buildResult.stderr && buildResult.stderr.length > 0) {
16-
const errorOutput = buildResult.stderr.toString()
17-
console.error(`Build stderr (could be debugger output): ${errorOutput}`)
18-
const stdout = buildResult.stdout.toString()
19-
console.log(`Build stdout: ${stdout}`)
13+
// Make sure to build the project before running tests
14+
// We rely on the dist files to spawn our CLI in integration tests
15+
const buildResult = spawnSync('yarn', ['build'], { stdio: 'pipe' })
2016

21-
if (errorOutput.includes('Command failed with exit code')) {
22-
throw new Error(`Build failed STDERR: ${errorOutput}`)
17+
if (buildResult.stderr && buildResult.stderr.length > 0) {
18+
const errorOutput = buildResult.stderr.toString()
19+
console.error(`Build stderr (could be debugger output): ${errorOutput}`)
20+
const stdout = buildResult.stdout.toString()
21+
console.log(`Build stdout: ${stdout}`)
22+
23+
if (errorOutput.includes('Command failed with exit code')) {
24+
throw new Error(`Build failed STDERR: ${errorOutput}`)
25+
}
2326
}
2427
}

vitest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default defineConfig({
1212
globals: false,
1313
environment: 'node',
1414
include: ['src/**/*.test.ts'],
15-
setupFiles: ['./src/test-setup.ts'],
15+
globalSetup: ['./src/test-setup.ts'],
1616
coverage: {
1717
provider: 'v8',
1818
reporter: ['text', 'json', 'html'],

0 commit comments

Comments
 (0)