Nothing measured what the tests reach. scripts/coverage.sh runs the cargo tests under cargo-llvm-cov in the ipx-coverage image (Dockerfile.coverage, built by build-image.sh coverage), in a container held to the image builder's 6 GB and six threads, one crate at a time, with the same room and load checks: an instrumented build rebuilds every dependency, the kind of build that took Tower down on 2026-11-04. The first run stayed under load 8 with 11 GB free; 69% of lines. web.rs and daemon.rs read low because the browser suite drives them against a daemon that is not instrumented. npm run coverage:page runs the browser suite on a build of the page (IPX_COVERAGE=1) whose script keeps a source map to each web/src file: web/concat-map.mts maps the joined files line by line and swc takes it as its input map. Each test's page records V8's coverage (tests/ui/coverage.ts, which the specs now take test and expect from), and monocart-coverage-reports writes it file by file: 73% of lines. build.mjs requires the map helper only for that build, since Dockerfile.web's Node does not run TypeScript, and not with a top-level await, which stopped the CommonJS tests requiring build.mjs. The offline tests move to offline.spec.ts, in TypeScript, and stand alone (they add their feed and set the read state they need), with what #391 found untested: another account signing in clears what was kept, a position saved offline waits and is sent, and pictures past the budget go oldest first (keepPictures takes the budget, and trims whether or not anything new came). The fixture JPEGs were a few bytes no browser could draw; they are real now, and the artwork test checks one draws. tsconfig.tools.json type-checks the tests' and build's TypeScript, in npm run typecheck. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { test, expect } = require('@playwright/test');
|
||||
// With the page's coverage recorded when asked for (#390).
|
||||
const { test, expect } = require('./coverage.ts');
|
||||
const { TOKEN } = require('./global-setup');
|
||||
|
||||
// Signals' tests run only when the Signals code has changed since each last passed: they spend the
|
||||
@@ -1285,6 +1286,8 @@ test('artwork comes from iPX, kept, and only as an image', async ({ page }) => {
|
||||
expect(r.headers()['content-type']).toMatch(/^image\//);
|
||||
expect(r.headers()['content-security-policy']).toContain('sandbox');
|
||||
}
|
||||
// And it draws: the fixture's JPEGs were once a few bytes that only said they were one (#391).
|
||||
expect(await page.evaluate((src) => new Promise(r => { const i = new Image(); i.onload = () => r(i.naturalWidth); i.onerror = () => r(0); i.src = src; }), src)).toBe(96);
|
||||
// An address no feed names is not fetched.
|
||||
expect((await page.request.get('/api/art?u=' + encodeURIComponent('http://127.0.0.1:8792/show.xml'))).status()).toBe(404);
|
||||
});
|
||||
@@ -2485,61 +2488,3 @@ test('an error toast is announced and stays until it is dismissed', async ({ pag
|
||||
await t.getByRole('button', { name: 'Dismiss' }).click();
|
||||
await expect(t).toHaveCount(0);
|
||||
});
|
||||
|
||||
// Last: it adds a feed, which the feed counts of earlier tests do not expect.
|
||||
test.describe('offline (#389)', () => {
|
||||
test.use({ serviceWorkers: 'allow' });
|
||||
const outbox = page => page.evaluate(async () => (await (await caches.open('ipx-outbox')).keys()).length);
|
||||
|
||||
test('iPX opens offline with what it read and its pictures, and sends a read made offline once back', async ({ page, context }) => {
|
||||
const api = (p, init) => page.evaluate(([p, init]) => fetch(p, { headers: { 'Content-Type': 'application/json' }, ...init })
|
||||
.then((r) => r.json().catch(() => null)), [p, init]);
|
||||
const added = await api('/api/feeds', { method: 'POST', body: JSON.stringify({ url: 'http://127.0.0.1:8792/offline.xml' }) });
|
||||
const id = added.id || added.feed?.id || 'offline-blog';
|
||||
await page.evaluate(() => navigator.serviceWorker.ready);
|
||||
await page.reload();
|
||||
await expect.poll(() => page.evaluate(() => !!navigator.serviceWorker.controller)).toBe(true);
|
||||
await page.locator('#feedlist .feed', { hasText: 'Offline Blog' }).click({ timeout: 20_000 });
|
||||
await page.locator('#content .tabs button[data-f="unread"]').click();
|
||||
await expect(page.locator('.ep', { hasText: 'Read on a Plane' })).toBeVisible();
|
||||
// The unread item's picture, kept through ipx: no feed names it as artwork, only its text.
|
||||
await expect.poll(() => page.evaluate(async () => (await (await caches.open('ipx-pics')).keys()).length)).toBe(1);
|
||||
|
||||
await context.setOffline(true);
|
||||
await page.reload();
|
||||
// The page, the feed list and the list kept, with the feed and tab open before.
|
||||
await page.locator('.ep', { hasText: 'Read on a Plane' }).click({ timeout: 20_000 });
|
||||
await expect(page.locator('#detail .dbody')).toContainText('Read on a plane, with no connection.');
|
||||
await expect.poll(() => page.locator('#detail .dbody img').evaluate(i => i.complete ? i.naturalWidth : 0)).toBeGreaterThan(0);
|
||||
// Opening it read it, which waits to be sent.
|
||||
await expect.poll(() => outbox(page)).toBe(1);
|
||||
|
||||
await context.setOffline(false);
|
||||
await expect.poll(() => outbox(page), { timeout: 15_000 }).toBe(0);
|
||||
const list = await api(`/api/feeds/${encodeURIComponent(id)}/entries?offset=0&limit=50&filter=all`);
|
||||
expect(list.entries.find(e => e.guid === 'offline-1').read).toBe(true);
|
||||
});
|
||||
|
||||
test('online, a picture in an item\'s text still comes from its publisher, through the worker', async ({ page }) => {
|
||||
await page.evaluate(() => navigator.serviceWorker.ready);
|
||||
await page.reload();
|
||||
await page.locator('#feedlist .feed', { hasText: 'Offline Blog' }).click({ timeout: 20_000 });
|
||||
await page.locator('#content .tabs button[data-f="all"]').click();
|
||||
await page.locator('.ep', { hasText: 'Read on a Plane' }).click();
|
||||
const img = page.locator('#detail .dbody img');
|
||||
await expect.poll(() => img.evaluate(i => i.complete ? i.naturalWidth : 0)).toBeGreaterThan(0);
|
||||
// Past the worker, not round it: what it passes on online is what it would keep.
|
||||
expect(await page.evaluate(() => performance.getEntriesByName('http://127.0.0.1:8792/pic.png')[0]?.workerStart > 0)).toBe(true);
|
||||
});
|
||||
|
||||
test('signing out leaves nothing kept for offline on the device', async ({ page }) => {
|
||||
await page.evaluate(() => navigator.serviceWorker.ready);
|
||||
await page.reload();
|
||||
await expect.poll(() => page.evaluate(async () => (await caches.keys()).filter(k => k.startsWith('ipx-')).length)).toBeGreaterThan(0);
|
||||
await page.locator('#signout').evaluate(b => b.click());
|
||||
await page.waitForURL(u => !u.pathname.endsWith('/') || u.pathname === '/login' || u.pathname.includes('signed-out'));
|
||||
// What was read, its pictures and unsent writes. The sign-in page's own script and styles are
|
||||
// kept again as it loads: the same files for everyone, nothing of the account's.
|
||||
expect(await page.evaluate(async () => (await caches.keys()).filter(k => k.startsWith('ipx-') && k !== 'ipx-page'))).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
7
tests/ui/coverage-setup.ts
Normal file
7
tests/ui/coverage-setup.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// A coverage run starts from nothing: what an earlier run added is not this one's (#390).
|
||||
import fs from 'node:fs';
|
||||
import { coverageOptions } from './coverage.ts';
|
||||
|
||||
export default function setup() {
|
||||
if (process.env.IPX_COVERAGE) fs.rmSync(coverageOptions.outputDir!, { recursive: true, force: true });
|
||||
}
|
||||
7
tests/ui/coverage-teardown.ts
Normal file
7
tests/ui/coverage-teardown.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
// The page's coverage report, once every test has added its page's (coverage.ts, #390).
|
||||
import { CoverageReport } from 'monocart-coverage-reports';
|
||||
import { coverageOptions } from './coverage.ts';
|
||||
|
||||
export default async function teardown() {
|
||||
if (process.env.IPX_COVERAGE) await new CoverageReport(coverageOptions).generate();
|
||||
}
|
||||
34
tests/ui/coverage.ts
Normal file
34
tests/ui/coverage.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
// What the browser tests run of the page's script (#390). With IPX_COVERAGE=1, web/build.mjs
|
||||
// builds the script unminified with a source map to web/src, every test's page records V8's
|
||||
// coverage of it, and the teardown (coverage-teardown.ts) writes the report, file by file, to
|
||||
// target/coverage/page. Without it, `test` is Playwright's own.
|
||||
//
|
||||
// The specs take `test` and `expect` from here, not from @playwright/test, so no test is left out.
|
||||
|
||||
import { test as base, expect } from '@playwright/test';
|
||||
import { CoverageReport, type CoverageReportOptions } from 'monocart-coverage-reports';
|
||||
|
||||
export const coverageOptions: CoverageReportOptions = {
|
||||
name: 'iPX page',
|
||||
outputDir: 'target/coverage/page',
|
||||
reports: ['v8', 'lcovonly', 'console-summary', 'markdown-details'],
|
||||
// The pages' scripts; the service worker is a worker of its own, which a page's coverage does
|
||||
// not see.
|
||||
entryFilter: (e) => /\/(app|admin|login)\.js(\?|$)/.test(e.url),
|
||||
sourceFilter: (p) => p.startsWith('web/src/'),
|
||||
};
|
||||
|
||||
export const test = base.extend<{ coverage: void }>({
|
||||
coverage: [
|
||||
async ({ page }, use) => {
|
||||
if (!process.env.IPX_COVERAGE) return use();
|
||||
// Kept across a reload or a sign-in, which several tests make.
|
||||
await page.coverage.startJSCoverage({ resetOnNavigation: false });
|
||||
await use();
|
||||
await new CoverageReport(coverageOptions).add(await page.coverage.stopJSCoverage());
|
||||
},
|
||||
{ auto: true },
|
||||
],
|
||||
});
|
||||
|
||||
export { expect };
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 278 B |
Binary file not shown.
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 247 B |
@@ -1,7 +1,10 @@
|
||||
<?xml version="1.0"?>
|
||||
<rss version="2.0">
|
||||
<channel><title>Offline Blog</title><link>http://127.0.0.1:8792/</link><description>A post with a picture in its text, to read offline (#389).</description>
|
||||
<channel><title>Offline Blog</title><link>http://127.0.0.1:8792/</link><description>Posts with pictures in their text, to read offline (#389).</description>
|
||||
<item><title>Read on a Plane</title><guid>offline-1</guid>
|
||||
<pubDate>Mon, 01 Sep 2026 10:00:00 +0000</pubDate>
|
||||
<description><p>Read on a plane, with no connection.</p><img src="http://127.0.0.1:8792/pic.png" alt="a picture"></description></item>
|
||||
<item><title>Three Pictures</title><guid>offline-2</guid>
|
||||
<pubDate>Sun, 31 Aug 2026 10:00:00 +0000</pubDate>
|
||||
<description><p>Three of them.</p><img src="http://127.0.0.1:8792/pic.png?n=1"><img src="http://127.0.0.1:8792/pic.png?n=2"><img src="http://127.0.0.1:8792/pic.png?n=3"></description></item>
|
||||
</channel></rss>
|
||||
|
||||
154
tests/ui/offline.spec.ts
Normal file
154
tests/ui/offline.spec.ts
Normal file
@@ -0,0 +1,154 @@
|
||||
// iPX without a connection (#389): the service worker (web/sw/sw.ts) keeps the page, what it read
|
||||
// and the pictures in unread items, and holds writes made offline until the connection is back.
|
||||
// After app.spec.js, file order being run order: it adds a feed, which that file's counts of
|
||||
// feeds do not expect.
|
||||
|
||||
import type { BrowserContext, Page, Worker } from '@playwright/test';
|
||||
import { TOKEN } from './global-setup.js';
|
||||
import { expect, test } from './coverage.ts';
|
||||
|
||||
// The suite blocks the worker, which answers before page.route can; these tests are about it.
|
||||
test.use({ serviceWorkers: 'allow' });
|
||||
|
||||
const call = (page: Page, p: string, init?: RequestInit) =>
|
||||
page.evaluate(([p, init]) => fetch(p!, { headers: { 'Content-Type': 'application/json' }, ...(init as RequestInit) })
|
||||
.then((r) => r.json().catch(() => null)), [p, init] as const);
|
||||
const cacheSize = (page: Page, name: string) =>
|
||||
page.evaluate(async (name) => (await (await caches.open(name)).keys()).length, name);
|
||||
const outbox = (page: Page) => cacheSize(page, 'ipx-outbox');
|
||||
|
||||
/// The page, under the worker's control.
|
||||
async function controlled(page: Page) {
|
||||
await page.evaluate(() => navigator.serviceWorker.ready);
|
||||
await page.reload();
|
||||
await expect.poll(() => page.evaluate(() => !!navigator.serviceWorker.controller)).toBe(true);
|
||||
}
|
||||
async function worker(context: BrowserContext): Promise<Worker> {
|
||||
return context.serviceWorkers()[0] ?? context.waitForEvent('serviceworker');
|
||||
}
|
||||
|
||||
/// The feed these tests read, added once; the tests that follow find it there.
|
||||
async function offlineBlog(page: Page): Promise<string> {
|
||||
const feeds: { id: string, url: string }[] = await call(page, '/api/feeds');
|
||||
const had = feeds.find((f) => f.url.endsWith('/offline.xml'));
|
||||
if (had) return had.id;
|
||||
const added = await call(page, '/api/feeds', { method: 'POST', body: JSON.stringify({ url: 'http://127.0.0.1:8792/offline.xml' }) });
|
||||
return added?.id || added?.feed?.id || 'offline-blog';
|
||||
}
|
||||
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto(`/?token=${TOKEN}`);
|
||||
await expect(page.locator('#feedlist')).toBeVisible();
|
||||
await offlineBlog(page);
|
||||
});
|
||||
|
||||
test('iPX opens offline with what it read and its pictures, and sends a read made offline once back', async ({ page, context }) => {
|
||||
const id = await offlineBlog(page);
|
||||
// A run before this one read them: both unread again, so the Unread list holds both.
|
||||
await expect.poll(async () => (await call(page, `/api/feeds/${encodeURIComponent(id)}/entries?offset=0&limit=50&filter=all`))?.entries?.length ?? 0,
|
||||
{ timeout: 20_000 }).toBe(2);
|
||||
for (const guid of ['offline-1', 'offline-2'])
|
||||
await call(page, `/api/entries/${encodeURIComponent(id)}/${guid}/flags`, { method: 'POST', body: JSON.stringify({ read: false }) });
|
||||
await controlled(page);
|
||||
await page.locator('#feedlist .feed', { hasText: 'Offline Blog' }).click({ timeout: 20_000 });
|
||||
await page.locator('#content .tabs button[data-f="unread"]').click();
|
||||
await expect(page.locator('.ep', { hasText: 'Read on a Plane' })).toBeVisible();
|
||||
// The unread items' four pictures, kept through ipx: no feed names them as artwork, only text.
|
||||
await expect.poll(() => cacheSize(page, 'ipx-pics')).toBe(4);
|
||||
|
||||
await context.setOffline(true);
|
||||
await page.reload();
|
||||
// The page, the feed list and the list kept, with the feed and tab open before.
|
||||
await page.locator('.ep', { hasText: 'Read on a Plane' }).click({ timeout: 20_000 });
|
||||
await expect(page.locator('#detail .dbody')).toContainText('Read on a plane, with no connection.');
|
||||
await expect.poll(() => page.locator('#detail .dbody img').evaluate((i: HTMLImageElement) => i.complete ? i.naturalWidth : 0)).toBeGreaterThan(0);
|
||||
// Opening it read it, which waits to be sent.
|
||||
await expect.poll(() => outbox(page)).toBe(1);
|
||||
// Opened again offline, the Unread list kept no longer has it: read, as the outbox has it.
|
||||
await page.reload();
|
||||
await expect(page.locator('.ep', { hasText: 'Three Pictures' })).toBeVisible({ timeout: 20_000 });
|
||||
await expect(page.locator('.ep', { hasText: 'Read on a Plane' })).toHaveCount(0);
|
||||
|
||||
await context.setOffline(false);
|
||||
await expect.poll(() => outbox(page), { timeout: 15_000 }).toBe(0);
|
||||
const list = await call(page, `/api/feeds/${encodeURIComponent(id)}/entries?offset=0&limit=50&filter=all`);
|
||||
expect(list.entries.find((e: { guid: string }) => e.guid === 'offline-1').read).toBe(true);
|
||||
});
|
||||
|
||||
test('a place in an episode saved offline waits, and is saved once back', async ({ page, context }) => {
|
||||
await controlled(page);
|
||||
const at = '/api/entries/offline-blog/offline-2/position';
|
||||
await context.setOffline(true);
|
||||
const answer = await page.evaluate((at) => fetch(at, {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ secs: 321, duration: 600 }),
|
||||
}).then((r) => `${r.status} ${r.headers.get('X-Ipx-Queued')}`), at);
|
||||
// Answered for the server, so the player carries on, and kept.
|
||||
expect(answer).toBe('204 1');
|
||||
expect(await outbox(page)).toBe(1);
|
||||
|
||||
await context.setOffline(false);
|
||||
await page.evaluate(() => window.dispatchEvent(new Event('online')));
|
||||
await expect.poll(() => outbox(page), { timeout: 15_000 }).toBe(0);
|
||||
expect((await call(page, '/api/entries/offline-blog/offline-2')).position).toBe(321);
|
||||
});
|
||||
|
||||
test('online, a picture in an item\'s text still comes from its publisher, through the worker', async ({ page }) => {
|
||||
await controlled(page);
|
||||
await page.locator('#feedlist .feed', { hasText: 'Offline Blog' }).click({ timeout: 20_000 });
|
||||
await page.locator('#content .tabs button[data-f="all"]').click();
|
||||
await page.locator('.ep', { hasText: 'Read on a Plane' }).click();
|
||||
const img = page.locator('#detail .dbody img');
|
||||
await expect.poll(() => img.evaluate((i: HTMLImageElement) => i.complete ? i.naturalWidth : 0)).toBeGreaterThan(0);
|
||||
// Past the worker, not round it: what it passes on online is what it would keep.
|
||||
expect(await page.evaluate(() =>
|
||||
((performance.getEntriesByName('http://127.0.0.1:8792/pic.png')[0] as PerformanceResourceTiming | undefined)?.workerStart ?? 0) > 0)).toBe(true);
|
||||
});
|
||||
|
||||
test('kept pictures past the budget go oldest first', async ({ page, context }) => {
|
||||
const pic = (n: number) => `http://127.0.0.1:8792/pic.png?n=${n}`;
|
||||
// ipx serves only pictures it has sent in item text: the list names them, once scanned.
|
||||
await expect.poll(async () => (await call(page, '/api/feeds/offline-blog/entries?offset=0&limit=50&filter=all'))?.entries?.length ?? 0,
|
||||
{ timeout: 20_000 }).toBe(2);
|
||||
// Read, so the page asks the worker to keep none of them itself while this test does.
|
||||
for (const guid of ['offline-1', 'offline-2'])
|
||||
await call(page, `/api/entries/offline-blog/${guid}/flags`, { method: 'POST', body: JSON.stringify({ read: true }) });
|
||||
await controlled(page);
|
||||
const sw = await worker(context);
|
||||
const kept = await sw.evaluate(async ([a, b, c]) => {
|
||||
await caches.delete('ipx-pics');
|
||||
// One at a time, so which is oldest is known; the third goes over two pictures' budget.
|
||||
await keepPictures([a!]);
|
||||
await keepPictures([b!]);
|
||||
const one = Number((await (await caches.open('ipx-pics')).match(`/api/art?u=${encodeURIComponent(a!)}`))?.headers.get('X-Size'));
|
||||
await keepPictures([c!], one * 2.5);
|
||||
return (await (await caches.open('ipx-pics')).keys()).map((k) => decodeURIComponent(new URL(k.url).searchParams.get('u')!));
|
||||
}, [pic(1), pic(2), pic(3)]);
|
||||
expect(kept).toEqual([pic(2), pic(3)]);
|
||||
});
|
||||
|
||||
test('another account signing in on the device clears what the last one kept', async ({ page }) => {
|
||||
await controlled(page);
|
||||
// What an account before this one left, and the page last opened as that account.
|
||||
await page.evaluate(async () => {
|
||||
await (await caches.open('ipx-api')).put('/api/left-by-someone-else', new Response('{}'));
|
||||
localStorage.setItem('ipx.owner', 'someone else');
|
||||
});
|
||||
await page.reload();
|
||||
await expect.poll(() => page.evaluate(async () =>
|
||||
!!(await (await caches.open('ipx-api')).match('/api/left-by-someone-else')))).toBe(false);
|
||||
// This account is the owner now, and what it keeps from here stays.
|
||||
expect(await page.evaluate(() => localStorage.getItem('ipx.owner'))).not.toBe('someone else');
|
||||
});
|
||||
|
||||
test('signing out leaves nothing kept for offline on the device', async ({ page }) => {
|
||||
await controlled(page);
|
||||
await expect.poll(() => page.evaluate(async () => (await caches.keys()).filter((k) => k.startsWith('ipx-')).length)).toBeGreaterThan(0);
|
||||
await page.locator('#signout').evaluate((b: HTMLButtonElement) => b.click());
|
||||
await page.waitForURL((u) => u.pathname !== '/');
|
||||
// What was read, its pictures and unsent writes. The sign-in page's own script and styles are
|
||||
// kept again as it loads: the same files for everyone, nothing of the account's.
|
||||
expect(await page.evaluate(async () => (await caches.keys()).filter((k) => k.startsWith('ipx-') && k !== 'ipx-page'))).toEqual([]);
|
||||
});
|
||||
|
||||
// The worker's own functions, called in it by the test above; declared for the type check.
|
||||
declare function keepPictures(srcs: string[], budget?: number): Promise<void>;
|
||||
Reference in New Issue
Block a user