Skip to content

Commit f5166fa

Browse files
committed
feat(playwright): expose _nuxtHooks fixture setup function
1 parent 5f5a5be commit f5166fa

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

Diff for: src/playwright.ts

+17-8
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,22 @@ type TestOptions = {
1515
goto: (url: string, options?: GotoOptions) => Promise<Response | null>
1616
}
1717

18+
/**
19+
* The function used to create the _nuxtHooks fixture internally.
20+
* 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.
21+
* @param nuxt the nuxt config that should be used to create the nuxt app to test
22+
* @param use the `use` function of playwright
23+
*/
24+
export const nuxtHooksFixture = async (
25+
nuxt: ConfigOptions['nuxt'],
26+
use: (hooks: WorkerOptions['_nuxtHooks']) => Promise<void>,
27+
) => {
28+
const hooks = createTest(nuxt || {})
29+
await hooks.setup()
30+
await use(hooks)
31+
await hooks.afterAll()
32+
}
33+
1834
/**
1935
* Use a preconfigured Nuxt fixture.
2036
*
@@ -31,14 +47,7 @@ type TestOptions = {
3147
*/
3248
export const test = base.extend<TestOptions, WorkerOptions & ConfigOptions>({
3349
nuxt: [undefined, { option: true, scope: 'worker' }],
34-
_nuxtHooks: [
35-
async ({ nuxt }, use) => {
36-
const hooks = createTest(nuxt || {})
37-
await hooks.setup()
38-
await use(hooks)
39-
await hooks.afterAll()
40-
}, { scope: 'worker' },
41-
],
50+
_nuxtHooks: [({ nuxt }, use) => nuxtHooksFixture(nuxt, use), { scope: 'worker' }],
4251
baseURL: async ({ _nuxtHooks }, use) => {
4352
_nuxtHooks.beforeEach()
4453
await use(url('/'))

0 commit comments

Comments
 (0)