Skip to content
Myr

Add test for request cancellation (#728)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sindre Sorhus · committed by GitHub · parent 2fb39e9 · Browse files · 1 file+34 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+34 added−0 removed

  • tests:+34 added−0 removed

1 file+34 added−0 removed

modified:test/browser.ts+34 added
483 unmodified lines
484 );485486 t.is(requestCount, 2);487});488489defaultBrowsersTest('request is cancelled on timeout', async (t: ExecutionContext, page: Page) => {490 let requestAborted = false;491492 server.get('/', (_request, response) => {493 response.end('meow');494 });495496 server.get('/slow', (request, response) => {497 request.on('aborted', () => {498 requestAborted = true;499 });500501 // Never respond to simulate timeout502 setTimeout(() => {503 if (!response.headersSent) {504 response.end('too late');505 }506 }, 2000);507 });508509 await page.goto(server.url);510 await addKyScriptToPage(page);511512 await t.throwsAsync(513 page.evaluate(async (url: string) => window.ky(`${url}/slow`, {timeout: 100}).text(), server.url),514 {message: /Request timed out/},515 );516517 // Wait a bit to ensure the abort signal was received518 await page.waitForTimeout(200);519520 t.true(requestAborted, 'Request should be aborted on timeout');521});