-
-
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
Snapshot differs and fail when running all tests vs one test at time #3129
Comments
I know Vitest uses pretty-format from Jest and I found this Jest issue which seems related, but it was closed without actions.
I also tried to toggle export default defineConfig({
test: {
clearMocks: true,
threads: false,
snapshotFormat: {
escapeString: false, // <<-- toggling this option has zero effect on shapshot format output, why???
printBasicPrototype: false,
},
},
}); |
All tests with the same environment in |
I don't think that I have problem with the global scope being shared in this case. The issue is that the escaping of the snapshot is different when run one by one than it is when running all tests. I didn't have that issue with Jest, it's only in Vitest. Why would the property escape be different when run one at a time or when running all tests, why does it uses single quote vs double quotes? |
It does seem to be related to some global scope of some kind, I have to use What's strange also is that even though I use export default defineConfig({
test: {
cache: false,
clearMocks: true,
environment: 'node',
testTimeout: 60000,
setupFiles: ['./vitest/vitest-setup.ts', './vitest/silence-logging.ts', './helpers/npm/set-npm-userconfig.ts'],
watch: false,
provider: 'c8',
}
},
}); for now my only way to get consistent tests is to always run all tests and not one file at a time because some of them fails. It's too bad because that also mean that I can't always debug in VSCode one file at a time and that problem is only for snapshot escaping, the rest is working fine |
facing same issue. my test single database is conflicting insert by 2 test files. |
I took another look at this and this comment helped me find my problem, that I was having, the root cause was that I use different Snapshot Serializers in different unit tests and when running In summary, adding the serializer to all unit tests, not just some of them but all of them, fixed my issue. The shared scope is still a bit of an issue but at least now my result is the same in all cases, so I can close this issue |
Describe the bug
Migrating from Jest to Vitest (to support ESM), I see that all snapshots created by Vitest have different escaping and fail when running the entire tests but if I run them as a single filename pattern then they always pass (either by filename pattern in the CLI or via the VSCode debugger). When run one file at a time, it always pass and are equivalent to Jest snaphots (escaped with double quotes) but they are very different when running all tests at once (sometime escaped with single quotes & sometime without and sometime with double quotes).
The only thing that I can think of to bypass the problem for now would be to update all snapshots so that it passes in the CI but that is basically inversing the problem, it will then fail when run one at a time. I also think that the one at a time snapshot are the correct ones since they are equivalent to Jest before I started the migration to Vitest.
Reproduction
For a reproduction you can do a git checkout of this Lerna-Lite PR 537 and run all unit tests (follow installation instructions). I will merge the PR with the snapshot failures so that it can be inspected and I can continue with my migration to ESM. The only thing that is consistent in all of this is that it always fail when all tests are ran but always pass when run one at a time.
Also worth to know that I need to run Vitest with
--no-threads
since Lerna/Lerna-Lite unit tests are usingprocess.chdir()
extensively, what I wonder is why it is different when running the test one at a time, technically speaking it is supposed to be isolated because of the--no-threads
so why does it fail when running all tests? Is there another flag to really isolate each tests? I triedisolate
,useAtomic
andsingleThread
but none have any effects and are irrelevant, if I read correctly, when executed with--no-threads
, so... ?Fails when running all unit tests
Always pass when running one file at a time
System Info
Used Package Manager
pnpm
Validations
The text was updated successfully, but these errors were encountered: