Public: anyone can read this; the crew can change it.
A test pins `navigationBranch`, the release smoke's read of the service worker's navigate branch #6754
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/6751-a-test-pins-navigationbranch-the-release → main 2 commits fork 2 threads · 2 unresolved
1 file
changed +24
−0
test/smoke.test.ts +24
| @@ -161,6 +161,30 @@ test("--outsider without FORGE_TOKEN exits 2 and prints no ok", async () => { | ||
| 161 | 161 | expect(await new Response(proc.stderr).text()).toContain("FORGE_TOKEN"); |
| 162 | 162 | }); |
| 163 | 163 | |
| 164 | test("navigationBranch finds the real service worker's navigate branch, free of Response.error()", async () => { | |
| 165 | const { swSource } = await import("../src/web/sw.ts"); | |
Nit: a static import at the top of the file (as |
||
| 166 | const { navigationBranch } = await import("../src/release/smoke.ts"); | |
| 167 | const nav = navigationBranch(swSource); | |
| 168 | expect(nav).not.toBeNull(); | |
| 169 | expect(nav).toContain("navigate"); | |
| 170 | expect(nav).not.toMatch(/Response\s*\.\s*error\s*\(/); | |
| 171 | }); | |
| 172 | ||
| 173 | test("navigationBranch gives null without a navigate mode", async () => { | |
| 174 | const { navigationBranch } = await import("../src/release/smoke.ts"); | |
| 175 | expect(navigationBranch("self.addEventListener('fetch', function (e) { e.respondWith(fetch(e.request)); });")).toBeNull(); | |
| 176 | }); | |
| 177 | ||
| 178 | test("navigationBranch counts Response.error() inside the branch only, not in comments or after return", async () => { | |
| 179 | const { navigationBranch } = await import("../src/release/smoke.ts"); | |
| 180 | const error = /Response\s*\.\s*error\s*\(/; | |
| 181 | const wrap = (body: string) => `if (e.request.mode === 'navigate') {\n${body}\n return;\n}\nreturn Response.error();`; | |
| 182 | expect(navigationBranch(wrap("// Response.error()\n respond();"))).not.toMatch(error); | |
| 183 | expect(navigationBranch(wrap("/* Response.error() */ respond();"))).not.toMatch(error); | |
| 184 | expect(navigationBranch(wrap("respond(Response.error());"))).toMatch(error); | |
| 185 | expect(navigationBranch(wrap("respond();"))).not.toMatch(error); | |
| 186 | }); | |
| 187 | ||
| 164 | 188 | test("--app-host fails when an app host answers with the forge's page", async () => { |
| 165 | 189 | const forgePage = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => new Response("<title>forge</title>", { headers: { "content-type": "text/html" } }) }); |
| 166 | 190 | const appPage = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch: () => new Response("<title>notes</title>") }); |
new above
offline
Nit: the file already imports statically from ../scripts/smoke.ts. Import navigationBranch and swSource at the top rather than using await import in each test.