Repository navigation
test: use chartjs-test-utils instead of the copied test helpers - #329
Merged
Merged
Conversation
test/utils was a copy of chartjs-test-utils, which now ships the same helpers
for Vitest browser mode. Depend on the package and delete the copy.
- test/setup.js calls setup({ Chart }) for the matchers, the per-spec chart
release and the device pixel ratio. The globalThis shim the fixture configs
rely on and the colors plugin default stay local.
- The fixture specs use createFixtures, with the globs kept in the spec file.
- The browser config uses createSaveFixtureImage for update mode.
- The min-bundle integration spec imports the helpers it needs from the
package and registers only the toEqualImageData matcher.
- Drop the direct pixelmatch devDependency, which the package now provides.
No reference image or tolerance changes: the differing-pixel count of every
fixture is identical before and after in Chromium and Firefox, on macOS and
Linux.
Deploying chartjs-plugin-gradient with
|
| Latest commit: |
ae28fbf
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://eb2983bb.chartjs-plugin-gradient.pages.dev |
| Branch Preview URL: | https://test-chartjs-test-utils.chartjs-plugin-gradient.pages.dev |
|
|
Size Change: 0 B Total Size: 12.7 kB ℹ️ View Unchanged
|
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 changed
test/utils/{canvas,chart,fixtures,index,matchers,sprite}.jswere a copy of chartjs-test-utils, which now ships the same code for Vitest browser mode (v1.1.0). This PR depends on the package and deletes the copy. The same change was made in chartjs-chart-sankey: kurkle/chartjs-chart-sankey#482test/setup.js: callssetup({ Chart })(matchers, per-spec chart release,devicePixelRatio = 1). Kept local: the plugin registration and the luxon adapter, theglobalThis.*shim the fixture configs use bare (Chart,acquireChart,afterEvent,triggerMouseEvent), andChart.defaults.plugins.colors.enabled = false. The package does not set globals, and the colors default is specific to this repo.test/specs/gradient.spec.js:createFixtures({ configs, images, prefix })with theimport.meta.globmaps, which have to be written in the spec file because globs resolve relative to it. All 42 fixtures sit at the root oftest/fixtures/, sospecsFromFixtures()still takes no argument.vitest.browser.config.ts:createSaveFixtureImage()fromchartjs-test-utils/nodereplaces the localsaveFixtureImagecommand.npm run fixtures:updateandscripts/update-fixtures.mjsare unchanged.test/integration/min-bundle/min.spec.js(the minified-bundle check) importsreadImageData,spritingOn,spritingOffandtoEqualImageDatafrom the package and registers onlytoEqualImageDatawithexpect.extend. It deliberately does not callsetup(), so this suite still runs without a registeredafterEach, wrapper CSS or device pixel ratio override, exactly as before. Its localbuildChart/releaseChartstay, because they build against the UMD-shimmedChart.package.json: addschartjs-test-utils@^1.1.0, removes the directpixelmatchdevDependency (nothing else imports it). The lockfile has exactly onepixelmatch, 8.0.0, now pulled in by the package.biome.json: drops thetest/utilsinclude.Nothing in
test/utilswas repo-specific, so the directory is gone entirely. No spec usedpersistentcharts, so the package'sreleaseChartsbehaviour matches. The published package is unchanged:npm pack --dry-runlists the same 12 files before and after.No pixel changed
No reference PNG and no tolerance is touched. To check that the rendering did not move, the differing-pixel count (pixelmatch, as reported by the matcher) of every fixture was recorded before and after the change, in Chromium and Firefox, on macOS (arm64) and on Linux (
mcr.microsoft.com/playwright:v1.65.1-noble, arm64, freshnpm ci), using temporary instrumentation that is not part of this PR. The three min-bundle comparisons (Chromium) were recorded too. 42 fixtures x 2 browsers + 3 min-bundle = 87 counts per environment (27 non-zero, maximum 42 px inrRadialLinear0Negativeunder Firefox).The package injects wrapper CSS by default, which the local setup did not; every count is identical anyway, so the default is kept.
Verification
npm run lint,npm run typecheck,npm run buildandnpm testpass. Fixture suite: 96 tests (2 browsers x 48), min-bundle: 5 tests, package check: 19 checks; the same numbers as before the change.test/fixtures/yCartesianLinear.pngand runningnpm run fixtures:updaterecreated only that file (every other PNG was left untouched), byte-identical to what the previous local helper regenerates, and the suite passes against it (96/96).