Repository navigation
fix: compare charts drawn on an OffscreenCanvas - #45
Merged
Merged
Conversation
toEqualImageData accepted only a CanvasRenderingContext2D, an HTMLCanvasElement or a chart whose context was one, so a chart acquired with `useOffscreenCanvas: true` failed with "Input value is not a valid image source." before any pixel was compared. 0.x checked `instanceof Chart` and passed such charts on. toBeValidChart rejected them as well. Both matchers now also accept an OffscreenCanvas and its OffscreenCanvasRenderingContext2D, recognised by their tags so that a browser without OffscreenCanvas does not throw. Updating a reference image copies an OffscreenCanvas onto a plain canvas first, since it has no toDataURL.
kurkle
marked this pull request as ready for review
November 24, 2026 03:59
kurkle
requested review from
etimberg
and
a balanced review from Copilot
and removed request for
Copilot
November 24, 2026 13:15
etimberg
approved these changes
Nov 24, 2026
|
🎉 This PR is included in version 1.1.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
toEqualImageDataresolved its input only as aCanvasRenderingContext2D, anHTMLCanvasElement, or a chart whosectxwas aCanvasRenderingContext2D. A chart acquired withacquireChart(config, {useOffscreenCanvas: true})draws on anOffscreenCanvas, so its fixture failed with "Input value is not a valid image source." before any pixel was compared. Chart.js'scontroller.line/point-style-offscreen-canvasfixture hits this; under 0.x the matcher checkedinstanceof Chartand compared such charts.toBeValidChartrejected them too, since it required[object HTMLCanvasElement]and[object CanvasRenderingContext2D].What changed
src/matchers.js: both matchers also acceptOffscreenCanvasandOffscreenCanvasRenderingContext2D. They are recognised by theirObject.prototype.toStringtags, astoBeValidChartalready did, so a browser withoutOffscreenCanvasdoes not throw aReferenceError.src/fixtures.js: when reference images are updated, anOffscreenCanvas(which has notoDataURL) is copied onto a plain canvas withdrawImagefirst. The copy is exact: in both browsers itsgetImageDatais byte for byte the same as the offscreen context's.basic/bar-offscreenand two browser specs. The fixture has its own reference image: Chromium rasterizes anOffscreenCanvasslightly differently from an onscreen canvas (4887 of 262144 bytes differ for the same bar chart, along the bar edges), while Firefox renders both the same.Failing test before the fix
On 12417a7 with the new fixture and specs,
npm run test:browser:After the fix,
npm testpasses: 30 passed, 2 skipped (the existing spec that checks the skip of an unsupported feature, once per browser).basic/bar-offscreen.pngwas written bynpm run fixtures:updatethrough the new copy path.How to try it