diff --git a/src/hooks.ts b/src/hooks.ts index ff62a1b4..f0326714 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -9,7 +9,7 @@ type SetupFunction = ( ctx: SetupContext ) => void | Record -const globalSetup = new Set() +let globalSetup: Set /** * Run a callback function in the global setup function. This should be called from a Nuxt plugin. @@ -34,6 +34,7 @@ export const onGlobalSetup = (fn: SetupFunction) => { */ export const globalPlugin: Plugin = context => { const { setup } = context.app + globalSetup = new Set() context.app.setup = (...args) => { let result = {} if (setup instanceof Function) { diff --git a/test/e2e/hooks.ts b/test/e2e/hooks.ts index 16e27cc1..098874f2 100644 --- a/test/e2e/hooks.ts +++ b/test/e2e/hooks.ts @@ -5,14 +5,17 @@ import { navigateTo, expectOnPage } from './helpers' fixture`onGlobalSetup` const assertions = async () => { - await expectOnPage('global setup was run on server') - await expectOnPage('global setup was run on client') + await expectOnPage('global setup was run 1 times on server') + await expectOnPage('global setup was run 1 times on client') await expectOnPage('globally injected value was received') } test('Runs plugin on server side page', async () => { await navigateTo('/hooks') await assertions() + + await navigateTo('/hooks') + await assertions() }) test('Runs plugin on client rendered page', async t => { diff --git a/test/fixture/pages/hooks.vue b/test/fixture/pages/hooks.vue index 56cc94d6..e1203b5d 100644 --- a/test/fixture/pages/hooks.vue +++ b/test/fixture/pages/hooks.vue @@ -1,9 +1,9 @@