From 19e73ca8b1fe02c603a3dcbf0f26f36aee3ee436 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Sat, 21 Feb 2026 08:15:12 +0000 Subject: [PATCH] [vite-plugin] fix: use direct fetch in workflows tests to avoid Windows flakes (#12619) --- .../playground/__test-utils__/responses.ts | 17 +++++++++++++++++ .../__tests__/workflows.spec.ts | 6 +++--- .../workflows/__tests__/workflows.spec.ts | 6 +++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/vite-plugin-cloudflare/playground/__test-utils__/responses.ts b/packages/vite-plugin-cloudflare/playground/__test-utils__/responses.ts index 9387980d9806..cb4f49f8645f 100644 --- a/packages/vite-plugin-cloudflare/playground/__test-utils__/responses.ts +++ b/packages/vite-plugin-cloudflare/playground/__test-utils__/responses.ts @@ -1,5 +1,22 @@ import { page, viteTestUrl } from "./index"; +/** + * Fetches JSON from the server using direct fetch (no browser). + * Use this for tests that only need to hit API endpoints without browser interaction. + * This avoids the race condition in `getJsonResponse` which uses Playwright's + * `page.waitForResponse()` that can hang on Windows. + */ +export async function fetchJson(path = "/"): Promise { + const url = `${viteTestUrl}${path}`; + const response = await fetch(url); + const text = await response.text(); + try { + return JSON.parse(text); + } catch { + throw new Error("Invalid JSON response:\n" + text); + } +} + export async function getTextResponse(path = "/"): Promise { const response = await getResponse(path); return response.text(); diff --git a/packages/vite-plugin-cloudflare/playground/external-workflows/__tests__/workflows.spec.ts b/packages/vite-plugin-cloudflare/playground/external-workflows/__tests__/workflows.spec.ts index aaee94c1da8c..c7606249a4aa 100644 --- a/packages/vite-plugin-cloudflare/playground/external-workflows/__tests__/workflows.spec.ts +++ b/packages/vite-plugin-cloudflare/playground/external-workflows/__tests__/workflows.spec.ts @@ -1,13 +1,13 @@ import { test, vi } from "vitest"; -import { getJsonResponse, WAIT_FOR_OPTIONS } from "../../__test-utils__"; +import { fetchJson, WAIT_FOR_OPTIONS } from "../../__test-utils__"; test("creates a Workflow with an ID", async ({ expect }) => { const instanceId = "external-workflows-test-id"; - await getJsonResponse(`/create?id=${instanceId}`); + await fetchJson(`/create?id=${instanceId}`); await vi.waitFor(async () => { - expect(await getJsonResponse(`/get?id=${instanceId}`)).toEqual({ + expect(await fetchJson(`/get?id=${instanceId}`)).toEqual({ status: "complete", __LOCAL_DEV_STEP_OUTPUTS: [ { output: "First step result" }, diff --git a/packages/vite-plugin-cloudflare/playground/workflows/__tests__/workflows.spec.ts b/packages/vite-plugin-cloudflare/playground/workflows/__tests__/workflows.spec.ts index 37ae032c1b60..eebfa4a99e51 100644 --- a/packages/vite-plugin-cloudflare/playground/workflows/__tests__/workflows.spec.ts +++ b/packages/vite-plugin-cloudflare/playground/workflows/__tests__/workflows.spec.ts @@ -1,13 +1,13 @@ import { test, vi } from "vitest"; -import { getJsonResponse, WAIT_FOR_OPTIONS } from "../../__test-utils__"; +import { fetchJson, WAIT_FOR_OPTIONS } from "../../__test-utils__"; test("creates a Workflow with an ID", async ({ expect }) => { const instanceId = "workflows-test-id"; - await getJsonResponse(`/create?id=${instanceId}`); + await fetchJson(`/create?id=${instanceId}`); await vi.waitFor(async () => { - expect(await getJsonResponse(`/get?id=${instanceId}`)).toEqual({ + expect(await fetchJson(`/get?id=${instanceId}`)).toEqual({ status: "complete", __LOCAL_DEV_STEP_OUTPUTS: [ { output: "First step result" },