-
-
Notifications
You must be signed in to change notification settings - Fork 298
fix(vitest-angular): reset TestBed between tests in Vitest Browser Mode
#1995
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
fix(vitest-angular): reset TestBed between tests in Vitest Browser Mode
#1995
Conversation
✅ Deploy Preview for analog-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-app ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for analog-blog ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
c63abea to
b24883a
Compare
| export function setupTestBed( | ||
| options: TestBedSetupOptions = { zoneless: true, providers: [] }, | ||
| ) { | ||
| beforeEach(getCleanupHook(false)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, we're sure the hooks will be registered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you see any tests slow down by putting them here? Or does it have no impact with the Vitest fixes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No slowdown observed, and it shouldn't slow down anything.
libs/my-package/src/lib/my-package/reset-test-bed-between-tests.spec.ts
Outdated
Show resolved
Hide resolved
b24883a to
bd59992
Compare
TestBed between tests in Vitest Browser ModeTestBed between tests in Vitest Browser Mode
|
@yjaaidi just needs merge conflicts resolved. |
Vitest Browser Mode caches modules and does not re-execute side-effects. Therefore, when hooks are cleared, they are not set up again so TestBed is not reset after each test. Vitest was fixed to allow side-effects on setup files by not caching them (see vitest-dev/vitest#8884), but the behavior is not recursive so hooks that are registered as side effects in other files such as `@analogjs/vitest-angular/setup-testbed.ts` will not work. The solution is to register these hooks inside the `setUsetupTestBed` function. Closes analogjs#1994
1baf01a to
a8d9be0
Compare
Really weird, I can't reproduce the conflict locally 😅. Any clues? Should I open another PR? Update: 🤦🏻♂️ I was targeting |
|
P.S.: I've updated the tests to avoid false negatives where the tests could pass when using multiple workers, or disabling/removing other tests such as the |
Vitest Browser Mode caches modules and does not re-execute side-effects.
Therefore, when hooks are cleared, they are not set up again so TestBed
is not reset after each test.
Vitest was fixed to allow side-effects on setup files by
not caching them (see vitest-dev/vitest#8884),
but the behavior is not recursive so hooks that are
registered as side effects in other files such as
@analogjs/vitest-angular/setup-testbed.tswill not work.The solution is to register these hooks inside the
setUsetupTestBedfunction.