Skip to content

test: use chartjs-test-utils instead of the copied test helpers - #329

Merged
kurkle merged 1 commit into
mainfrom
test/chartjs-test-utils
Nov 19, 2026
Merged

kurkle merged 1 commit into
mainfrom
test/chartjs-test-utils

Conversation

@kurkle

@kurkle kurkle commented Nov 19, 2026

Copy link
Copy Markdown
Owner

What changed

test/utils/{canvas,chart,fixtures,index,matchers,sprite}.js were 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#482

  • test/setup.js: calls setup({ Chart }) (matchers, per-spec chart release, devicePixelRatio = 1). Kept local: the plugin registration and the luxon adapter, the globalThis.* shim the fixture configs use bare (Chart, acquireChart, afterEvent, triggerMouseEvent), and Chart.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 the import.meta.glob maps, which have to be written in the spec file because globs resolve relative to it. All 42 fixtures sit at the root of test/fixtures/, so specsFromFixtures() still takes no argument.
  • vitest.browser.config.ts: createSaveFixtureImage() from chartjs-test-utils/node replaces the local saveFixtureImage command. npm run fixtures:update and scripts/update-fixtures.mjs are unchanged.
  • test/integration/min-bundle/min.spec.js (the minified-bundle check) imports readImageData, spritingOn, spritingOff and toEqualImageData from the package and registers only toEqualImageData with expect.extend. It deliberately does not call setup(), so this suite still runs without a registered afterEach, wrapper CSS or device pixel ratio override, exactly as before. Its local buildChart / releaseChart stay, because they build against the UMD-shimmed Chart.
  • package.json: adds chartjs-test-utils@^1.1.0, removes the direct pixelmatch devDependency (nothing else imports it). The lockfile has exactly one pixelmatch, 8.0.0, now pulled in by the package.
  • biome.json: drops the test/utils include.

Nothing in test/utils was repo-specific, so the directory is gone entirely. No spec used persistent charts, so the package's releaseCharts behaviour matches. The published package is unchanged: npm pack --dry-run lists 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, fresh npm 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 in rRadialLinear0Negative under Firefox).

Environment Counts compared Different
macOS Chromium (42 fixtures + 3 min-bundle) 45 0
macOS Firefox 42 0
Linux Chromium (42 fixtures + 3 min-bundle) 45 0
Linux Firefox 42 0

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 build and npm test pass. Fixture suite: 96 tests (2 browsers x 48), min-bundle: 5 tests, package check: 19 checks; the same numbers as before the change.
  • Update mode: on a scratch copy, deleting test/fixtures/yCartesianLinear.png and running npm run fixtures:update recreated 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).

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.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying chartjs-plugin-gradient with  Cloudflare Pages  Cloudflare Pages

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

View logs

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 12.7 kB

ℹ️ View Unchanged
Filename Size
dist/chartjs-plugin-gradient.cjs 3.63 kB
dist/chartjs-plugin-gradient.esm.js 3.47 kB
dist/chartjs-plugin-gradient.js 3.63 kB
dist/chartjs-plugin-gradient.min.js 2.02 kB

compressed-size-action

@kurkle
kurkle merged commit 2c9ca49 into main Nov 19, 2026
6 checks passed
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.

1 participant