Skip to content

Setting vitest environment in package.json doesn't play well with VS Code's vitest extension #199

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

Closed
segevfiner opened this issue Nov 22, 2022 · 7 comments
Labels
enhancement New feature or request

Comments

@segevfiner
Copy link

Setting the vitest environment to jsdom in the package.json instead of in vite.config.ts doesn't play well with the VS Code vitest extension which won't know about it and will fail to run vitest without further configuration.

"test:unit": "vitest --environment jsdom --root src/"

@segevfiner segevfiner changed the title Setting vitest environment in package.json doesn't play well with VS Code vitest extension Setting vitest environment in package.json doesn't play well with VS Code's vitest extension Nov 22, 2022
@haoqunjiang
Copy link
Member

I think this needs to be reported to the Vitest VS Code extension instead of here?

It is a fair use of the CLI arguments considering how few options the command needs to use. The VS Code extension should support this use case.

@segevfiner
Copy link
Author

How would it know which script it should look at? There is probably a VS Code setting to set which CLI arguments should be used, but that's not as good as it just working without further configuration.

@haoqunjiang
Copy link
Member

I think they can use some heuristics to suggest a setting.

But yeah, your argument makes sense. It is not ideal.
I need to figure out a way to make it work out of the box without sacrificing simplicity.

@segevfiner
Copy link
Author

Isn't just setting it in vite.config.ts simple enough?

@haoqunjiang
Copy link
Member

I kinda don't like using /// <reference types="vitest" />, so I'm looking into the documentation, trying to find a different way now. If there turn out to be no better options, I'll use it then.

@haoqunjiang haoqunjiang added the enhancement New feature or request label Jan 5, 2023
@segevfiner
Copy link
Author

BTW, Seems like this had another unfortunate side effect, vitest in VS Code didn't know about the root flag so it would also pick up playwright tests.

@haoqunjiang
Copy link
Member

Yeah, the --root src/ argument was initially introduced to work around that problem.

Anyway, thanks to @beta, now we'll create a perfectly working and scalable vitest.config.js file for new projects: https://github.com/vuejs/create-vue/pull/227/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants