Skip to content

[v3] Browser Mode: @vitest/coverage-v8 should work with multiple instances and --project=chromiumΒ #7286

Description

@OrbisK

Clear and concise description of the problem

I completely understand that v8 can only support chromium. But it would be good if v8 would not only look at the config, but also at the --project before throwing an error.

> vitest run --coverage --project="browser (chromium)"


⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Startup Error ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
Error: @vitest/coverage-v8 does not work with
{
  "browser": {
    "provider": "playwright",
    "instances": [
      {
        "browser": "chromium"
      },
      {
        "browser": "firefox"
      }
    ]
  }
}

Suggested solution

coverage error should take project filter into account

Alternative

No response

Additional context

No response

Validations

Activity

  1. changed the title [-][v3] Browser Mode: `@vitest/coverage-v8` does not work with multiple instances and `--project=chromium`[/-] [+][v3] Browser Mode: `@vitest/coverage-v8` should work with multiple instances and `--project=chromium`[/+] on Jan 18, 2025
  2. AriPerkkio commented on Jan 19, 2025

    @AriPerkkio
    Member

    The check is done around here:

    const playwrightChromiumOnly = browser.provider === 'playwright' && (browser.name === 'chromium' || browser.instances?.every(i => i.browser === 'chromium'))
    // Browser-mode "Playwright + Chromium" only features:
    if (browser.enabled && !playwrightChromiumOnly) {
    const browserConfig = {
    browser: {
    provider: browser.provider,
    name: browser.name,
    instances: browser.instances,
    },
    }
    if (resolved.coverage.enabled && resolved.coverage.provider === 'v8') {
    throw new Error(
    `@vitest/coverage-v8 does not work with\n${JSON.stringify(browserConfig, null, 2)}\n`
    + `\nUse either:\n${JSON.stringify({ browser: { provider: 'playwright', instances: [{ browser: 'chromium' }] } }, null, 2)}`
    + `\n\n...or change your coverage provider to:\n${JSON.stringify({ coverage: { provider: 'istanbul' } }, null, 2)}\n`,
    )
    }

  3. added
    feat: browser
    on Jan 19, 2025
  4. added
    feat: coverage
    p3-minor-bug
    and removed on Jan 20, 2025
  5. cyyynthia commented on Jan 22, 2025

    @cyyynthia

    I still observe this issue on Vitest 3.0.3

    $ pnpm vitest --version                                
    vitest/3.0.3 linux-x64 node-v22.11.0
    
    $ pnpm vitest --project "browser (chromium)" --coverage
    (...) Error: @vitest/coverage-v8 does not work with (...)
    
    $ pnpm vitest --project unit --coverage # Does not even use browser testing
    (...) Error: @vitest/coverage-v8 does not work with (...)
    // vite.config.ts, irrelevant parts redacted for clarity
    export default defineConfig({
      plugins: [ ... ],
      test: {
        reporters: ['default', 'junit'],
        outputFile: {
          html: './.reports/vitest/report.html',
          junit: './.reports/vitest/junit.xml',
        },
        coverage: {
          provider: 'v8',
          reporter: ['cobertura', 'text'],
          reportsDirectory: './.reports/vitest/coverage',
          exclude: [...coverageConfigDefaults.exclude, '**/*.story.vue'],
        },
        workspace: [
          {
            extends: true,
            test: {
              name: 'unit',
              include: [ ... ],
              exclude: [...defaultExclude, ... ],
              environment: 'happy-dom',
            },
          },
          {
            extends: true,
            optimizeDeps: {
              include: ['vue', 'radix-vue', 'radix-vue/date'],
            },
            test: {
              name: 'browser',
              include: ['src/**/*.browser.{test,spec}.?(c|m)[jt]s?(x)'],
              browser: {
                enabled: true,
                provider: 'playwright',
                testerHtmlPath: './browser-test.html',
                instances: [{ browser: 'chromium' }, { browser: 'firefox' }, { browser: 'webkit' }],
    
                screenshotFailures: true,
                screenshotDirectory: '.reports/vitest/screenshots',
              },
            },
          },
          {
            extends: true,
            test: {
              // Workaround: https://github.com/vitest-dev/vitest/issues/6755
              name: 'typecheck',
              exclude: ['**/*'],
              typecheck: {
                enabled: true,
                checker: 'vue-tsc',
              },
            },
          },
        ],
      },
    })
  6. OrbisK commented on Jan 22, 2025

    @OrbisK
    ContributorAuthor

    Can confirm that it does not work.

    Reproduction: (not minimal)

  7. locked and limited conversation to collaborators on Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: browserfeat: coveragep3-minor-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions