Conversation
…ndefined (older browser), or <= 1 (actual low-res screen)
…anslation we apply on lower DPI screens
test/plot.js
Outdated
| @@ -56,7 +63,7 @@ for (const [name, plot] of Object.entries(plots)) { | |||
| await fs.writeFile(diffile, actual, "utf8"); | |||
| } | |||
|
|
|||
| assert.ok(equal, `${name} must match snapshot`); | |||
| expect(equal, `${name} must match snapshot`).toBe(true); | |||
There was a problem hiding this comment.
Don’t we want to use Vitest’s file snapshots here? In my mind that was one of the primary goals of adopting Vitest. See (internal) example: https://github.com/observablehq/charts/blob/main/test/charts/test.ts
There was a problem hiding this comment.
The issue here is that snapshots have embedded images and that the file snapshots need to discard them (with something like <replaced>) because of inconsistencies between platforms. We can adopt a system where the images are compared separately, but it's not so great when you review changes visually.
There was a problem hiding this comment.
I think we can do it with a custom snapshot serializer.
There was a problem hiding this comment.
New strategy: extract the images to the side as PNGs, apply the image comparison algo to them, and link them by name instead of the <replaced> string.
There was a problem hiding this comment.
As I understand it a custom serializer would create the output as a .snap file containing the SVG/HTML structure and the images. But the comparison would still want an exact equality, which can't be guaranteed across platforms. We need the comparison to say "ok" even when files are slightly different, but I think I found a way to do this by doing the substitution early if the image discrepancy is low.
This:
AI disclosure: I used @claude to generate this PR. Reviewed every line very carefully though.