diff --git a/e2e.spec.ts b/e2e.spec.ts index fbe1fbe..ceb99ee 100644 --- a/e2e.spec.ts +++ b/e2e.spec.ts @@ -4,7 +4,7 @@ import { open as openFile, readFile, writeFile } from 'node:fs/promises'; import { chromium, expect, firefox, test, type Browser, type BrowserType, type Page } from '@playwright/test'; import { createServer, type ViteDevServer } from 'vite'; -// Runs against the real public trackers and STUN servers from src/main.ts. +// Runs against the real public trackers and STUN servers, the defaults in src/main.ts. const BROWSERS: Record = { chromium, firefox }; const SIZE = 5_000_000; // Opt-in with LARGE=1: beyond what fits comfortably in RAM and beyond the 2000 MiB the old OPFS @@ -38,7 +38,9 @@ const MODES: Record Promise> = { // gatherIce Chromium would wait 40 s per side, with only the hard timeout still 10 s. async 'dead-stun'(sender, receiver) { for (const page of [sender, receiver]) { - await page.evaluate((path) => import(path).then((core) => core.STUN_SERVERS.push('stun:192.0.2.1:3478')), '/src/main.ts'); + await page.click('#servers summary'); + const servers = await page.inputValue('#stun-servers'); + await page.fill('#stun-servers', `${servers}\nstun:192.0.2.1:3478`); } const start = Date.now(); await MODES.manual!(sender, receiver); @@ -260,6 +262,32 @@ for (const mode of Object.keys(MODES)) { } } +for (const name of Object.keys(BROWSERS)) { + test(`servers: ${name} skips invalid lines and keeps the lists over a reload`, async () => { + const page = await open(name, []); + const core = () => + page.evaluate((path) => import(path).then(({ settings }) => [settings.stunServers, settings.trackers]), '/src/main.ts'); + await page.click('#servers summary'); + // Both would make the constructors throw. + await page.fill('#stun-servers', 'stun:stun.example:99999'); + await page.fill('#trackers', 'tracker.example\nwss://tracker.example/#\nwss://tracker.example'); + await expect(page.locator('#servers')).toContainText('accepts: stun:stun.example:99999'); + await expect(page.locator('#servers')).toContainText('without #: tracker.example, wss://tracker.example/#'); + expect(await core()).toEqual([[], ['wss://tracker.example']]); + + await page.reload(); + await page.click('#servers summary'); + await expect(page.locator('#trackers')).toHaveValue('wss://tracker.example'); + expect(await core()).toEqual([[], ['wss://tracker.example']]); + + await page.fill('#trackers', ''); + await expect(page.locator('#receive')).toBeDisabled(); + await page.click('#reset-servers'); + await expect(page.locator('#receive')).toBeEnabled(); + expect((await core())[1]).toContain('wss://tracker.webtorrent.dev'); + }); +} + for (const name of Object.keys(BROWSERS)) { test(`update: ${name} receives after sw.js changed`, async () => { const [sender, receiver] = await Promise.all([open(name, []), open(name, [])]); diff --git a/src/App.vue b/src/App.vue index 41f3c80..f5381c5 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,8 +1,10 @@