diff --git a/test/api-hmr.test.ts b/test/api-hmr.test.ts deleted file mode 100644 index e13e5c66..00000000 --- a/test/api-hmr.test.ts +++ /dev/null @@ -1,88 +0,0 @@ -import { expect, test } from "@playwright/test"; - -import type { - AppFixture, - DevFixture, - Fixture, -} from "./helpers/create-fixture.js"; -import { - createDevFixture, - createFixture, - js, -} from "./helpers/create-fixture.js"; -import { - PlaywrightFixture, - prettyHtml, - selectHtml, -} from "./helpers/playwright-fixture.js"; - -test.describe("api hmr", () => { - let fixture: DevFixture; - let appFixture: AppFixture; - // test.skip(process.env.START_ADAPTER !== "solid-start-node"); - - test.beforeAll(async () => { - fixture = await createDevFixture({ - files: {}, - }); - - appFixture = await fixture.createServer(); - }); - - test.afterAll(async () => { - await appFixture.close(); - }); - - let logs: string[] = []; - - test.beforeEach(({ page }) => { - page.on("console", (msg) => { - logs.push(msg.text()); - }); - }); - - test.afterEach(async () => { - await fixture.reset(); - }); - - test("hmr api", async () => { - let res = await fixture.requestDocument("/api/hello"); - expect(res.status).toBe(200); - expect(res.headers.get("Content-Type")).toBe("text/html"); - expect(await res.text()).toBe("Hello world"); - - await fixture.updateFile( - "app/api/hello.ts", - js`export default function handler(event) { - return "Hello world too"; - }`, - ); - - await new Promise((r) => setTimeout(r, 1000)); - - res = await fixture.requestDocument("/api/hello"); - expect(res.status).toBe(200); - expect(res.headers.get("Content-Type")).toBe("text/html"); - expect(await res.text()).toBe("Hello world too"); - - await fixture.updateFile( - "app/api/new.ts", - js`export default function handler(event) { - return "Hello new"; - }`, - ); - - await new Promise((r) => setTimeout(r, 1000)); - - res = await fixture.requestDocument("/api/new"); - expect(res.status).toBe(200); - expect(res.headers.get("Content-Type")).toBe("text/html"); - expect(await res.text()).toBe("Hello new"); - - await fixture.deleteFile("app/api/new.ts"); - - await new Promise((r) => setTimeout(r, 1000)); - res = await fixture.requestDocument("/api/new"); - expect(res.status).toBe(404); - }); -}); diff --git a/test/basic-dev.test.ts b/test/basic-dev.test.ts index a9cae7db..c994cec1 100644 --- a/test/basic-dev.test.ts +++ b/test/basic-dev.test.ts @@ -19,32 +19,7 @@ test.describe("rendering", () => { test.beforeAll(async () => { fixture = await createDevFixture({ - files: { - "app/root.tsx": js` - import { useState } from "react"; - - export default function App({ assets }) { - const [count, setCount] = useState(0); - return ( - - - - {assets} - - -
-

Hello from Vinxi

- - {count} -
- - - ); - } - `, - }, + files: {}, }); appFixture = await fixture.createServer(); @@ -88,4 +63,11 @@ test.describe("rendering", () => { prettyHtml(`1`), ); }); + + test("api", async () => { + let res = await fixture.requestDocument("/api/hello"); + expect(res.status).toBe(200); + expect(res.headers.get("Content-Type")).toBe("text/html"); + expect(await res.text()).toBe("Hello world"); + }); }); diff --git a/test/basic.test.ts b/test/basic.test.ts index ebfbf870..2fcdb65e 100644 --- a/test/basic.test.ts +++ b/test/basic.test.ts @@ -15,32 +15,7 @@ test.describe("rendering", () => { test.beforeAll(async () => { fixture = await createFixture({ - files: { - "app/root.tsx": js` - import { useState } from "react"; - - export default function App({ assets }) { - const [count, setCount] = useState(0); - return ( - - - - {assets} - - -
-

Hello from Vinxi

- - {count} -
- - - ); - } - `, - }, + files: {}, }); appFixture = await fixture.createServer(); @@ -84,4 +59,11 @@ test.describe("rendering", () => { prettyHtml(`1`), ); }); + + test("api", async () => { + let res = await fixture.requestDocument("/api/hello"); + expect(res.status).toBe(200); + expect(res.headers.get("Content-Type")).toBe("text/html"); + expect(await res.text()).toBe("Hello world"); + }); }); diff --git a/test/hmr.test.ts b/test/hmr.test.ts index 9667862a..f405ea23 100644 --- a/test/hmr.test.ts +++ b/test/hmr.test.ts @@ -125,4 +125,45 @@ test.describe("rendering", () => { prettyHtml(``), ); }); + + test("hmr api", async () => { + let res = await fixture.requestDocument("/api/hello"); + expect(res.status).toBe(200); + expect(res.headers.get("Content-Type")).toBe("text/html"); + expect(await res.text()).toBe("Hello world"); + + await fixture.updateFile( + "app/api/hello.ts", + js`export default function handler(event) { + return "Hello world too"; + }`, + ); + + await new Promise((r) => setTimeout(r, 1000)); + + res = await fixture.requestDocument("/api/hello"); + expect(res.status).toBe(200); + expect(res.headers.get("Content-Type")).toBe("text/html"); + expect(await res.text()).toBe("Hello world too"); + + await fixture.updateFile( + "app/api/new.ts", + js`export default function handler(event) { + return "Hello new"; + }`, + ); + + await new Promise((r) => setTimeout(r, 1000)); + + res = await fixture.requestDocument("/api/new"); + expect(res.status).toBe(200); + expect(res.headers.get("Content-Type")).toBe("text/html"); + expect(await res.text()).toBe("Hello new"); + + await fixture.deleteFile("app/api/new.ts"); + + await new Promise((r) => setTimeout(r, 1000)); + res = await fixture.requestDocument("/api/new"); + expect(res.status).toBe(404); + }); });