-
-
Notifications
You must be signed in to change notification settings - Fork 97
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 extension is confused when same tests are run in Node and Browser mode #516
Comments
This is a limitation of Vitest API, unfortunately. It only accepts files. It behaves the same in the CLI. I will try to find a workaround. |
Does it? If I run the tests with $ npx vitest run
RUN v2.1.4 /home/k/Projects/vitest-bugs/vitest-bug-2
[Browser] Browser runner started by playwright at http://localhost:63315/
stdout | sum.test.js > sum > sums numbers
User Agent: Node.js/22
stdout | sum.test.js > sum > sums numbers
User Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/130.0.6723.31 Safari/537.36
✓ |Node| sum.test.js (1)
✓ |Browser| sum.test.js (1)
Test Files 2 passed (2)
Tests 2 passed (2)
Start at 19:20:53
Duration 642ms (transform 52ms, setup 0ms, collect 10ms, tests 5ms, environment 0ms, prepare 366ms) And I can run them separately without problems. |
The double run is weird indeed.
What you cannot do in Vitest is rerun a specific test in a specific project in watch mode (which is what the extension is using). The extension never runs the vitest command. |
Ah, ok, I understand now. So my current workaround with prefixing the top-level test description depending on test environment works because the extension and vitest itself see the same names. When the extension would add such a prefix itself internally then vitest can't find the test... I hope you find a workaround or vitest can be extended to improve the situation. Thank you, for looking into it. |
Turns out there is a non-hacky way to achieve that (#517). It doesn't work with the continuous mode yet, though. |
@sheremet-va It's much better now, thanks a lot! But it still has some problems: When I freshly open the project and then right-click the Test play button at the Clicking "Refresh Tests" in the Testing panel doesn't change that. I have to first click "Run Tests" in the Testing Panel to do a full test run and THEN the context menu show the sub menus and they work fine (Only executing the test in one project, as expected) but it is still not possible to see which one is which: Maybe prefix/suffix the menu titles with the project name? Like it is done in the Testing panel? Shall I create a new issue for this? Or do you want to reopen this one? |
Yeah, it looks like we have to go back to displaying the project as |
Describe the bug
The Vitest documentation suggests to use Vitest Workspaces to have both Node and Browser mode tests. I know they possibly meant having DIFFERENT tests for browser and node but in my opinion it perfectly makes sense to run the same tests in both environments to ensure that the project works correctly in Node and Browser and no node-specific or browser-specific features were used in the code.
It looks like the vitest vscode extension have some support for this scenario because it distinguishes between the two different test modes in the Testing panel. The test is listed twice and the workspace project name (Browser and Node) is shown next to it:
But when you click the play button on the Browser or Node Test in the Testing panel then always both Tests are executed (both useragents are logged in console):
When clicking the play button in the code panel (at the
describe
orit
line) then both tests are even executed two times (both user agents are logged twice in console):The context menu on the play buttons is also confused, it shows the same line twice, and no matter which one you use, both tests are executed:
I think this whole confusion is triggered because the Node and Browser Test have the same test path. Maybe it can be fixed by also looking at the workspace project name ("Node" and "Browser" in this case) to distinguish the tests from each other?
Reproduction
npm i
Output
Version
1.6.2
Validations
The text was updated successfully, but these errors were encountered: