Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/playwright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ type TestOptions = {
goto: (url: string, options?: GotoOptions) => Promise<Response | null>
}

/**
* The function used to create the _nuxtHooks fixture internally.
* It's exported so projects have the option to overwrite the `_nuxtHooks` fixture and e.g. overwrite settings in the nuxt config before the nuxt app is built.
* @param nuxt the nuxt config that should be used to create the nuxt app to test
* @param use the `use` function of playwright
*/
export const nuxtHooksFixture = async (
nuxt: ConfigOptions['nuxt'],
use: (hooks: WorkerOptions['_nuxtHooks']) => Promise<void>,
) => {
const hooks = createTest(nuxt || {})
await hooks.setup()
await use(hooks)
await hooks.afterAll()
}

/**
* Use a preconfigured Nuxt fixture.
*
Expand All @@ -31,14 +47,7 @@ type TestOptions = {
*/
export const test = base.extend<TestOptions, WorkerOptions & ConfigOptions>({
nuxt: [undefined, { option: true, scope: 'worker' }],
_nuxtHooks: [
async ({ nuxt }, use) => {
const hooks = createTest(nuxt || {})
await hooks.setup()
await use(hooks)
await hooks.afterAll()
}, { scope: 'worker' },
],
_nuxtHooks: [({ nuxt }, use) => nuxtHooksFixture(nuxt, use), { scope: 'worker' }],
baseURL: async ({ _nuxtHooks }, use) => {
_nuxtHooks.beforeEach()
await use(url('/'))
Expand Down