Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<unknown> {
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<string> {
const response = await getResponse(path);
return response.text();
Expand Down
Original file line number Diff line number Diff line change
@@ -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" },
Expand Down
Original file line number Diff line number Diff line change
@@ -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" },
Expand Down
Loading