Skip to content

Commit 1700aa1

Browse files
committed
test: properly close page in e2e tests
1 parent 4782e3c commit 1700aa1

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

test/e2e/basic.browser.test.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ describe('basic browser', () => {
130130
await page.nuxt.navigate('/scroll-to-top/scroll-to-top-true')
131131
const pageYOffset = await page.evaluate(() => window.pageYOffset)
132132
expect(pageYOffset).toBe(0)
133-
page.close()
133+
await page.close()
134134
})
135135

136136
test('/scroll-to-top with scrollToTop set to false', async () => {
@@ -139,7 +139,7 @@ describe('basic browser', () => {
139139
await page.nuxt.navigate('/scroll-to-top/scroll-to-top-false')
140140
const pageYOffset = await page.evaluate(() => window.pageYOffset)
141141
expect(pageYOffset).toBeGreaterThan(0)
142-
page.close()
142+
await page.close()
143143
})
144144

145145
test('/scroll-to-top in the same page', async () => {
@@ -148,7 +148,7 @@ describe('basic browser', () => {
148148
await page.nuxt.navigate('/scroll-to-top?test=1')
149149
const pageYOffset = await page.evaluate(() => window.pageYOffset)
150150
expect(pageYOffset).toBeGreaterThan(0)
151-
page.close()
151+
await page.close()
152152
})
153153

154154
test('/scroll-to-top in the same page with watchQuery: true', async () => {
@@ -160,7 +160,7 @@ describe('basic browser', () => {
160160
await page.nuxt.go(-1)
161161
pageYOffset = await page.evaluate(() => window.pageYOffset)
162162
expect(pageYOffset).toBeGreaterThan(0)
163-
page.close()
163+
await page.close()
164164
})
165165

166166
test('/scroll-to-top in the same page with watchQuery array', async () => {
@@ -178,7 +178,7 @@ describe('basic browser', () => {
178178
await page.nuxt.go(-1)
179179
pageYOffset = await page.evaluate(() => window.pageYOffset)
180180
expect(pageYOffset).toBeGreaterThan(0)
181-
page.close()
181+
await page.close()
182182
})
183183

184184
test('/scroll-to-top in the same page with watchQuery function', async () => {
@@ -196,7 +196,7 @@ describe('basic browser', () => {
196196
await page.nuxt.go(-1)
197197
pageYOffset = await page.evaluate(() => window.pageYOffset)
198198
expect(pageYOffset).toBe(0)
199-
page.close()
199+
await page.close()
200200
})
201201

202202
test('/validate should display a 404', async () => {
@@ -264,7 +264,7 @@ describe('basic browser', () => {
264264
await page.waitForFunction(
265265
() => window.location.href === 'https://example.com/test/'
266266
)
267-
page.close()
267+
await page.close()
268268
})
269269

270270
test('/redirect-name', async () => {
@@ -308,6 +308,7 @@ describe('basic browser', () => {
308308

309309
const p = await page.$text('p')
310310
expect(p).toBe('Nuxt')
311+
await page.close()
311312
})
312313

313314
test('/refresh-page-data', async () => {
@@ -317,12 +318,13 @@ describe('basic browser', () => {
317318
await page.evaluate($nuxt => $nuxt.refresh(), page.$nuxt)
318319
h1 = await page.$text('h1')
319320
expect(h1).toContain('Hello from client')
320-
page.close()
321+
await page.close()
321322
})
322323

323324
test('/redirection/no loop', async () => {
324325
const page = await browser.page(url('/redirection/no loop'))
325326
expect(await page.$text('h1')).toContain('Redirected page')
327+
await page.close()
326328
})
327329

328330
// Close server and ask nuxt to stop listening to file changes
@@ -332,7 +334,6 @@ describe('basic browser', () => {
332334

333335
// Stop browser
334336
afterAll(async () => {
335-
await page.close()
336337
await browser.close()
337338
})
338339
})

test/e2e/fetch.browser.test.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ describe('basic browser', () => {
9999
])
100100
expect(await page.$text('div')).toContain('foo-bar-baz')
101101
expect(await page.$text('div')).toContain('fizz-buzz')
102+
await page.close()
102103
})
103104

104105
test('ssr: /nested', async () => {
@@ -112,6 +113,7 @@ describe('basic browser', () => {
112113
'ie0'
113114
])
114115
expect(await page.$text('button')).toContain('has fetch')
116+
await page.close()
115117
})
116118

117119
test('ssr: /nested/child', async () => {
@@ -127,40 +129,41 @@ describe('basic browser', () => {
127129
expect(team.includes('Atinux'))
128130
expect(await page.$text('div')).toContain('foo-bar-baz')
129131
expect(await page.$text('div')).toContain('fizz-buzz')
132+
await page.close()
130133
})
131134

132135
test('ssr: /fetch-root', async () => {
133136
const page = await browser.page(url('/fetch-root'))
134137
expect(await page.$text('button')).toContain('has fetch')
135-
page.close()
138+
await page.close()
136139
})
137140

138141
test('ssr: /fetch-client', async () => {
139142
const page = await browser.page(url('/fetch-client'))
140143
expect(await page.$text('p')).toContain('Fetching...')
141144
await page.waitForSelector('pre')
142145
expect(await page.$text('pre')).toContain('pi0')
143-
page.close()
146+
await page.close()
144147
})
145148

146149
test('ssr: /fetch-conditional', async () => {
147150
const page = await browser.page(url('/fetch-conditional'))
148151
expect(await page.$text('pre')).toContain('galvez')
149-
page.close()
152+
await page.close()
150153
})
151154

152155
test('ssr: /fetch-conditional?fetch_client=true', async () => {
153156
const page = await browser.page(url('/fetch-conditional?fetch_client=true'))
154157
expect(await page.$text('p')).toContain('Fetching...')
155158
await page.waitForSelector('pre')
156159
expect(await page.$text('pre')).toContain('pimlie')
157-
page.close()
160+
await page.close()
158161
})
159162

160163
test('ssr: /fetch-error', async () => {
161164
const page = await browser.page(url('/fetch-error'))
162165
expect(await page.$text('#error')).toContain('fetch-error')
163-
page.close()
166+
await page.close()
164167
})
165168

166169
test('ssr: /fetch-deep', async () => {
@@ -200,7 +203,7 @@ describe('basic browser', () => {
200203
async2: 'data2fetch'
201204
})
202205

203-
page.close()
206+
await page.close()
204207
})
205208

206209
// Close server and ask nuxt to stop listening to file changes
@@ -210,7 +213,6 @@ describe('basic browser', () => {
210213

211214
// Stop browser
212215
afterAll(async () => {
213-
await page.close()
214216
await browser.close()
215217
})
216218
})

test/e2e/spa-base.browser.test.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const browser = new Browser()
66
const url = route => 'http://127.0.0.1:' + port + route
77

88
let nuxt = null
9-
let page = null
109

1110
describe('spa router base browser', () => {
1211
beforeAll(async () => {
@@ -24,7 +23,7 @@ describe('spa router base browser', () => {
2423
})
2524

2625
test('Open /app (router base)', async () => {
27-
page = await browser.page(url('/app'))
26+
const page = await browser.page(url('/app'))
2827

2928
expect(await page.evaluate(() => location.href)).toBe(url('/app/'))
3029

@@ -34,28 +33,32 @@ describe('spa router base browser', () => {
3433
const headings = document.evaluate("//div[text()='Hello SPA!']", document, null, XPathResult.ANY_TYPE, null)
3534
return headings.iterateNext()
3635
})).not.toBe(null)
36+
await page.close()
3737
})
3838

3939
test('Open /app/ (router base with trailing slash)', async () => {
40-
page = await browser.page(url('/app/'))
40+
const page = await browser.page(url('/app/'))
4141

4242
expect(await page.evaluate(() => location.href)).toBe(url('/app/'))
4343

4444
expect(await page.html()).not.toContain('This page could not be found')
45+
await page.close()
4546
})
4647

4748
test('Open /app/mounted', async () => {
48-
page = await browser.page(url('/app/mounted'))
49+
const page = await browser.page(url('/app/mounted'))
4950

5051
expect(await page.$text('h1')).toMatch('Test: updated')
52+
await page.close()
5153
})
5254

5355
test('/app/unknown', async () => {
54-
page = await browser.page(url('/app/unknown'))
56+
const page = await browser.page(url('/app/unknown'))
5557

5658
expect(await page.evaluate(() => location.href)).toBe(url('/app/unknown'))
5759

5860
expect(await page.html()).toContain('This page could not be found')
61+
await page.close()
5962
})
6063

6164
// Close server and ask nuxt to stop listening to file changes
@@ -65,7 +68,6 @@ describe('spa router base browser', () => {
6568

6669
// Stop browser
6770
afterAll(async () => {
68-
await page.close()
6971
await browser.close()
7072
})
7173
})

0 commit comments

Comments
 (0)