Skip to content

Enable restoreMocks in Vitest and remove manual vi.restoreAllMocks() calls - #483

Merged
dmarcos merged 1 commit into
sparkjsdev:mainfrom
mrxz:vitest-restore-mocks
Oct 16, 2026
Merged

dmarcos merged 1 commit into
sparkjsdev:mainfrom
mrxz:vitest-restore-mocks

Conversation

@mrxz

@mrxz mrxz commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Noticed while writing unit tests for #463 that the majority of unit test files include an afterEach callback for restoring all mocks through vi.restoreAllMocks(). Vitest offers a convenience feature that automatically calls this method before each test (see https://vitest.dev/config/restoremocks#restoremocks).

This PR enables restoreMocks in the vite.config.ts and removes the afterEach callbacks from the unit tests.

This does mean the timing changes slightly, from after tests to before tests, but this should be indistinguishable. It now also happens unconditionally, though most likely the snippet would've been copied in most tests files anyway. As mentioned in the Vitest documentation it can cause issue when using test.concurrent, but I don't see any immediate reason where we'd start using that.

@oscarlorentzon oscarlorentzon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Comment thread test/unit/SparkRenderer.test.ts Outdated
@mrxz
mrxz force-pushed the vitest-restore-mocks branch from 0524fb9 to 16079a5 Compare October 14, 2026 09:52
@dmarcos

dmarcos commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Need a small rebase

@mrxz
mrxz force-pushed the vitest-restore-mocks branch from 16079a5 to 38426d2 Compare October 16, 2026 09:45
@mrxz

mrxz commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator Author

@dmarcos I've rebased it.

@dmarcos

dmarcos commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Thank you!

@dmarcos
dmarcos merged commit 2959531 into sparkjsdev:main Oct 16, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants