-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 execution in a browser page #586
Comments
Vitest is designed to run only inside Node. That's why we have Our general recommendation is to use Cypress for UI testing. |
I see. Yeah, it is probably out of scope. |
@holtwick If I understand you correctly, mocha-vite-puppeteer might give you what you want, as it runs code and tests inside Puppeteer, instead of inside Node. |
I guess this comes close to what I intended: #891 I created a kind of runtime to be loaded before running a regular behavioral test. Maybe this gist gives an idea of it: https://gist.github.com/holtwick/ec4219363808a0d066ef02fd6c405077 |
Now that #891 is on-going, I think this issue could be re-opened for discussion related to topic. How should vitest handle coverage when tests are running in the browser? Currently vitest is using nodejs's V8 API +
This would mean that coverage collection would be limited to Chromium based browsers only. Using something like |
Introduced browser testing is very limited at the moment, and doesn't support many features (including module mocking and snapshots). And not even released :) Not sure if we should discuss it here, or open a proper roadmap issue |
You might want karma-vite |
I'm interested when browser testing becomes more generally available. My use case is for writing isomorphic JavaScript modules that can run on Node.js as well as in the browser. I'm currently using Karma + Jasmine to test in browsers, while just using Jasmine for Node, which gives me the benefit of only having to write the tests once, but there's still a bit of overhead that I'd like to simplify. |
If anyone is using Vite and wants browser tests, Cypress Component Testing works with your existing Vite config out of the box. https://docs.cypress.io/guides/component-testing/overview It's aimed at component tests and UI development, but this might be useful for people in the "I am using Vite, but I want to run some tests in a browser, too". |
Clear and concise description of the problem
Currently, vitest is executing test in the classic way on the node.js engine. I would like to execute my (non UI) vitest also on real browsers in their environment.
The benefit is to test for granular differences in different browsers like missing features or APIs. For example IndexedDB or Crypto related test.
Suggested solution
Reuse vitest environment to allow test execution in a web page. vite should be able to do the necessary updates quickly. Just provide a simple output like the one we get with the
--ui
option.There is no need for automation regarding launching browsers etc. this could be achieved by integrating calls to the web pages by Cypress, Puppeteer, Playwright etc. if required.
Alternative
Cypress, Playwright, etc. provide their own test environment and focus on user interfaces.
Additional context
I made a tiny implementation for my own purposes: https://github.com/holtwick/zeed/blob/master/demos/tests/src/jest.ts
Validations
The text was updated successfully, but these errors were encountered: