diff --git a/src/playwright.ts b/src/playwright.ts index 5577269d90..263ac538dc 100644 --- a/src/playwright.ts +++ b/src/playwright.ts @@ -15,6 +15,22 @@ type TestOptions = { goto: (url: string, options?: GotoOptions) => Promise } +/** + * 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, +) => { + const hooks = createTest(nuxt || {}) + await hooks.setup() + await use(hooks) + await hooks.afterAll() +} + /** * Use a preconfigured Nuxt fixture. * @@ -31,14 +47,7 @@ type TestOptions = { */ export const test = base.extend({ 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('/'))