From d121d4294b8ae4400e6a4ee00b5d4d4a77b494de Mon Sep 17 00:00:00 2001 From: Mark Brockhoff Date: Fri, 19 Jul 2024 16:36:18 +0200 Subject: [PATCH] feat(playwright): expose _nuxtHooks fixture setup function --- src/playwright.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/playwright.ts b/src/playwright.ts index 5577269d9..263ac538d 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('/'))