Skip to content

Commit

Permalink
test: close out playwright page after each test
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 27, 2024
1 parent b3bde17 commit 2b4bac9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 6 additions & 2 deletions test/e2e/no-ssr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand 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()
})
}

Expand All @@ -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()
})
})
10 changes: 7 additions & 3 deletions test/e2e/ssr.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand 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()
})
}

Expand All @@ -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 () => {
Expand Down

0 comments on commit 2b4bac9

Please sign in to comment.