Add server lists to edit

This commit is contained in:
Schluffe committed 2026-10-23 20:19:07 +02:00
1 parent 08b9f659c2
commit 85ccdbfc03
4 files changed
+151 -11

No files matched your search

+30 -2
View File
@@ -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<string, BrowserType> = { 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<string, (sender: Page, receiver: Page) => Promise<void>> = {
// 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, [])]);