-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathvitest.config.js
More file actions
95 lines (90 loc) · 4.15 KB
/
Copy pathvitest.config.js
File metadata and controls
95 lines (90 loc) · 4.15 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
import { defineConfig, configDefaults } from 'vitest/config';
/**
* Test-runtime unhandled-error policy (v0.9.3 — issues #1186 / #1152)
* ------------------------------------------------------------------
* Two unhandled-error patterns surface intermittently during the full
* `make test` run even though every test asserts pass and the suite
* is otherwise clean. Both are test-runtime cross-pollination noise,
* not application bugs:
*
* 1. happy-dom + undici WebSocket dispatchEvent (#1186, P1):
* undici's WebSocket calls `fireEvent` constructing a Node-side
* `Event` object; happy-dom's `EventTarget.dispatchEvent` runtime
* check rejects it because the two runtimes don't share the
* Web-platform Event prototype. The error fires from
* `WebSocket.dispatchEvent` deep in node_modules and never
* propagates into a test assertion.
*
* 2. view-transitions teardown (#1152, P2):
* Non-deterministic `EnvironmentTeardownError: Closing rpc while
* "onUserConsoleLog" was pending` during teardown of
* `tests/js/view-transitions.test.js`. The test stubs already
* yield a microtask before invoking the inner callback (per CLAUDE.md
* retro #1113), so this is RPC-timing teardown noise, not a stub
* regression.
*
* Both are filtered here rather than worked around in test files so the
* suppression is centralized and reviewable. Each pattern matches on
* narrow `message` + `stack` substrings — anything else still re-throws.
*
* TODO(#1186 v0.9.4+): replace WebSocket filter with a proper happy-dom
* WebSocket stub or upstream-fixed happy-dom version.
*/
export default defineConfig({
test: {
environment: 'happy-dom',
globals: true,
// Don't discover tests inside agent git worktrees (`.claude/worktrees/*`)
// or other `.claude/` internals — those are other branches' checkouts and
// running their (possibly stale) test copies against this tree's built
// client.js produces spurious failures. Preserve vitest's defaults.
//
// `.django-src/` is the same situation (#2637): the gitignored Django
// checkout `make django-template-suite` creates carries Django's own
// QUnit admin tests, which cannot run under vitest and are not ours.
exclude: [...configDefaults.exclude, '**/.claude/**', '**/.django-src/**'],
onUnhandledError(error) {
const msg = String(error && error.message ? error.message : '');
const stack = String(error && error.stack ? error.stack : '');
// Pattern 1: happy-dom + undici WebSocket dispatchEvent (#1186)
if (
msg.includes("Failed to execute 'dispatchEvent' on 'EventTarget'") &&
(stack.includes('undici/lib/web/websocket') ||
stack.includes('happy-dom/lib/event/EventTarget'))
) {
return false;
}
// Pattern 2: view-transitions teardown (#1152)
// Match only the diagnosed cause: vitest's `Closing rpc` teardown
// signature paired with the specific console-log RPC handler that
// had a pending call when the environment was torn down. The
// earlier broader `stack.includes('view-transitions')` disjunct
// (PR #1187) widened the net beyond the diagnosed shape — closes
// #1188 🟡 #1.
if (
msg.includes('Closing rpc') &&
(msg.includes('onUserConsoleLog') || msg.includes('onConsoleLog'))
) {
return false;
}
// Pattern 3: undici socket `setTypeOfService` EINVAL (macOS).
// Node's built-in fetch sets the IP type-of-service on each new
// socket; on recent macOS the kernel rejects it with EINVAL for some
// sockets. It fires from undici's HTTP/1 writer after a test's
// relative fetch() resolves against happy-dom's localhost origin,
// and vitest attributes it to whichever file is running then. It
// is a host-socket error, never an assertion; nothing else is
// filtered by it.
if (
error &&
error.code === 'EINVAL' &&
error.syscall === 'setTypeOfService' &&
stack.includes('undici')
) {
return false;
}
// Anything else — let vitest surface it.
return true;
},
},
});