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

Vitest browser mode tests not working when running in a sub directory #4522

Closed
6 tasks done
nicojs opened this issue Nov 16, 2023 · 3 comments
Closed
6 tasks done

Vitest browser mode tests not working when running in a sub directory #4522

nicojs opened this issue Nov 16, 2023 · 3 comments

Comments

@nicojs
Copy link
Contributor

nicojs commented Nov 16, 2023

Describe the bug

Similar to #3363, vitest's browser mode doesn't work when run from a subdirectory.

For example, this directory tree:

.
├── package-lock.json
├── package.json
└── test-resources
    └── browser-project
        ├── node_modules
        ├── package.json
        ├── src
        │   ├── heading.component.spec.ts
        │   └── heading.component.ts
        └── vitest.config.js

And you cd into test-resources/browser-project and run npx vitest, you get this error (or similar):

TypeError: Failed to fetch dynamically imported module: http://localhost:5173/@id/vitest/utils

Reproduction

See this reproduction repo.

  1. Run npm i
  2. cd into test-resources/browser-project
  3. Run npx vitest

browser-project.zip

System Info

System:
    OS: Linux 5.15 Ubuntu 20.04.6 LTS (Focal Fossa)
    CPU: (16) x64 11th Gen Intel(R) Core(TM) i7-11850H @ 2.50GHz
    Memory: 5.18 GB / 15.49 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 18.18.0 - ~/.nvm/versions/node/v18.18.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v18.18.0/bin/yarn
    npm: 9.8.1 - ~/.nvm/versions/node/v18.18.0/bin/npm
    pnpm: 8.9.2 - ~/.nvm/versions/node/v18.18.0/bin/pnpm
  Browsers:
    Chrome: 118.0.5993.117
  npmPackages:
    @vitest/browser: ^0.34.6 => 0.34.6 
    vitest: ^0.34.6 => 0.34.6 

Used Package Manager

npm

Validations

@sheremet-va
Copy link
Member

This error should be fixed in the next beta release (already merged), it's not about a subdirectory

@nicojs
Copy link
Contributor Author

nicojs commented Nov 20, 2023

Thanks @sheremet-va. I've noticed beta5 got released yesterday and tried it on this example. It seems to work now 🎉

However, I now notice another issue when implementing browser mode inside StrykerJS's mono repo. The browser opens and seems to redirect infinitely; see the animated gif below.

You can find the source code for this example here: https://github.com/stryker-mutator/stryker-js/tree/feat/vitest-browser-mode/packages/vitest-runner/testResources/browser-project

vitest-infinite-reload

@nicojs
Copy link
Contributor Author

nicojs commented Nov 22, 2023

I've found the cause for this last error and created a new issue: #4570. Closing this one

@nicojs nicojs closed this as completed Nov 22, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants