@naturalcycles/dev-lib 16.3.0 → 16.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cfg/vitest.config.mjs +75 -42
- package/package.json +1 -1
package/cfg/vitest.config.mjs
CHANGED
|
@@ -1,52 +1,18 @@
|
|
|
1
1
|
import fs from 'node:fs'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
)
|
|
9
|
-
|
|
10
|
-
if (runsInIDE) {
|
|
11
|
-
silent = false
|
|
12
|
-
|
|
13
|
-
if (process.argv.some(a => a.endsWith('.integration.test.ts'))) {
|
|
14
|
-
testType = 'integration'
|
|
15
|
-
} else if (process.argv.some(a => a.endsWith('.manual.test.ts'))) {
|
|
16
|
-
testType = 'manual'
|
|
17
|
-
}
|
|
18
|
-
} else {
|
|
19
|
-
silent = isRunningAllTests()
|
|
20
|
-
}
|
|
21
|
-
|
|
3
|
+
const runsInIDE = doesItRunInIDE()
|
|
4
|
+
const testType = getTestType(runsInIDE)
|
|
5
|
+
const silent = shouldBeSilent(runsInIDE)
|
|
6
|
+
const setupFiles = getSetupFiles(testType)
|
|
7
|
+
const { include, exclude } = getIncludeAndExclude(testType)
|
|
22
8
|
const isCI = !!process.env['CI']
|
|
23
|
-
|
|
9
|
+
const junitReporterEnabled = isCI && testType !== 'manual'
|
|
10
|
+
process.env.TZ ||= 'UTC'
|
|
11
|
+
|
|
24
12
|
if (testType === 'unit') {
|
|
25
13
|
process.env['APP_ENV'] = process.env['APP_ENV'] || 'test'
|
|
26
14
|
}
|
|
27
15
|
|
|
28
|
-
// Set 'setupFiles' only if setup files exist
|
|
29
|
-
const setupFiles = []
|
|
30
|
-
if (fs.existsSync(`./src/test/setupVitest.ts`)) {
|
|
31
|
-
setupFiles.push('./src/test/setupVitest.ts')
|
|
32
|
-
}
|
|
33
|
-
if (fs.existsSync(`./src/test/setupVitest.${testType}.ts`)) {
|
|
34
|
-
setupFiles.push(`./src/test/setupVitest.${testType}.ts`)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let include
|
|
38
|
-
const exclude = ['**/__exclude/**']
|
|
39
|
-
|
|
40
|
-
if (testType === 'integration') {
|
|
41
|
-
include = ['{src,scripts}/**/*.integration.test.ts']
|
|
42
|
-
} else if (testType === 'manual') {
|
|
43
|
-
include = ['{src,scripts}/**/*.manual.test.ts']
|
|
44
|
-
} else {
|
|
45
|
-
// normal unit test
|
|
46
|
-
include = ['{src,scripts}/**/*.test.ts']
|
|
47
|
-
exclude.push('**/*.{integration,manual}.test.*')
|
|
48
|
-
}
|
|
49
|
-
|
|
50
16
|
if (silent) {
|
|
51
17
|
process.env['TEST_SILENT'] = 'true'
|
|
52
18
|
}
|
|
@@ -69,6 +35,18 @@ export const sharedConfig = {
|
|
|
69
35
|
},
|
|
70
36
|
include,
|
|
71
37
|
exclude,
|
|
38
|
+
reporters: [
|
|
39
|
+
'default',
|
|
40
|
+
junitReporterEnabled && [
|
|
41
|
+
'junit',
|
|
42
|
+
{
|
|
43
|
+
suiteName: `${testType} tests`,
|
|
44
|
+
// classNameTemplate: '{filename} - {classname}',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
].filter(Boolean),
|
|
48
|
+
// outputFile location is specified for compatibility with the previous jest config
|
|
49
|
+
outputFile: junitReporterEnabled ? `./tmp/jest/${testType}.xml` : undefined,
|
|
72
50
|
coverage: {
|
|
73
51
|
enabled: isCI && testType === 'unit',
|
|
74
52
|
reporter: ['html', 'lcov', 'json', !isCI && 'text'].filter(Boolean),
|
|
@@ -94,6 +72,32 @@ export const sharedConfig = {
|
|
|
94
72
|
},
|
|
95
73
|
}
|
|
96
74
|
|
|
75
|
+
function doesItRunInIDE() {
|
|
76
|
+
return process.argv.some(
|
|
77
|
+
a => a === '--runTestsByPath' || a.includes('IDEA') || a.includes('Visual Studio'),
|
|
78
|
+
)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function getTestType(runsInIDE) {
|
|
82
|
+
if (runsInIDE) {
|
|
83
|
+
if (process.argv.some(a => a.endsWith('.integration.test.ts'))) {
|
|
84
|
+
return 'integration'
|
|
85
|
+
}
|
|
86
|
+
if (process.argv.some(a => a.endsWith('.manual.test.ts'))) {
|
|
87
|
+
return 'manual'
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return process.env['TEST_TYPE'] || 'unit'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function shouldBeSilent(runsInIDE) {
|
|
95
|
+
if (runsInIDE) {
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
return isRunningAllTests()
|
|
99
|
+
}
|
|
100
|
+
|
|
97
101
|
/**
|
|
98
102
|
* Detects if vitest is run with all tests, or with selected individual tests.
|
|
99
103
|
*/
|
|
@@ -114,3 +118,32 @@ function isRunningAllTests() {
|
|
|
114
118
|
|
|
115
119
|
return !hasPositionalArgs
|
|
116
120
|
}
|
|
121
|
+
|
|
122
|
+
function getSetupFiles(testType) {
|
|
123
|
+
// Set 'setupFiles' only if setup files exist
|
|
124
|
+
const setupFiles = []
|
|
125
|
+
if (fs.existsSync(`./src/test/setupVitest.ts`)) {
|
|
126
|
+
setupFiles.push('./src/test/setupVitest.ts')
|
|
127
|
+
}
|
|
128
|
+
if (fs.existsSync(`./src/test/setupVitest.${testType}.ts`)) {
|
|
129
|
+
setupFiles.push(`./src/test/setupVitest.${testType}.ts`)
|
|
130
|
+
}
|
|
131
|
+
return setupFiles
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getIncludeAndExclude(testType) {
|
|
135
|
+
let include
|
|
136
|
+
const exclude = ['**/__exclude/**']
|
|
137
|
+
|
|
138
|
+
if (testType === 'integration') {
|
|
139
|
+
include = ['{src,scripts}/**/*.integration.test.ts']
|
|
140
|
+
} else if (testType === 'manual') {
|
|
141
|
+
include = ['{src,scripts}/**/*.manual.test.ts']
|
|
142
|
+
} else {
|
|
143
|
+
// normal unit test
|
|
144
|
+
include = ['{src,scripts}/**/*.test.ts']
|
|
145
|
+
exclude.push('**/*.{integration,manual}.test.*')
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return { include, exclude }
|
|
149
|
+
}
|