Skip to content

fix(vitest): override config.include option with config.browser.instances[].include option if it is specified #8260

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

Conversation

Shinyaigeek
Copy link
Contributor

@Shinyaigeek Shinyaigeek commented Jul 4, 2025

Description

Close: #7914

Hi Team 👋

As described in #7914 (comment), I understand that #7914 happens because mergeConfig merges array in config object instead of overriding it.

As mentioned in docs, vitest config root's include option has ['**/*.{test,spec}.?(c|m)[jt]s?(x)'] as default value, and config which is calculated per browser instance configuration will be like below:

// input vitest.config.ts

export default defineConfig({
  test: {
    browser: {
      enabled: true,
      provider: 'playwright',

      instances: [
        // Run all tests with Chromium, it's stable
        { browser: "chromium" },

        // Firefox is flaky, run just one test 
        { browser: "firefox", include: ["test/something-simple.test.ts"] },
      ],
    },
    // include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)'] as default value
  },
});

// output config for chromium
export default defineConfig({
  test: {
    ...config,
    include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)']
});

// output config for firefox
export default defineConfig({
  test: {
    ...config,
    include: ['**/*.{test,spec}.?(c|m)[jt]s?(x)', "test/something-simple.test.ts"]
});

and so, '**/*.{test,spec}.?(c|m)[jt]s?(x)' pattern in firefox's config will match test files which should be ignored by config.browsers.instances[firefox].include.

I thought vitest user expect include config in deeper will be prioritized than the root that, so I fixed this issue by ignoreing project root's include value if config.browser.instances[].include is specified.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. If the feature is substantial or introduces breaking changes without a discussion, PR might be closed.
  • Ideally, include a test that fails without this PR but passes with it.
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Tests

  • Run the tests with pnpm test:ci.

Documentation

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs command.

Changesets

  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.

Copy link

netlify bot commented Jul 4, 2025

Deploy Preview for vitest-dev ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit d59b896
🔍 Latest deploy log https://app.netlify.com/projects/vitest-dev/deploys/6877dda33d34330008e35f5d
😎 Deploy Preview https://deploy-preview-8260--vitest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Shinyaigeek Shinyaigeek force-pushed the override-include-with-browser-instance-config branch from f83b803 to f454f39 Compare July 4, 2025 17:53
Copy link
Member

@sheremet-va sheremet-va left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Let's also apply this to exclude and includeSource

@@ -321,6 +322,8 @@ function cloneConfig(project: TestProject, { browser, ...config }: BrowserInstan
providerOptions: config,
instances: undefined, // projects cannot spawn more configs
},
// If there is no include pattern in browser.instances[], we should use the include pattern from the parent project
include: (overrideConfig.include && overrideConfig.include.length > 0) ? [] : clonedConfig.include,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also have exclude and includeSource here, they usually all go together as a single source of test files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense! Thank you! d59b896

…stances[].include` option if it is specified
…` option within `config.browser.instances[]` option if it is specified
@Shinyaigeek Shinyaigeek force-pushed the override-include-with-browser-instance-config branch from 3ec9ef0 to d59b896 Compare July 16, 2025 17:13
@Shinyaigeek Shinyaigeek requested a review from sheremet-va July 16, 2025 17:28
@sheremet-va sheremet-va merged commit 010fc55 into vitest-dev:main Aug 4, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

browser.instances[].includes is ignored
2 participants