const { test, expect } = require('@playwright/test'); const { openClassic } = require('./helpers/classic-fixture'); function wavTone() { const rate = 48000, frames = rate; const b = Buffer.alloc(44 + frames * 2); b.write('RIFF', 0); b.writeUInt32LE(b.length - 8, 4); b.write('WAVEfmt ', 8); b.writeUInt32LE(16, 16); b.writeUInt16LE(1, 20); b.writeUInt16LE(1, 22); b.writeUInt32LE(rate, 24); b.writeUInt32LE(rate * 2, 28); b.writeUInt16LE(2, 32); b.writeUInt16LE(16, 34); b.write('data', 36); b.writeUInt32LE(frames * 2, 40); for (let i = 0; i < frames; i++) b.writeInt16LE(Math.round(Math.sin(2 * Math.PI * 440 * i / rate) * 9000), 44 + i * 2); return b; } test('JamesDSP stays lazy when off, plays a fixture tone when enabled, and persists settings', async ({ page }) => { await page.route('**/tone.wav', route => route.fulfill({ contentType: 'audio/wav', body: wavTone() })); await openClassic(page); await page.evaluate(() => { window.__audioContexts = 0; const AC = window.AudioContext; window.AudioContext = class extends AC { constructor(...args) { super(...args); window.__audioContexts++; } }; }); expect(await page.evaluate(() => window.__audioContexts)).toBe(0); await page.locator('.nav-item[data-view="settings"]').click(); await page.locator('[data-section="jamesdsp"]').click(); await page.locator('#setJamesDsp').check(); await expect.poll(() => page.evaluate(() => window.__audioContexts)).toBe(1); await page.evaluate(async () => { const audio = document.getElementById('audio'); Player.mode = 'audio'; Player.master = audio; Player.secondary = null; await JamesDSP.activate(audio); audio.src = '/tone.wav'; audio.load(); await audio.play(); }); await expect.poll(() => page.locator('#audio').evaluate(a => a.currentTime)).toBeGreaterThan(0.1); await page.waitForTimeout(600); const reloaded = await page.context().newPage(); await reloaded.goto('/'); await reloaded.locator('.nav-item[data-view="settings"]').click(); await expect(reloaded.locator('[data-section="jamesdsp"]')).toBeVisible(); await reloaded.locator('[data-section="jamesdsp"]').click(); await expect(reloaded.locator('#setJamesDsp')).toBeChecked(); await expect(reloaded.locator('#setJamesDspPreset')).toHaveValue('Flat'); });