diff options
| author | Adam Soltys <[email protected]> | 2026-10-07 08:40:21 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-10-07 08:40:21 -0700 |
| commit | 3aff6e4cc9eb97fc0fa488f1f95001f69f24330a (patch) | |
| tree | 932ed498851f9e2167a1c1419c96d630be0d02e2 /tools/feed-streaming-test.js | |
| parent | 6d288aeb194d2765282cf9fd72bd1f5fdd747a71 (diff) | |
| parent | 6c51dcf2542314d5fe883f756f0840ef51860d67 (diff) | |
| download | coinosv3-3aff6e4cc9eb97fc0fa488f1f95001f69f24330a.tar.gz coinosv3-3aff6e4cc9eb97fc0fa488f1f95001f69f24330a.zip | |
Merge branch 'worktree-agent-ad1d843e9e394974e'
Diffstat (limited to 'tools/feed-streaming-test.js')
| -rw-r--r-- | tools/feed-streaming-test.js | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/tools/feed-streaming-test.js b/tools/feed-streaming-test.js index e662b42..3070771 100644 --- a/tools/feed-streaming-test.js +++ b/tools/feed-streaming-test.js @@ -51,6 +51,7 @@ const server = Bun.serve({ port: 0, fetch(req) { if (path.startsWith('/punks')) return new Response(png, { headers: { 'Content-Type': 'image/png' } }); return new Response(html, { headers: { 'Content-Type': 'text/html' } }); } }); +const heldPng = { status: 200, contentType: 'image/png', body: png }; const browser = await puppeteer.launch({ executablePath: '/usr/bin/google-chrome', headless: true, args: ['--no-sandbox'] }); const errors = []; try { @@ -61,10 +62,23 @@ try { await page.emulateMediaFeatures([{ name: 'prefers-reduced-motion', value: 'reduce' }]); await page.setRequestInterception(true); page.on('request', (r) => { - if (r.url() === 'https://media.example/held.png') { page.heldImage = r; return; } + if (r.url() === 'https://media.example/held.png') { + // held until the test lets it go; once it has, asking again (the + // picture is read more than once on its way in) is answered at once + if (page.released) r.respond(heldPng); else page.heldImage = r; + return; + } if (r.url().startsWith(server.url.origin) || r.url().startsWith('data:')) r.continue(); else r.abort(); }); await page.evaluateOnNewDocument(() => { + // the stub wallet's feed is Following (a wallet with none remembered opens on Popular) + try { localStorage.setItem('btc-wallet-feed:', 'following'); } catch {} + // rows that went on screen wearing the new-post tint (it fades the + // moment a row is seen, so the class alone can't be read afterwards) + window.freshSeen = new Set(); + new MutationObserver((ms) => { for (const m of ms) for (const n of m.type === 'attributes' ? [m.target] : m.addedNodes) + if (n.classList?.contains('note-fresh')) window.freshSeen.add(n.getAttribute('data-key')); }) + .observe(document, { childList: true, subtree: true, attributes: true, attributeFilter: ['class'] }); const sockets = []; window.feedClosed = 0; class FakeSocket extends EventTarget { @@ -125,7 +139,7 @@ try { assert.equal(await count(page), 2, 'out-of-order posts count and duplicates do not'); assert(Math.abs(await page.$eval(row(reading), (r) => r.getBoundingClientRect().top) - held) <= 1, 'streaming preserves reading position'); assert(page.heldImage, 'slow media is being prepared'); - await page.heldImage.respond({ status: 200, contentType: 'image/png', body: png }); + page.released = true; await page.heldImage.respond(heldPng); await page.waitForSelector(row(slow.id), { timeout: 2000 }); assert.equal(await count(page), 3); assert(await page.$eval(row(slow.id), (r) => { const img = r.querySelector('.note-img'); return img?.complete && img.naturalWidth > 0; }), 'photo is decoded when admitted'); @@ -173,9 +187,9 @@ try { assert(await page.evaluate(() => !window.bootDone), 'new-post notice does not wait for cached media'); await page.click('.feed-new-pill'); await page.waitForSelector(row(fast.id)); - assert(await page.$eval(row(fast.id), (r) => r.classList.contains('note-fresh')), 'prepared new rows keep their stable presentation during cache warm-up'); + assert(await page.evaluate((id) => window.freshSeen.has(id), fast.id), 'prepared new rows keep their stable presentation during cache warm-up'); assert(page.heldImage); - await page.heldImage.respond({ status: 200, contentType: 'image/png', body: png }); + page.released = true; await page.heldImage.respond(heldPng); await page.waitForFunction(() => window.bootDone); await page.evaluate(() => window.endQueries()); await page.waitForFunction(() => window.refreshDone); @@ -192,7 +206,7 @@ try { await page.click('.feed-new-pill'); await page.waitForSelector(row(fast.id)); assert(page.heldImage); - await page.heldImage.respond({ status: 200, contentType: 'image/png', body: png }); + page.released = true; await page.heldImage.respond(heldPng); await page.waitForFunction(() => window.batchDone); await page.evaluate(() => window.endQueries()); await page.waitForFunction(() => window.refreshDone); |
