-
Notifications
You must be signed in to change notification settings - Fork 24
/
vitest.config.mjs
68 lines (60 loc) · 1.72 KB
/
vitest.config.mjs
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
import { loadEnv } from 'vite'
import { defineConfig, mergeConfig } from 'vitest/config'
import ViteConfig from './vite.config.mjs'
// See for more details: https://vitest.dev/config/#coverage-exclude
const EXCLUDE_FROM_TESTING = [
// Default exclude patterns
'**/node_modules/**',
'**/dist/**',
'**/cypress/**',
'**/.{idea,git,cache,output,temp}/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
// Custom exclude patterns
'src/**/*.spec.*',
'src/**/*.stories.*',
'src/**/*.mocks.*',
]
const EXCLUDE_FROM_COVERAGE = [
...EXCLUDE_FROM_TESTING,
'src/**/*.test.*',
'repo-test-setup.jsx',
'vitest.setup.ts',
'custom-testing-library.js',
'setupTestGlobal.js',
'setupTests.js',
'setupProxy.js',
'ts-override.d.ts',
'types.ts',
'vite-env.d.ts',
]
const VitestConfig = defineConfig((config) => {
const reporters = ['basic']
if (process.env.ENABLE_TEST_REPORTER) {
reporters.push(['junit', { outputFile: 'reports/junit/junit.xml' }])
}
if (process.env.GITHUB_ACTIONS) {
reporters.push('github-actions')
}
const env = loadEnv(config.mode, process.cwd(), 'REACT_APP')
return {
test: {
env: env,
coverage: {
include: ['src/**/*'],
exclude: EXCLUDE_FROM_COVERAGE,
provider: 'istanbul',
reporters: [['text'], ['html', { outputFile: 'coverage/index.html' }]],
reportOnFailure: true,
},
globals: true,
environment: 'jsdom',
setupFiles: './src/vitest.setup.ts',
reporters: reporters,
include: ['src/**/*.test.*'],
exclude: EXCLUDE_FROM_TESTING,
},
}
})
export default defineConfig((configEnv) =>
mergeConfig(ViteConfig(configEnv), VitestConfig(configEnv))
)