Repository navigation
Expand file tree
/
Copy pathvitest.config.ts
More file actions
234 lines (228 loc) · 7.59 KB
/
Copy pathvitest.config.ts
File metadata and controls
234 lines (228 loc) · 7.59 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
// used for unit tests from test/unit
import { defineConfig } from "vitest/config";
import path, { resolve } from "node:path";
import { readFileSync } from "node:fs";
import vue from "@vitejs/plugin-vue";
// Prefer __dirname here (same as als_root/mcp_root below). Do not import
// ./test/setup — eslint no-restricted-imports bans relative imports, and
// @test/* aliases are not available while this config file is loading.
const alsPackageVersion = (
JSON.parse(
readFileSync(
resolve(__dirname, "packages/ansible-language-server/package.json"),
"utf8",
),
) as { version: string }
).version;
// see https://vitest.dev/guide/migration.html
// we use this approach because it allows 'knip' to also detect the imports
// otherwise it gets confused about projects use in config and fail to
// resolve the relative paths, as each path is relative to the root of the
// current project.
const als_root = resolve(__dirname, "packages", "ansible-language-server");
const mcp_root = resolve(__dirname, "packages", "ansible-mcp-server");
// ALS unit tests use podman/docker and a Linux-oriented toolchain; skip on Windows
// (matches packages/ansible-language-server/Taskfile.yml test platforms).
const skipAlsTests = process.platform === "win32";
// Save real HOME before any globalSetup overrides it.
// ALS @ee tests need the original HOME — rootless podman is ~60x slower
// with a redirected HOME directory.
if (!skipAlsTests) {
process.env._ALS_ORIGINAL_HOME =
process.env.HOME || process.env.USERPROFILE || "";
}
const reporters = ["default", "junit"]; // text-summary shows only overall coverage stats, skipping per-file details
if (process.env.GITHUB_ACTIONS) {
reporters.push("github-actions");
}
// Disable coverage when the user is running a targeted subset of tests, e.g.:
// vitest -t "my test name"
// vitest run src/foo.test.ts
// Partial runs produce misleading (always-low) coverage numbers and slow down
// the interactive feedback loop.
const vitestSubcommands = new Set([
"run",
"watch",
"dev",
"bench",
"list",
"typecheck",
]);
const isFiltered = process.argv.slice(2).some((arg) => {
if (arg === "-t" || arg === "--testNamePattern") return true;
// A positional arg that is not a flag and not a vitest subcommand is a file filter
return !arg.startsWith("-") && !vitestSubcommands.has(arg);
});
const alsVitestProject = {
extends: true as const,
define: {
// Match tsdown define so importing src/cli.ts in unit tests works.
PACKAGE_VERSION: JSON.stringify(alsPackageVersion),
},
resolve: {
alias: {
"@root": path.resolve(__dirname),
"@src": path.resolve(als_root, "src"),
"@test": path.resolve(als_root, "test"),
},
},
test: {
name: "als",
globals: true,
globalSetup: [`${als_root}/test/globalSetup.ts`],
environment: "node",
exclude: ["node_modules", "out"],
fileParallelism: false,
include: ["test/**/*.test.ts"],
isolate: true, // required or will produce MaxListenersExceededWarning warnings
root: als_root, // ensure reports have valid paths
testTimeout: 60000, // same as mocha timeout (60 seconds)
hookTimeout: 30000, // self-hosted WSL runner needs more than the 10s default
setupFiles: [`${als_root}/test/vitestSetup.ts`],
env: {
// ALS @ee unit tests only: runner ~/.ansible collections break completion ordering.
...(process.env.CI === "true"
? { ALS_EE_COLLECTIONS_PREPEND: "/usr/share/ansible/collections" }
: {}),
},
sequence: {
concurrent: false,
groupOrder: 2,
},
//slowTestThreshold: 8000, // tests with >8s will show duration in yellow/red
},
};
export default defineConfig({
test: {
name: "ext",
projects: [
{
extends: true,
test: {
name: "ext",
globals: true,
globalSetup: ["test/unit/globalSetup.ts"],
environment: "node",
fileParallelism: false,
include: ["test/unit/**/*.test.ts"],
exclude: ["test/unit/webviews/**"],
setupFiles: ["./test/unit/vitestSetup.ts"],
sequence: {
// After mcp (1) and als @ee/podman (2); CLI smokes must not run during ALS tests
groupOrder: 3,
},
},
},
{
extends: true,
plugins: [
vue({
template: {
compilerOptions: {
isCustomElement: (tag: string) => tag.startsWith("vscode-"),
},
},
}),
],
test: {
name: "vue",
globals: true,
environment: "jsdom",
include: ["test/unit/webviews/**/*.test.ts"],
setupFiles: ["./test/unit/webviews/vitestSetup.ts"],
exclude: [],
},
},
...(skipAlsTests ? [] : [alsVitestProject]),
{
extends: true,
resolve: {
alias: {
"@src": path.resolve(mcp_root, "src"),
"@test": path.resolve(mcp_root, "test"),
},
},
test: {
name: "mcp",
globals: true,
environment: "node",
exclude: ["test/fixtures/**"],
include: ["test/**/*.test.ts"],
root: mcp_root,
sequence: {
concurrent: false,
groupOrder: 1,
},
testTimeout: process.platform === "darwin" ? 60000 : 30000, // mac GHA: slow ansible-navigator spawns
},
},
],
environment: "node",
globals: true,
silent: true,
coverage: {
// cannot be configured for sub-projects
allowExternal: false,
cleanOnRerun: true,
clean: true,
enabled: !isFiltered,
exclude: [
// Pure bootstrap/demo webview entrypoints (createApp().mount() glue / demo)
"webviews/lightspeed/src/explanation.ts",
"webviews/lightspeed/src/hello-world.ts",
"webviews/lightspeed/src/playbook-generation.ts",
"webviews/lightspeed/src/role-generation.ts",
"webviews/lightspeed/src/HelloWorld.vue",
"webviews/lightspeed/src/explorer.ts",
],
include: [
"src/**/**.{js,jsx,ts,tsx}",
...(skipAlsTests
? []
: ["packages/ansible-language-server/src/**/*.{js,jsx,ts,tsx}"]),
"packages/ansible-mcp-server/src/**/*.{js,jsx,ts,tsx}",
"webviews/**/*.{ts,vue}",
], // Include source files, workspace packages, and webviews for coverage
provider: "v8",
reportOnFailure: false,
reportsDirectory: `${__dirname}/out/coverage/unit`,
reporter: [
["lcovonly", { file: "lcov.info", projectRoot: __dirname }],
"text-summary",
"text",
],
skipFull: true,
thresholds: {
// We cannot enable until we normalize the results across all platforms.
// autoUpdate:
// process.platform === "linux" && process.env.IS_WSL !== "1"
// ? (newThreshold: number) => Math.floor(newThreshold)
// : false,
branches: 42,
},
watermarks: {
branches: [0, 44],
functions: [0, 51],
lines: [0, 49],
statements: [0, 49],
},
},
outputFile: {
// cannot be configured for sub-projects
junit: resolve(__dirname, "out/junit/unit-test-results.xml"),
},
reporters: reporters,
slowTestThreshold: 25000,
testTimeout: 30003,
watch: false,
},
resolve: {
alias: {
vscode: path.resolve(__dirname, "./test/unit/mocks/vscode.ts"),
"@src": path.resolve(__dirname, "src"),
"@webviews": path.resolve(__dirname, "webviews"),
"@test": path.resolve(__dirname, "test"),
"@root": path.resolve(__dirname),
},
},
});