From 2b4bac9904be9841e8f7fd3e5af54f33356c525d Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 27 Mar 2024 17:26:02 +0000 Subject: [PATCH] test: close out playwright `page` after each test --- test/e2e/no-ssr.test.ts | 8 ++++++-- test/e2e/ssr.test.ts | 10 +++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/test/e2e/no-ssr.test.ts b/test/e2e/no-ssr.test.ts index 4eda132fd..c7b1c2f1e 100644 --- a/test/e2e/no-ssr.test.ts +++ b/test/e2e/no-ssr.test.ts @@ -24,11 +24,11 @@ describe('browser (ssr: false)', () => { const requests: string[] = [] const page = await createPage() - page.route('**', (route) => { + await page.route('**', (route) => { requests.push(route.request().url()) return route.continue() }) - page.goto(url(providerPath)) + await page.goto(url(providerPath)) await page.waitForSelector('img') const images = await page.getByRole('img').all() @@ -39,6 +39,8 @@ describe('browser (ssr: false)', () => { expect(sources).toMatchSnapshot() expect(requests.map(r => r.replace(url('/'), '/')).filter(r => r !== providerPath && !r.match(/\.(js|css)/))).toMatchSnapshot() + + await page.close() }) } @@ -52,5 +54,7 @@ describe('browser (ssr: false)', () => { expect(logs.filter(log => log === 'Image was loaded').length).toBe(4) expect(logs.filter(log => log === 'Error loading image').length).toBe(2) + + await page.close() }) }) diff --git a/test/e2e/ssr.test.ts b/test/e2e/ssr.test.ts index 4f79ed9f9..95ff76855 100644 --- a/test/e2e/ssr.test.ts +++ b/test/e2e/ssr.test.ts @@ -24,12 +24,12 @@ describe('browser (ssr: true)', () => { const page = await createPage() const requests: string[] = [] - page.route('**', (route) => { + await page.route('**', (route) => { requests.push(route.request().url()) return route.continue() }) - page.goto(url(providerPath)) + await page.goto(url(providerPath)) await page.waitForSelector('img') const images = await page.getByRole('img').all() @@ -40,6 +40,8 @@ describe('browser (ssr: true)', () => { expect(sources).toMatchSnapshot() expect(requests.map(r => r.replace(url('/'), '/')).filter(r => r !== providerPath && !r.match(/\.(js|css)/))).toMatchSnapshot() + + await page.close() }) } @@ -49,12 +51,14 @@ describe('browser (ssr: true)', () => { page.on('console', (msg) => { logs.push(msg.text()) }) - page.goto(url('/events')) + await page.goto(url('/events')) await page.waitForLoadState('networkidle') expect(logs.filter(log => log === 'Image was loaded').length).toBe(4) expect(logs.filter(log => log === 'Error loading image').length).toBe(2) + + await page.close() }) it('works with runtime ipx', async () => {