test-utils icon indicating copy to clipboard operation
test-utils copied to clipboard

feat(playwright): expose _nuxtHooks fixture setup function

Open markbrockhoff opened this issue 1 year ago • 1 comments

Hi,

I just setup a mock server to mock third party requests made by my nuxt app while running tests with playwright. In order to redirect those requests to the mock server I overwrote the _nuxtHooks playwright fixture with my own to modify the nuxt config, injecting the url to my mock server into it.

All of this works great but I'd like to keep using the original _nuxtHooks fixture if possible, just modifying the nuxt config passed to it before the app is built. That's why I extracted it into an exported function so projects can easily modify the nuxt config used for the test app depending on their custom fixtures.

For example like this:

import { test as base, nuxtHooksFixture } from "@nuxt/test-utils/playwright";

export const test = base.extend({
  _nuxtHooks: [
    async ({ nuxt, otherFixture }, use) => {
        // Just imagine that some custom fixure `otherFixture` needs to define the port the nuxt app needs to use
        // By overwriting the _nuxtHooks fixture this is now easily possible.
        await nuxtHooksFixture({ ...nuxt, port: otherFixture.port });
    },
    { scope: "worker" },
  ],
});

Please let me know what you think :)

markbrockhoff avatar Jul 19 '24 14:07 markbrockhoff

Btw: I think the CI pipeline might be broken or flaky as I don't really see a reason why the made change would cause that test to fail on windows and it's failing on main as well ^^'

markbrockhoff avatar Jul 19 '24 15:07 markbrockhoff