Skip to content

Commit

Permalink
feat(playwright): expose _nuxtHooks fixture setup function
Browse files Browse the repository at this point in the history
  • Loading branch information
markbrockhoff committed Jul 22, 2024
1 parent 5f5a5be commit f5166fa
Showing 1 changed file with 17 additions and 8 deletions.
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

0 comments on commit f5166fa

Please sign in to comment.