mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-06-05 12:44:22 +00:00
fix(test): drain React scheduler macrotask before jsdom teardown
React 19 defers passive-effect flushes onto a setImmediate callback that reads window.event. When one was still queued as vitest tore down the jsdom environment, it fired after window was deleted and surfaced as an unhandled 'window is not defined' error, failing the run with exit 1 despite all tests passing. Drain the macrotask queue in afterEach so any pending callback runs while window still exists.
This commit is contained in:
parent
cfd3b34362
commit
ed21cf836d
2 changed files with 14 additions and 2 deletions
|
|
@ -292,7 +292,7 @@ export const InboundSchema = z.object({
|
|||
listen: z.string(),
|
||||
nodeId: z.number().int().nullable().optional(),
|
||||
port: z.number().int().min(1).max(65535),
|
||||
protocol: z.enum(['vmess', 'vless', 'trojan', 'shadowsocks', 'wireguard', 'hysteria', 'http', 'mixed', 'tunnel']),
|
||||
protocol: z.enum(['vmess', 'vless', 'trojan', 'shadowsocks', 'wireguard', 'hysteria', 'http', 'mixed', 'tunnel', 'tun']),
|
||||
remark: z.string(),
|
||||
settings: z.unknown(),
|
||||
sniffing: z.unknown(),
|
||||
|
|
|
|||
|
|
@ -58,7 +58,19 @@ if (!i18next.isInitialized) {
|
|||
});
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
afterEach(async () => {
|
||||
cleanup();
|
||||
document.body.innerHTML = '';
|
||||
/*
|
||||
* React 19 defers passive-effect flushes onto a macrotask (setImmediate),
|
||||
* whose callback reads `window.event`. If one is still queued when vitest
|
||||
* tears down the jsdom environment, it fires after `window` is gone and
|
||||
* throws "window is not defined". Drain a few macrotask ticks here so any
|
||||
* pending callback runs while `window` still exists. Several ticks are used
|
||||
* because a microtask resolving mid-drain (rc-trigger/AntD) can queue a new
|
||||
* one behind the first.
|
||||
*/
|
||||
for (let i = 0; i < 3; i += 1) {
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue