-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvitest.config.ts
126 lines (121 loc) · 3.48 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* @file Vitest Configuration
* @module config/vitest
* @see https://vitest.dev/config
*/
import { NodeEnv } from '@flex-development/tutils'
import ci from 'is-ci'
import path from 'node:path'
import type { UserConfig } from 'vite'
import tsconfigpaths from 'vite-tsconfig-paths'
import GithubActionsReporter from 'vitest-github-actions-reporter'
import { BaseSequencer } from 'vitest/node'
/**
* Creates a {@link UserConfig} object for test environments.
*
* @return {UserConfig} Vitest configuration options
*/
const config = (): UserConfig => {
/**
* Absolute path to [experimental loader for Node.js][1].
*
* [1]: https://nodejs.org/docs/latest-v16.x/api/esm.html#loaders
*
* @const {string} NODE_LOADER_PATH
*/
const NODE_LOADER_PATH: string = path.resolve('loader.mjs')
/**
* Absolute path to tsconfig file.
*
* @const {string} TSCONFIG_PATH
*/
const TSCONFIG_PATH: string = path.resolve('tsconfig.json')
return {
define: {
'import.meta.env.CI': JSON.stringify(ci),
'import.meta.env.NODE_ENV': JSON.stringify(NodeEnv.TEST),
'process.env.NODE_OPTIONS': JSON.stringify(`--loader=${NODE_LOADER_PATH}`)
},
mode: NodeEnv.TEST,
plugins: [tsconfigpaths({ projects: [TSCONFIG_PATH] })],
test: {
allowOnly: !ci,
clearMocks: true,
coverage: {
all: true,
clean: true,
exclude: [
'**/__mocks__/**',
'**/__tests__/**',
'**/index.ts',
'src/flags.ts',
'src/options.ts'
],
extension: ['.ts'],
include: ['src'],
reporter: ['json-summary', 'lcov', 'text'],
reportsDirectory: './coverage',
skipFull: false
},
globalSetup: [
'./__tests__/setup/setup.ts',
'./__tests__/setup/teardown.ts'
],
globals: true,
hookTimeout: 10 * 1000,
include: ['**/__tests__/*.spec.ts'],
isolate: true,
mockReset: true,
outputFile: {
json: './__tests__/report.json'
},
passWithNoTests: true,
reporters: [
'json',
'verbose',
ci ? new GithubActionsReporter() : './__tests__/reporters/notifier.ts'
],
/**
* Stores snapshots next to `file`'s directory.
*
* @param {string} file - Path to test file
* @param {string} extension - Snapshot extension
* @return {string} Custom snapshot path
*/
resolveSnapshotPath(file: string, extension: string): string {
return path.resolve(
path.resolve(path.dirname(path.dirname(file)), '__snapshots__'),
path.basename(file).replace(/\.spec.tsx?/, '') + extension
)
},
restoreMocks: true,
root: process.cwd(),
sequence: {
sequencer: class Sequencer extends BaseSequencer {
/**
* Determines test file execution order.
*
* @public
* @override
* @async
*
* @param {string[]} files - Paths to test files
* @return {Promise<string[]>} `files` sorted
*/
public override async sort(files: string[]): Promise<string[]> {
return (await super.sort(files)).sort((a, b) => a.localeCompare(b))
}
}
},
setupFiles: ['./__tests__/setup/index.ts'],
silent: false,
snapshotFormat: {
callToJSON: true,
min: false,
printFunctionName: true
},
testTimeout: 10 * 1000
}
}
}
export default config