From 2ee8d82d5a7e5adb0a52e6f6c761741955359664 Mon Sep 17 00:00:00 2001 From: "github.sudoku" <49580702+forcingfx@users.noreply.github.com> Date: Wed, 9 Sep 2026 22:24:50 +0200 Subject: [PATCH] test: keep the unit suite off the network MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit What: every 'npm test' run printed ~30 lines of ECONNREFUSED / AbortError / AsyncTaskManager stack traces. All tests passed, so nobody looked. Why: two sources. (1) happy-dom is a real resource loader: and '; + await settle(); + + expect(request).not.toHaveBeenCalled(); + }); +}); diff --git a/tests/pages/billing-success.test.tsx b/tests/pages/billing-success.test.tsx index ca5e31de..dc3add25 100644 --- a/tests/pages/billing-success.test.tsx +++ b/tests/pages/billing-success.test.tsx @@ -1,4 +1,4 @@ -import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"; +import { describe, it, expect, vi, beforeEach, afterEach, type Mock } from "vitest"; import { render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { MemoryRouter } from "react-router"; @@ -33,6 +33,21 @@ function renderWithRoute(path: string) { } describe("BillingSuccess page", () => { + // Rendering with a session_id makes the page request the license for that + // session on mount. Tests that only assert copy never stubbed fetch, so + // happy-dom opened a real socket to localhost:3000 on every run. A default + // pending stub keeps the page in its initial state, which is what those + // tests were observing anyway; tests that need a response override it. + beforeEach(() => { + vi.stubGlobal( + "fetch", + vi.fn(() => new Promise(() => {})), + ); + }); + afterEach(() => { + vi.unstubAllGlobals(); + }); + it("renders a confirmation heading", () => { renderWithRoute("/billing/success"); expect( @@ -48,6 +63,12 @@ describe("BillingSuccess page", () => { expect( screen.getByRole("button", { name: /save/i }), ).toBeInTheDocument(); + // The page asks the server for this session's license rather than + // waiting for the user to paste — the input is the fallback. + const calls = (globalThis.fetch as unknown as Mock).mock.calls as Array< + [RequestInfo | URL, RequestInit?] + >; + expect(calls.some(([url]) => String(url).includes("/api/license/retrieve"))).toBe(true); }); it("does NOT render the session id as page chrome on the polling-state happy path", async () => { diff --git a/vitest.config.js b/vitest.config.js index e8d38e2c..59673d09 100644 --- a/vitest.config.js +++ b/vitest.config.js @@ -10,6 +10,21 @@ export default defineConfig({ }, test: { environment: "happy-dom", + // happy-dom is a real resource loader: a or + //