From bd4efa9dc128a32c5f26fb207c1cd670d930dfbc Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Wed, 11 Jan 2023 10:16:51 -0800 Subject: [PATCH] test: update tests for waituntil:commit (#20042) Instead of never finishing the response which works differently across browsers, stall the required script. This makes "DOMContentLoaded" to never fire and properly tests the "commit" signal. --- tests/page/page-goto.spec.ts | 11 ++++------- tests/page/page-wait-for-navigation.spec.ts | 12 ++++-------- tests/page/page-wait-for-url.spec.ts | 12 ++++-------- 3 files changed, 12 insertions(+), 23 deletions(-) diff --git a/tests/page/page-goto.spec.ts b/tests/page/page-goto.spec.ts index 3f6587ae85..8483e15c00 100644 --- a/tests/page/page-goto.spec.ts +++ b/tests/page/page-goto.spec.ts @@ -663,17 +663,14 @@ it('should return from goto if new navigation is started', async ({ page, server }); it('should return when navigation is committed if commit is specified', async ({ page, server }) => { + server.setRoute('/script.js', (req, res) => {}); server.setRoute('/empty.html', (req, res) => { - res.writeHead(200, { - 'content-type': 'text/html', - 'content-length': '8192' - }); - // Write enought bytes of the body to trigge response received event. - res.write('' + 'A'.repeat(4100)); - res.uncork(); + res.setHeader('content-type', 'text/html'); + res.end('<title>Hello'); }); const response = await page.goto(server.EMPTY_PAGE, { waitUntil: 'commit' }); expect(response.status()).toBe(200); + expect(await page.title()).toBe('Hello'); }); it('should wait for load when iframe attaches and detaches', async ({ page, server }) => { diff --git a/tests/page/page-wait-for-navigation.spec.ts b/tests/page/page-wait-for-navigation.spec.ts index 74fe95af7e..3313a2940b 100644 --- a/tests/page/page-wait-for-navigation.spec.ts +++ b/tests/page/page-wait-for-navigation.spec.ts @@ -61,18 +61,14 @@ it('should work with both domcontentloaded and load', async ({ page, server }) = }); it('should work with commit', async ({ page, server }) => { + server.setRoute('/script.js', (req, res) => {}); server.setRoute('/empty.html', (req, res) => { - res.writeHead(200, { - 'content-type': 'text/html', - 'content-length': '8192' - }); - // Write enought bytes of the body to trigge response received event. - res.write('' + 'A'.repeat(4100)); - res.uncork(); + res.setHeader('content-type', 'text/html'); + res.end('<title>Hello'); }); - page.goto(server.EMPTY_PAGE).catch(e => {}); await page.waitForNavigation({ waitUntil: 'commit' }); + expect(await page.title()).toBe('Hello'); }); it('should work with clicking on anchor links', async ({ page, server }) => { diff --git a/tests/page/page-wait-for-url.spec.ts b/tests/page/page-wait-for-url.spec.ts index ccfec39f96..8f9c56c53c 100644 --- a/tests/page/page-wait-for-url.spec.ts +++ b/tests/page/page-wait-for-url.spec.ts @@ -50,18 +50,14 @@ it('should work with both domcontentloaded and load', async ({ page, server }) = }); it('should work with commit', async ({ page, server }) => { + server.setRoute('/script.js', (req, res) => {}); server.setRoute('/empty.html', (req, res) => { - res.writeHead(200, { - 'content-type': 'text/html', - 'content-length': '8192' - }); - // Write enought bytes of the body to trigge response received event. - res.write('' + 'A'.repeat(4100)); - res.uncork(); + res.setHeader('content-type', 'text/html'); + res.end('<title>Hello'); }); - page.goto(server.EMPTY_PAGE).catch(e => {}); await page.waitForURL('**/empty.html', { waitUntil: 'commit' }); + expect(await page.title()).toBe('Hello'); }); it('should work with commit and about:blank', async ({ page, server }) => {