Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(playwright): expose _nuxtHooks fixture setup function #899

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

markbrockhoff
Copy link
Contributor

@markbrockhoff markbrockhoff commented Jul 19, 2024

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 :)

@dosubot dosubot bot added size:S This PR changes 10-29 lines, ignoring generated files. enhancement New feature or request labels Jul 19, 2024
@markbrockhoff
Copy link
Contributor Author

markbrockhoff commented Jul 19, 2024

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 markbrockhoff force-pushed the expose-nuxt-hooks-fixture branch 2 times, most recently from f5166fa to 412204b Compare July 29, 2024 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant