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

Running a single project with browsers fails with Cannot read properties of undefined (reading 'provider') #7308

Closed
6 tasks done
JReinhold opened this issue Jan 20, 2025 · 3 comments · Fixed by #7313
Closed
6 tasks done

Comments

@JReinhold
Copy link

JReinhold commented Jan 20, 2025

Describe the bug

When running a single Vitest project with npx vitest run --project=myproject and a browser configuration, Vitest fails with:

⎯⎯ Unhandled Errors ⎯⎯

Vitest caught 1 unhandled error during the test run.
This might cause false positive tests. Resolve unhandled errors to make sure your tests are not affected.


⎯⎯ Unhandled Errors ⎯⎯
TypeError: Cannot read properties of undefined (reading 'provider')
 ❯ executeTests node_modules/@vitest/browser/dist/index.js:2997:30
 ❯ runWorkspaceTests node_modules/@vitest/browser/dist/index.js:3083:13
 ❯ executeTests node_modules/vitest/dist/chunks/resolveConfig.DATSOo7x.js:7720:5
 ❯ node_modules/vitest/dist/chunks/cli-api.B7hOUwun.js:12524:11
 ❯ Vitest.runFiles node_modules/vitest/dist/chunks/cli-api.B7hOUwun.js:12551:12
 ❯ Vitest.start node_modules/vitest/dist/chunks/cli-api.B7hOUwun.js:12431:21
 ❯ startVitest node_modules/vitest/dist/chunks/cli-api.B7hOUwun.js:13563:7
 ❯ start node_modules/vitest/dist/chunks/cac.CHB7MTUk.js:1571:17
 ❯ CAC.run node_modules/vitest/dist/chunks/cac.CHB7MTUk.js:1542:3

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯

 Test Files   (1)
      Tests  no tests
     Errors  1 error
   Start at  15:08:17
   Duration  26ms (transform 0ms, setup 0ms, collect 0ms, tests 0ms, environment 0ms, prepare 0ms)

Running without the project specifier (npx vitest run) works without issues. Running with browsers disabled works too.

It fails regardless if you use the new instances configuration structure or if you use the old name property.

The bug was introduced in v3.0.0-beta.3, as v3.0.0-beta.2 does not appear to exhibit this behavior. Most likely as a result of #6975 .

Reproduction

See reproduction at https://github.com/JReinhold/vitest-browser-config-project-bug

  1. git clone [email protected]:jreinhold/vitest-browser-config-project-bug.git
  2. cd vitest-browser-config-project-bug
  3. npm install
  4. npx playwright install
  5. npx vitest run
  6. See that it works
  7. npx vitest run --project=myproject
  8. See that it fails

System Info

System:
    OS: macOS 13.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 60.48 MB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.20.2 - ~/Library/Caches/fnm_multishells/90016_1737113474856/bin/node
    Yarn: 1.22.22 - ~/Library/Caches/fnm_multishells/90016_1737113474856/bin/yarn
    npm: 10.8.3 - ~/Library/Caches/fnm_multishells/90016_1737113474856/bin/npm
    pnpm: 9.12.3 - ~/Library/Caches/fnm_multishells/90016_1737113474856/bin/pnpm
  Browsers:
    Chrome: 132.0.6834.83
    Edge: 132.0.2957.115
    Safari: 16.2
  npmPackages:
    @vitest/browser: ^3.0.2 => 3.0.2 
    vite: ^6.0.5 => 6.0.9 
    vitest: ^3.0.2 => 3.0.2

Used Package Manager

npm

Validations

@chapmanio
Copy link

I'm getting the same, it might be related to this line

if (!config.headless || !project.browser!.provider.supportsParallelism) {

  function getThreadsCount(project: TestProject) {
    const config = project.config.browser
    
    // this line, it should be `project.config.browser`
    if (!config.headless || !project.browser!.provider.supportsParallelism) { 
      return 1
    }

    if (!config.fileParallelism) {
      return 1
    }

    return vitest.config.watch
      ? Math.max(Math.floor(numCpus / 2), 1)
      : Math.max(numCpus - 1, 1)
  }

@chapmanio
Copy link

Actually there appear to be a few references looking for project.browser when the data is in project.config.browser

@sheremet-va
Copy link
Member

The code you mention is correct, config.browser obviously doesn't expose the provider object.

The error lies in another place. The filter is applied incorrectly to projects with instances. Under the hood, instances are just regular projects (the same as workspace), but with a special handling (they share the same vite server). If projects are filtered with --project=myproject, then the root browser project is kept, but instances are filtered out because their names are myproject (chromium). The correct filter here at the moment is --project=myproject (*) (this is a workaround).

This should be fixed in the next patch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants