-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,5 @@ | ||
# https://github.com/nix-community/nix-direnv | ||
if ! has nix_direnv_version || ! nix_direnv_version 3.0.6; then | ||
source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/3.0.6/direnvrc" "sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=" | ||
fi | ||
use flake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,8 @@ jobs: | |
|
||
- uses: HatsuneMiku3939/direnv-action@v1 | ||
|
||
- run: nix flake check | ||
|
||
- run: bun install | ||
|
||
- run: tsc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ jobs: | |
|
||
- uses: HatsuneMiku3939/direnv-action@v1 | ||
|
||
- run: nix flake check | ||
|
||
- run: bun install | ||
|
||
- run: tsc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { afterEach, expect, test } from "bun:test"; | ||
import { copyFileSync, mkdtempSync } from "node:fs"; | ||
import { chromium } from "playwright"; | ||
|
||
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" }, | ||
}, { autoReload: false }); | ||
}), | ||
}); | ||
`; | ||
|
||
let close: () => Promise<void> | undefined; | ||
|
||
afterEach(async () => { | ||
await close?.(); | ||
}); | ||
|
||
test("can disable auto reload", async () => { | ||
const systemTmp = process.env["TMPDIR"] ?? "/tmp"; | ||
const tmpdir = mkdtempSync(`${systemTmp}/bun-`); | ||
const serverPath = `${tmpdir}/server.ts`; | ||
const libPath = `${tmpdir}/bun-html-live-reload.ts`; | ||
|
||
await Bun.write(serverPath, serverCodeInit); | ||
|
||
copyFileSync(`${import.meta.dir}/index.ts`, libPath); | ||
|
||
const child = Bun.spawn(["bun", "--hot", serverPath], { stderr: "ignore" }); | ||
|
||
const browser = await chromium.launch(); | ||
|
||
close = async (): Promise<void> => { | ||
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, serverCodeInit); | ||
await page.waitForEvent("framenavigated"); | ||
|
||
expect(await page.innerText("div")).toBe("Init"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters