-
-
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
src/test.ts
is picked up as a test
#3530
Comments
Start a new pull request in StackBlitz Codeflow. |
Our new patterns don't actually align with Jest 100%: 🤔 Jest:
Vitest:
But it is still expected change, since the same happens in Jest: https://jestjs.io/docs/configuration#testmatch-arraystring
|
I've added a note to release notes about this breaking change. |
How to exclude files now? I had |
The mechanism didn't change. Only default values. If you have custom patterns, it should work. Check that your pattern is correct. |
Ahh, my bad. Just checked it closely and |
In our codebase, switching to EDIT: setting |
I don't know what documentation you are reading but in 0.32.0 the default is this:
|
This is an expected breaking change which is described in the release notes. |
@sheremet-va It seems like our glob parser allows
@sheremet-va is right, picking up files named We should still keep this open for docs though. |
Honestly, when I used jest I never named or even considered naming a test file I still think it is counter intuitive and would advise against supporting this pattern. I think the fact that jest had to have a separate sentence explaining that this was the case is a sign of a non intuitive pattern. In general one thing I love about vitest is how zero configuration it is, which is why I raised the issue in the first place. Good defaults/conventions matter. But it is totally up to you. I will just be adding the pattern to our exclude array. Renaming the file in our own context would be be more confusing. |
I am open to discussing the best course of action here. I do agree that the pattern seems non-intuitive. We can revert the On the same note, I think Vitest team should reevaluate what we mean by Jest compatibility and make a paragraph in docs about this. People's requests are getting ridiculous by this point - adding features just because "they work like this in jest, makes for easier migration, and so on". |
As someone who's used Jest for years, I've often used Can we please start by documenting this change (which I'd be willing to work on) and waiting for more feedback? While I respect the concerns of other maintainers around back compatibility, we did release this with a compatibility warning, and we could prevent additional confusion by improving the docs. In Nuxt's case, I think modifying Vitest's includes or excludes would be the best solution. Alternatively if the Vitest team decides not to pursue Jest compatibility by default, can we please document this and ideally add some sort of option/config/codemod for Jest compatibility? This could include other differences in defaults from Jest including |
I really hate this change :( Using
|
Personally as a Jest user, I find assuming a
Do you have an example of this? Specifically I'm interested in knowing if any frameworks have their own |
I can't figure out an example right now, sorry :( |
It's very common for codebases to have mocks and other test utilities within the tests folders, they shouldn't be picked up. Right now even a file named Including only spec, or test files is a better default for any project, small or big because it enforces a helpful, longstanding convention that, by default, filters out non-test files. In other words, the previous behavior was sensitive default that encouraged better organization practices. Because of this I really think reverting this change would be beneficial for all vitest users. This is one of the points where vitest had a better default than jest 😄 |
I've created a draft PR for this, you can merge it once this suggestion is accepted, or simply close it :) |
PR should be a revert of #3392 if we decide to go back (at least include/exclude) |
I guess we can partially revert it because it still has quite a few parts worth keeping, such as simplified globs. That's why I created a new PR :) |
While I'm still open to discussion on this change, can we please publish docs on these changes before deciding to revert work and publish another breaking change? I agreed to add docs previously, and at the time I didn't realize this was being published without docs. I think most of the confusion that has been communicated in this thread is resulted from a lack of docs clarifying the change (outside of the release notes). Additionally, this issue still has the labels of a documentation fix, not a breaking change. I've pushed #3737 to help resolve the original issue with missing docs. |
Personally (but I think I’m not the only one) my problem is not about docs, my problem is the new default is worse than the previous one for the mentioned reasons. It’s not about labeling either, those are just organizational details. As an example: you could label this as a regression and a fix if you wanted to but what matter is not that it breaks, all software does and that’s just fine. What matter is that a sensitive default is adopted (or rather restored) |
I wasn't aware of the initial PR. Here are my thoughts:
To make a trade-off, we could introduce a preset system, or just a bare Jest-favor default object that makes for easier opt-in. Something like: import { defaultJestConfig } from 'vitest'
export default defineConfig({
test: {
...defaultJestConfig,
// user configs
}
} |
Describe the bug
This may not be a bug but I would consider it non-intuitive.
A file named
src/test.ts
is picked up as a test. I would suggest thattest.ts
should be required as a suffix rather than directly as a file name.Context:
Our CI started failing because we have a
test
command in our source code: https://github.com/nuxt/nuxt/actions/runs/5193588330/jobs/9364317315?pr=21410Introduced in glob changes in #3392.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-e9txbr?file=test.ts,test/basic.test.ts&initialPath=__vitest__/
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: