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

Example missing showing basic browser testing? #362

Closed
4 tasks done
NullVoxPopuli opened this issue Dec 29, 2021 · 10 comments
Closed
4 tasks done

Example missing showing basic browser testing? #362

NullVoxPopuli opened this issue Dec 29, 2021 · 10 comments
Labels
documentation Improvements or additions to documentation

Comments

@NullVoxPopuli
Copy link

NullVoxPopuli commented Dec 29, 2021

Describe the bug

The docs seem to be focused on node-testing, which for a lot of people is a deal breaker (need to test browser-compatibility across multiple browsers, maybe via browserstack, etc -- so the dom-mocking libraries are simply not an option).

Reproduction

visiting https://vitest.dev/, it's not clear if browser testing is supported.
I have a hunch it is, based on how I think vitest works, but I haven't played around with it yet.

System Info

n/a

Validations

@antfu
Copy link
Member

antfu commented Dec 29, 2021

Vitest is for unit-testing on Node and does not run on browsers. We might need to document it more clearly tho

@antfu antfu added the documentation Improvements or additions to documentation label Dec 29, 2021
@NullVoxPopuli
Copy link
Author

testing in browsers is hugely important for libraries and anyone who needs to ensure a certain level of cross-browser support -- why not support running in browsers?

@antfu
Copy link
Member

antfu commented Dec 30, 2021

We recommend using Cypress or Web Test runner for that as a complement of Vitest
https://vitest.dev/guide/comparisons.html

@NullVoxPopuli
Copy link
Author

Those are too high level/abstracted.
The ability to do component testing is a need, and doing unit tests through cypress sounds very slow

@Smrtnyk
Copy link

Smrtnyk commented Dec 30, 2021

there is a similar issue for jest
jestjs/jest#848
they are interested in it but it requires some bigger changes
there is also
https://github.com/4Catalyzer/karma-jest
which seems unmantained

one thing that is tricky with adding real browser env is how to isolate context for tests in there?
maybe iframe per test file? parallel browser instances?
there could be leaks if one test pollutes the env

@NullVoxPopuli
Copy link
Author

You can't fully isolate context out of the box, but existing browser testing has techniques for managing and notifying when it does happen. (Deep recursive proxies on the grobals for dirty tracking could be an option, not sure how or if they did it pre-proxies, or even if they use proxies)

Non-dom/window using tests could run in parallel in workers, etc

@Uninen
Copy link

Uninen commented Dec 30, 2021

There's also Playwright for testing in browsers. Cypress and Playwright alone cover a humongous amount of deep and complex problems in the browser land, don't see why it would be wise to bring any of that in Vitest.

Component testing w/ Cypress, while being work in progress atm, works fine and compared to traditional e2e testing is not slow at all. I'm sure there can be innovation and optimizations made in this arena as well but IMHO if would be better suited as a plugin than a core feature for Vitest.

@NullVoxPopuli
Copy link
Author

Playwright uses some webdriver.io stuff... which isn't what I'm after.

I mean, I guess I'll just use vite and an index.html file that includes some test setup stuff.
It's cool that this is out of scope for vitest. I just don't personally understand the resistance to this kind of testing. 🤷

@hornta
Copy link

hornta commented Aug 24, 2022

@NullVoxPopuli I think you should reopen because this is really needed IMO. Playwright is the closest right now with their test runner and their experimental component testing. However I'm not interested in duplicating all my tests just to run them in browser.

@NullVoxPopuli
Copy link
Author

Yeah, I started yet-another-testing tool: https://github.com/NullVoxPopuli/ember-addon-test (tho, focused more on getting ember.js stuff running with vite in a test environment. -- but it turns out that (so far) it's totally agnostic to any frontend framework, and could work with anything right now (except that I've only set this up with qunit for the actual test framework (I don't imagine it'd be hard to support mocha or similar, but qunit is what I use)).

The main thing I have to figure out so far is launching browsers automatically (and reporting test results to the cli). I started that here: NullVoxPopuli/ember-addon-test#1

but testem (which doesn't require any additional dependencies to launch browsers (such as chromedriver or geckodriver)), isn't setup to be used by other tools... so... that's dissappointing.

Would be fantastic if vitest just.. had a browser mode, but, they'd pretty much need to fragment their docs, because so much of the current vitest docs are centered around the "testing in node" story.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

5 participants