Skip to content

chore: migrate tests from Jest to Vitest#436

Merged
JoshuaKGoldberg merged 2 commits intoall-contributors:mainfrom
JoshuaKGoldberg:jest-to-vitest
Feb 12, 2026
Merged

chore: migrate tests from Jest to Vitest#436
JoshuaKGoldberg merged 2 commits intoall-contributors:mainfrom
JoshuaKGoldberg:jest-to-vitest

Conversation

@JoshuaKGoldberg
Copy link
Copy Markdown
Contributor

@JoshuaKGoldberg JoshuaKGoldberg commented Feb 10, 2026

closes #406
Switches from the old Jest config, which extended kcd-scripts/jest, to Vitest.

This was a little more involved than I'd first thought (hence this PR coming a week later than I expected). At first I tried a manual switch-over but got into a confusing state where imports weren't being properly mocked out with vi.mock. I then restarted with Copilot and used Research-Plan-Implement. Copilot nailed it in one go, with just a little docs & scripts cleanup needed on my end (I manually reviewed every file).

The only major behavioral difference in tests is that nock is now used in src/repo/__tests__/index.js instead of internal mocking of modules. The new tests keep the functions as asynchronous, whereas the old ones switched them to synchronous for testing (weird!). I actually like this as more of an end-to-end / comprehensive test, rather than specifically looking at implementation details of what that file imports.

I think we can ignore the failing coverage indirect changes check. If you look at the indirect changes in Codecov they're mostly on comment lines.

@JoshuaKGoldberg JoshuaKGoldberg marked this pull request as ready for review February 10, 2026 15:16
Copy link
Copy Markdown
Member

@JimMadge JimMadge left a comment

Choose a reason for hiding this comment

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

Looks good. I think the loss of coverage through indirect changes is just the cost of switching test frameworks. We can start focusing on maintaining/increasing coverage after we have this sorted.

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`addContributorsList create contributors section if content is empty 1`] = `
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@JoshuaKGoldberg thank you for this. i'm gonna approve but it just needs a quick rebase before we can merge!

i have one question about these snapshots. Do they get updated when we run the tests suite or do we need to update them separately? i'm familiar with casettes in Python, which seem similar BUT when i've used them we had to update them occasionally separately.

Copy link
Copy Markdown
Contributor Author

@JoshuaKGoldberg JoshuaKGoldberg Feb 12, 2026

Choose a reason for hiding this comment

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

Good question: they can be updated automatically, but only if you explicitly provide the -u / --update CLI option (https://vitest.dev/guide/cli.html#update).

  • Without -u: if snapshots mismatch, tests fail and print the diff
  • With -u: snapshots are updated for you automatically

Copy link
Copy Markdown
Member

@lwasser lwasser left a comment

Choose a reason for hiding this comment

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

@JoshuaKGoldberg can merge this after you rebase the pr - there is a merge conflict! Thank you so much for all of this work!! i'm excited that we are modernizing the code base as we go too!

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.

KCD Migration (tests): migrate tests step away from kcd to native configuration

3 participants