|
1 | 1 | /** |
2 | 2 | * Test setup file for vitest |
3 | | - * |
4 | | - * Configures the test environment before running tests |
| 3 | + * |
| 4 | + * Global setup that runs ONCE before all tests |
5 | 5 | */ |
6 | 6 |
|
7 | | -// Make sure to build the project before running tests |
8 | | -// We rely on the dist files to spawn our CLI in integration tests |
9 | 7 | import { spawnSync } from 'node:child_process' |
10 | 8 |
|
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' |
13 | 12 |
|
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' }) |
20 | 16 |
|
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 | + } |
23 | 26 | } |
24 | 27 | } |
0 commit comments