Skip to content

Commit 381c45f

Browse files
authored
fix: minor cleanup (#2)
1 parent eb4dad5 commit 381c45f

10 files changed

Lines changed: 393 additions & 209 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ concurrency:
1010
cancel-in-progress: true
1111

1212
jobs:
13-
lint:
13+
test:
1414
runs-on: ubuntu-latest
1515
steps:
1616
- uses: actions/checkout@v6
@@ -20,3 +20,11 @@ jobs:
2020
- run: corepack enable
2121
- run: pnpm i
2222
- run: pnpm lint-check
23+
- run: pnpm exec playwright install chromium --with-deps --no-shell
24+
- run: pnpm test-e2e
25+
- uses: actions/upload-artifact@v7
26+
if: failure()
27+
with:
28+
name: playwright-report
29+
path: test-results/
30+
retention-days: 7

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
node_modules
2-
.wrangler
2+
test-results

docs/prd.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@
77
- [x] chore: add example zip from vitest html artifact
88
- [x] `?url=` param for public URLs (GitHub artifact download requires auth, but pre-signed Azure blob URLs and S3 buckets work)
99
- [x] File picker button (not just drag-and-drop) — mobile/accessibility
10-
- [ ] refactor: rework code
11-
- deduplicate fflate import (script tag on line 6 is dead weight, only the ES module import is needed)
12-
- share constants (CACHE_NAME, PREFIX) between index.html and sw.js instead of duplicating
13-
- move MIME map to sw.js (it's serving the files, not the main thread)
14-
- add try/catch around unzipSync for corrupt/non-zip files
15-
- consider async unzip for large zips (fflate has async `unzip`)
16-
- SW scope may break under subpath hosting
17-
- [ ] "Load another zip" button — currently the drop zone hides permanently after first load, no way to swap without refresh
10+
- [x] refactor: remove dead fflate script tag, use single ESM import
11+
- [x] refactor: fix XSS in fetch error display (Preact escapes by default)
12+
- [x] refactor: parallelize cache.put() with Promise.all
13+
- [x] refactor: consider async unzip for large zips (fflate has async `unzip`)
14+
- [x] refactor: add try/catch around unzipSync for corrupt/non-zip files
15+
- [x] refactor: SW ready blocks event listeners — make non-blocking, show "registering…" status
16+
- [ ] refactor: share constants (CACHE_NAME, PREFIX) between index.html and sw.js
17+
- [ ] refactor: extract `<style>` block from index.html to style.css
18+
- [ ] refactor: subpath hosting — PREFIX is hardcoded to `/zipview/site/`; real fix derives it dynamically from location.pathname (also affects sw.js scope and startsWith check)
19+
- [x] setup e2e
20+
21+
## Backlog
22+
1823
- [ ] Persist last zip in IndexedDB so refresh doesn't lose state
19-
- [ ] Multi-zip / tabbed view — drop multiple zips, or auto-detect multiple dirs in one zip
20-
- [ ] Publish as `npx zipview`
21-
- [ ] Self-bootstrapping: embed SW in the static site output itself so the zip is directly openable
24+
- [ ] Provide CLI / API to package SPA into "index.html + sw.js" bundle
25+
- [ ] Integrate as Vitest html reporter two files mode

e2e/basic.spec.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect, Page, test } from "@playwright/test";
2+
3+
test("example", async ({ page }) => {
4+
await page.goto("/");
5+
await expect(page.getByTestId("status")).toContainText("Service worker ready");
6+
await page.getByText("example").click();
7+
await testHtmlReport(page);
8+
});
9+
10+
test("file input", async ({ page }) => {
11+
await page.goto("/");
12+
await expect(page.getByTestId("status")).toContainText("Service worker ready");
13+
await page.locator('input[type="file"]').setInputFiles("docs/assets/vitest-html-reporter.zip");
14+
await testHtmlReport(page);
15+
});
16+
17+
async function testHtmlReport(page: Page) {
18+
await expect(page.getByTestId("status")).toContainText("Cached 7 files");
19+
const frame = page.frameLocator("iframe");
20+
await expect(frame.getByTestId("pass-entry")).toHaveText("6 Pass");
21+
}

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
"scripts": {
66
"prepare": "vp config",
77
"dev": " sirv ./src --dev --single",
8-
"lint": "vp fmt",
9-
"lint-check": "vp fmt --check"
8+
"lint": "vp check --fix --no-lint",
9+
"lint-check": "vp check --no-lint",
10+
"test-e2e": "playwright test"
1011
},
11-
"dependencies": {},
1212
"devDependencies": {
13+
"@playwright/test": "^1.50.0",
14+
"@types/node": "^24.12.0",
1315
"sirv-cli": "^3.0.1",
1416
"vite-plus": "latest"
1517
},

playwright.config.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineConfig, devices } from "@playwright/test";
2+
3+
export default defineConfig({
4+
testDir: "./e2e",
5+
workers: 1,
6+
webServer: {
7+
command: "pnpm dev --port 5174",
8+
url: "http://localhost:5174",
9+
reuseExistingServer: false,
10+
},
11+
expect: {
12+
timeout: 5000,
13+
},
14+
use: {
15+
...devices["Desktop Chrome"],
16+
baseURL: "http://localhost:5174",
17+
actionTimeout: 5000,
18+
channel: "chromium",
19+
},
20+
forbidOnly: !!process.env.CI,
21+
reporter: [
22+
["list"],
23+
["json", { outputFile: "test-results/report.json" }],
24+
...(process.env.CI ? [["github"] as const] : []),
25+
],
26+
});

pnpm-lock.yaml

Lines changed: 66 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)