Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions injected/integration-test/favicon.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,37 +88,41 @@ test('favicon + monitor (many updates)', async ({ page, baseURL }, testInfo) =>
await page.getByRole('button', { name: 'Set many overrides' }).click();
await page.clock.fastForward(20);

const messages = await favicon.outgoingMessages();
expect(messages).toHaveLength(1);

await page.clock.fastForward(60);
await page.clock.fastForward(100);

// No mutation has happened yet (the first update is after a 40ms timeout),
// so we should still only have the initial message.
{
const messages = await favicon.outgoingMessages();
expect(messages).toHaveLength(3);
const messages = await favicon.waitForMessage('faviconFound', 1);
expect(messages).toHaveLength(1);
}

{
const url1 = new URL('/favicon/favicon.png', baseURL);
const url2 = new URL('/favicon/new_favicon.png?count=0', baseURL);
const url3 = new URL('/favicon/new_favicon.png?count=1', baseURL);

const messages = await favicon.outgoingMessages();
expect(messages.map((x) => /** @type {{params: any}} */ (x.payload).params)).toStrictEqual([
{
favicons: [{ href: url1.href, rel: 'shortcut icon' }],
documentUrl: 'http://localhost:3220/favicon/index.html',
},
{
favicons: [{ href: url2.href, rel: 'shortcut icon' }],
documentUrl: 'http://localhost:3220/favicon/index.html',
},
{
favicons: [{ href: url3.href, rel: 'shortcut icon' }],
documentUrl: 'http://localhost:3220/favicon/index.html',
},
]);
// `setManyOverrides()` updates every 40ms; this feature should debounce/throttle emissions.
// The exact number of updates emitted here can vary slightly (flake), so assert:
// - at least one update is emitted
// - overall message volume stays low
// - any emitted override points at `new_favicon.png?count=<n>`
await page.clock.fastForward(250);
await favicon.waitForMessage('faviconFound', 2);

const url1 = new URL('/favicon/favicon.png', baseURL);
const overrideBase = new URL('/favicon/new_favicon.png', baseURL).href;

const faviconFound = (await favicon.outgoingMessages())
.filter((x) => /** @type {any} */ (x.payload).method === 'faviconFound')
.map((x) => /** @type {any} */ (x.payload).params);

expect(faviconFound.length).toBeGreaterThanOrEqual(2);
expect(faviconFound.length).toBeLessThanOrEqual(3);

expect(faviconFound[0]).toStrictEqual({
favicons: [{ href: url1.href, rel: 'shortcut icon' }],
documentUrl: 'http://localhost:3220/favicon/index.html',
});

for (const params of faviconFound.slice(1)) {
expect(params.documentUrl).toBe('http://localhost:3220/favicon/index.html');
expect(params.favicons).toHaveLength(1);
expect(params.favicons[0].rel).toBe('shortcut icon');
expect(params.favicons[0].href.startsWith(`${overrideBase}?count=`)).toBe(true);
}
});

Expand Down