-
Notifications
You must be signed in to change notification settings - Fork 1
/
vitest.config.ts
33 lines (26 loc) · 1.02 KB
/
vitest.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import fs from 'fs'
import tsconfigPaths from 'vite-tsconfig-paths'
import { defineConfig } from 'vitest/config'
if (!process.env['TEST_TYPE']) {
throw new Error('The `TEST_TYPE` environment variable should be defined to specify the type of tests to run.')
}
export default defineConfig({
plugins: [tsconfigPaths()],
test: {
environment: process.env['TEST_TYPE'] === 'client' ? 'happy-dom' : 'node',
include: [`src/tests/${process.env['TEST_TYPE']}/**/*.test.ts`],
globalSetup: getConfigFilePath('globalSetup.ts'),
setupFiles: getConfigFilePath('filesSetup.ts'),
singleThread: process.env['TEST_TYPE'] === 'api',
},
})
function getConfigFilePath(fileName: string) {
if (!process.env['TEST_TYPE']) {
throw new Error(
`The 'TEST_TYPE' environment variable should be defined to get the configuration file path for '${fileName}'.`
)
}
const relativePath = `src/tests/${process.env['TEST_TYPE']}/${fileName}`
const exists = fs.existsSync(relativePath)
return exists ? relativePath : undefined
}