mirror of
https://github.com/cloudflare/vinext.git
synced 2026-09-14 19:04:59 +08:00
b5897d0595
* feat(build)!: require Vite 8 * fix(build): remove unused Vite version export * test(link): harden prefetch timing assertions
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import { once } from "node:events";
|
|
import { describe, expect, it } from "vite-plus/test";
|
|
import {
|
|
FIXTURE_HOOK_TIMEOUT_MS,
|
|
FIXTURE_STARTUP_TIMEOUT_MS,
|
|
startFixtureDevServer,
|
|
type FixtureDevServer,
|
|
} from "./fixture-dev-server.js";
|
|
|
|
describe("fixture dev server helper", () => {
|
|
it("keeps Vitest hook timeout above the internal startup timeout", () => {
|
|
expect(FIXTURE_HOOK_TIMEOUT_MS).toBeGreaterThan(FIXTURE_STARTUP_TIMEOUT_MS);
|
|
});
|
|
|
|
it("terminates the child process when startup readiness times out", async () => {
|
|
let fixtureProcess: FixtureDevServer["process"] | undefined;
|
|
|
|
await expect(
|
|
startFixtureDevServer({
|
|
name: "never-ready",
|
|
root: process.cwd(),
|
|
port: 49_999,
|
|
command: {
|
|
bin: process.execPath,
|
|
args: [
|
|
"-e",
|
|
"console.log('server booted but never listened'); setInterval(() => {}, 1000);",
|
|
],
|
|
},
|
|
startupTimeoutMs: 100,
|
|
readinessPollIntervalMs: 10,
|
|
readyRequestTimeoutMs: 20,
|
|
serverSettleDelayMs: 0,
|
|
onSpawn: (proc) => {
|
|
fixtureProcess = proc;
|
|
},
|
|
}),
|
|
).rejects.toThrow(/Fixture "never-ready" did not start within 100ms/);
|
|
|
|
expect(fixtureProcess).toBeDefined();
|
|
// Wait until the child has actually exited. `killed` only means a signal was
|
|
// sent, not that the process is gone — on Windows `stopFixtureDevServer`
|
|
// calls `proc.kill()`, which sets `killed` synchronously while exit is still
|
|
// pending, so gating on `!killed` would skip the wait and read a null code.
|
|
if (fixtureProcess && fixtureProcess.exitCode == null && fixtureProcess.signalCode == null) {
|
|
await once(fixtureProcess, "exit");
|
|
}
|
|
|
|
expect(fixtureProcess?.signalCode ?? fixtureProcess?.exitCode).not.toBeNull();
|
|
});
|
|
});
|