Skip to content

Commit

Permalink
Refactor: Simplify test command in deploy and test workflows, delete …
Browse files Browse the repository at this point in the history
…unused files.
  • Loading branch information
aabccd021 committed Dec 6, 2024
1 parent 52b6603 commit 5133439
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- run: bun run typescript-check

- run: bun test/reloads.ts
- run: bun test

- uses: JS-DevTools/npm-publish@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:

- run: bun run typescript-check

- run: bun test/reloads.ts
- run: bun test
9 changes: 0 additions & 9 deletions example.ts

This file was deleted.

63 changes: 63 additions & 0 deletions reload.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { chromium } from "playwright";
import * as fs from "fs";
import { afterEach, expect, test } from "bun:test";

const serverCodeInit = `
import { withHtmlLiveReload } from "./bun-html-live-reload.ts";
Bun.serve({
fetch: withHtmlLiveReload(async () => {
return new Response("<div>Init</div>", {
headers: { "Content-Type": "text/html" },
});
}),
});
`;

const serverCodeChanged = `
import { withHtmlLiveReload } from "./bun-html-live-reload.ts";
Bun.serve({
fetch: withHtmlLiveReload(async () => {
return new Response("<div>Changed</div>", {
headers: { "Content-Type": "text/html" },
});
}),
});
`;

let close: () => Promise<void> | undefined;

afterEach(async () => {
await close?.();
})

test("hot reload works", async () => {
const systemTmp = process.env["TMPDIR"] ?? "/tmp";
const tmpdir = fs.mkdtempSync(`${systemTmp}/bun-`);
const serverPath = `${tmpdir}/server.ts`;
const libPath = `${tmpdir}/bun-html-live-reload.ts`;

await Bun.write(serverPath, serverCodeInit);

fs.copyFileSync(`${import.meta.dir}/index.ts`, libPath);

const child = Bun.spawn(["bun", "--hot", serverPath], { stderr: "ignore" });

const browser = await chromium.launch();

close = async () => {
child?.kill();
await browser.close();
};

const context = await browser.newContext();
const page = await context.newPage();
await page.goto("http://localhost:3000");

expect(await page.innerText("div")).toBe("Init");

await Bun.write(serverPath, serverCodeChanged);
await page.waitForEvent("framenavigated");

expect(await page.innerText("div")).toBe("Changed");
});
41 changes: 0 additions & 41 deletions test/reloads.ts

This file was deleted.

0 comments on commit 5133439

Please sign in to comment.