(page, filename = 'transformed.wav')
| 13 | // the page submitted to /audio/transformations. The handler returns a tiny |
| 14 | // fake WAV blob so the page can render its result waveforms. |
| 15 | function mockAudioTransform(page, filename = 'transformed.wav') { |
| 16 | let resolveSubmit |
| 17 | const submitted = new Promise((resolve) => { resolveSubmit = resolve }) |
| 18 | |
| 19 | page.route('**/audio/transformations', (route) => { |
| 20 | if (route.request().method() !== 'POST') return route.continue() |
| 21 | const req = route.request() |
| 22 | const body = req.postData() || '' |
| 23 | resolveSubmit({ |
| 24 | contentType: req.headers()['content-type'] || '', |
| 25 | bodySize: body.length, |
| 26 | // Naive multipart field name extraction so a test can assert the |
| 27 | // form-data shape without parsing the multipart body. |
| 28 | fields: Array.from(body.matchAll(/name="([^"]+)"/g)).map((m) => m[1]), |
| 29 | }) |
| 30 | const wavHeader = new Uint8Array(44) // 44-byte RIFF/WAVE skeleton |
| 31 | route.fulfill({ |
| 32 | status: 200, |
| 33 | headers: { |
| 34 | 'Content-Type': 'audio/wav', |
| 35 | 'Content-Disposition': `attachment; filename="${filename}"`, |
| 36 | }, |
| 37 | body: Buffer.from(wavHeader), |
| 38 | }) |
| 39 | }) |
| 40 | |
| 41 | return submitted |
| 42 | } |
| 43 | |
| 44 | // Build a tiny in-memory WAV file (44-byte header, 4 silent samples) so |
| 45 | // Playwright's setInputFiles + the page's audio decoder both have valid |
no test coverage detected