-
Notifications
You must be signed in to change notification settings - Fork 85
/
playwright.ts
67 lines (62 loc) · 1.98 KB
/
playwright.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import defu from 'defu'
import { test as base } from '@playwright/test'
import type { Page, Response } from 'playwright-core'
import type { GotoOptions, TestOptions as SetupOptions, TestHooks } from './e2e'
import { createTest, url, waitForHydration } from './e2e'
export type ConfigOptions = {
nuxt: Partial<SetupOptions> | undefined
defaults: {
nuxt: Partial<SetupOptions> | undefined
}
}
type WorkerOptions = {
_nuxtHooks: TestHooks
}
type TestOptions = {
goto: (url: string, options?: GotoOptions) => Promise<Response | null>
}
/**
* Use a preconfigured Nuxt fixture.
*
* You can pass a `nuxt: {}` object in your device configuration, in the `use` key of your config file,
* or use the following syntax within your test file to configure your Nuxt fixture:
*
```ts
test.use({
nuxt: {
rootDir: fileURLToPath(new URL('.', import.meta.url)),
}
})
```
*
* In `playwright.config.ts` you can pass `defaults: { nuxt: {} }` object for merging with test.use nuxt options
*/
export const test = base.extend<TestOptions, WorkerOptions & ConfigOptions>({
nuxt: [undefined, { option: true, scope: 'worker' }],
defaults: [{ nuxt: undefined }, { option: true, scope: 'worker' }],
_nuxtHooks: [
async ({ nuxt, defaults }, use) => {
const hooks = createTest(defu(nuxt || {}, defaults.nuxt || {}))
await hooks.setup()
await use(hooks)
await hooks.afterAll()
}, { scope: 'worker' },
],
baseURL: async ({ _nuxtHooks }, use) => {
_nuxtHooks.beforeEach()
await use(url('/'))
_nuxtHooks.afterEach()
},
goto: async ({ page }, use) => {
await use(async (url, options) => {
const waitUntil = options?.waitUntil
if (waitUntil && ['hydration', 'route'].includes(waitUntil)) {
delete options.waitUntil
}
const response = await page.goto(url, options as Parameters<Page['goto']>[1])
await waitForHydration(page, url, waitUntil)
return response
})
},
})
export { expect } from '@playwright/test'