-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vitest.config.ts
84 lines (76 loc) · 2.06 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/// <reference types="vitest" />
import type { UserConfig } from 'vitest/node'
import { resolve } from 'node:path'
import process from 'node:process'
import { defineConfig } from 'vite'
import { valueToBooleanNotFalse } from './src/common/data/convert'
const config: UserConfig = {
snapshotFormat: {
printBasicPrototype: true,
},
globals: true,
alias: {
'@/': `${resolve(process.cwd(), 'src')}/`,
},
// include: ['**/*.{client,test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
// root: './src',
}
const isPreview = process.env.PREVIEW && valueToBooleanNotFalse(process.env.PREVIEW)
const isBrowser = process.env.BROWSER && valueToBooleanNotFalse(process.env.BROWSER)
const browserName = {
c: 'chromium',
chromium: 'chromium',
chrome: 'chromium',
g: 'chromium',
google: 'chromium',
e: 'chromium',
edge: 'chromium',
w: 'webkit',
webkit: 'webkit',
s: 'webkit',
safari: 'webkit',
f: 'firefox',
firefox: 'firefox',
}[String(process.env.BROWSER).toLowerCase()] ?? 'chromium'
if (isBrowser || isPreview) {
console.info('BROWSER', browserName, JSON.stringify(process.env.BROWSER))
Object.assign(config, {
include: [
'./src/browser/**/*.{client,test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
'./src/common/**/*.{client,test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
],
exclude: [
'**/_archive/**',
'**/demos/**',
'**/docs/**',
],
browser: {
enabled: true,
name: browserName,
provider: isPreview ? 'preview' : 'playwright', // https://playwright.dev
providerOptions: {
launch: {
devtools: true,
},
},
},
})
}
else {
console.info('NODE')
Object.assign(config, {
setupFiles: ['vitest-setup.ts'],
include: [
'./src/node/**/*.{client,test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
'./src/common/**/*.{client,test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}',
'./src/index.spec.ts',
],
})
}
export default defineConfig({
test: config,
// https://github.com/vitest-dev/vitest/issues/4183
esbuild: {
target: 'es2022',
},
})