Skip to content

Commit a1dce6d

Browse files
committed
fix: vitest global setup & teardown
1 parent f6ca8dc commit a1dce6d

5 files changed

Lines changed: 24 additions & 26 deletions

File tree

tests/global/global.d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/global/globalSetup.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/global/globalTeardown.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

tests/globalSetup.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { startServer, stopServer } from 'sync-dev-server';
2+
import { HOST as host, PORT as port } from './app/config';
3+
4+
export default function setup() {
5+
const command = 'pnpm start';
6+
globalThis.server = startServer(command, {
7+
host,
8+
port,
9+
debug: false,
10+
timeout: 50 * 1000,
11+
usedPortAction: 'ignore',
12+
});
13+
14+
return () => {
15+
stopServer(globalThis.server, 'SIGINT');
16+
}
17+
};

vitest.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
globalSetup: ['./tests/globalSetup.ts'],
6+
}
7+
})

0 commit comments

Comments
 (0)