Skip to content

adopt vitest; pnpm; regenerate snapshots#2373

Open
Fil wants to merge 19 commits intomainfrom
fil/vitest
Open

adopt vitest; pnpm; regenerate snapshots#2373
Fil wants to merge 19 commits intomainfrom
fil/vitest

Conversation

@Fil
Copy link
Copy Markdown
Contributor

@Fil Fil commented Mar 4, 2026

Replace mocha by vitest as the preferred test framework

AI disclosure: I used @claude to generate a first draft this PR.

@Fil Fil requested a review from mbostock March 4, 2026 20:30
@Fil Fil force-pushed the fil/vitest branch 2 times, most recently from 5ea6a23 to 635d2aa Compare March 5, 2026 11:47
Copy link
Copy Markdown
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

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

I bet we could make these change without having to regenerate all the snapshots… we could do some preprocessing to address the precision issue. That would make it easier to review and ensure that this isn’t introducing any unexpected changes.

@Fil Fil changed the base branch from main to fil/fix-axis-offset March 6, 2026 12:20
@Fil

This comment was marked as outdated.

@Fil Fil marked this pull request as draft March 6, 2026 13:08
@Fil Fil force-pushed the fil/vitest branch 2 times, most recently from 64ea8b9 to c2e0667 Compare March 6, 2026 13:29
@Fil
Copy link
Copy Markdown
Contributor Author

Fil commented Mar 6, 2026

Edit: OBSOLETE

I bet we could make these change without having to regenerate all the snapshots

Our snapshots in main, using mocha, are in fact wrong because the offset is computed inconsistently in the test section. (When we import d3-axis, the "fake" global.window object is not set up yet, so D3 axes have an offset of 0, whereas other elements in Plot use an offset of 0.5 because JSDOM's default DPI is 1.)

I created a fix-axis-offset branch off of main that only fixes the offset, and then rebased this branch on top of fix-axis-offset.

This should make it easier to review. All the changes to snapshots are in #2375.

@Fil Fil changed the title adopt vitest; fix hex bug adopt vitest Mar 7, 2026
@Fil Fil force-pushed the fil/fix-axis-offset branch from e4658e0 to 8229321 Compare March 7, 2026 16:20
@Fil Fil marked this pull request as ready for review March 7, 2026 16:34
@Fil Fil changed the base branch from fil/fix-axis-offset to main March 11, 2026 14:44
@Fil
Copy link
Copy Markdown
Contributor Author

Fil commented Mar 11, 2026

It is expected that b65a298 fails; but once #2380 is merged the tests should (will) pass — at least they do in my local setup.

@mbostock
Copy link
Copy Markdown
Member

Can’t we get the tests to pass as-is? That would give me more confidence that we’re testing correctly. I’m going to look at that now; I don’t understand yet why the tests are failing in this branch.

@mbostock
Copy link
Copy Markdown
Member

mbostock commented Mar 30, 2026

Ooooohkay, I’m just slow. The tests aren’t passing here because

  1. our snapshots have too much precision (e.g., translate(40,216.00000000000003));
  2. we “normalize” the actual result to limit precision; and
  3. toMatchFileSnapshot requires an exact match.

We don’t have this problem with main and Mocha because we normalize both the actual result and the expected result (i.e., the snapshot) before doing the exact comparison. (We also strip images in main, but that’s handled in this branch by the new withImages approach… with does some testing internally.)

So I guess we should just avoid toMatchFileSnapshot for now in this PR and do some “manual” snapshot testing. Then after we regenerate the snapshots, we can switch to toMatchFileSnapshot.

@mbostock
Copy link
Copy Markdown
Member

This passes now but I still want to do two things: first, I want to think about the design of withImages and see if I can make it independent of the expected images; second, I want to regenerate the snapshots (folding in #2380) so that we can adopt toMatchFileSnapshot.

Copy link
Copy Markdown
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

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

This works pretty well, but there are a few outstanding issues.

First, a minor annoyance is that all the snapshot tests are now lumped under test/plot.js, so you can’t see the individual tests run.

Second, editing any snapshot test causes all snapshot tests to rerun; this is related to the first problem. (I think this also causes u to update all snapshots rather than just the test that failed, but I’m not sure, as all the snapshots need to be regenerated anyway and we haven’t yet adopted toMatchFileSnapshot.)

I think we can declare the tests in source to fix…

Copy link
Copy Markdown
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

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

Almost there… the import.meta.vitest boilerplate is annoying, but I don’t think there’s a better fix. I should fix or remove this, though: Warning: No files were found with the provided path: test/output/*-changed.*. No artifacts will be uploaded. We don’t generate these now, so it’s hard to see how a test failed, and there’s no artifact generated in CI when tests fail.

@mbostock mbostock changed the title adopt vitest adopt vitest; pnpm; regenerate snapshots Mar 31, 2026
@mbostock
Copy link
Copy Markdown
Member

Things work, but I still haven’t removed the -changed logic, or figured out how to do the same thing with Vitest. I think we want it, because if the tests fail in CI (but not locally), how will we be able to see what the output was and debug?

Also to note that the tests seem to take 4+ minutes with VItest, while they only took 50 seconds with Mocha. 😩 Not sure what could be causing such a slowdown but likely worth investigating…

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.

2 participants