Skip to content

test: run the decimation, filler, legend, title and tooltip plugin specs under Vitest - #12509

Merged
kurkle merged 1 commit into
masterfrom
migrate-tests-to-vitest-p10-convert-plugins
Nov 26, 2026
Merged

kurkle merged 1 commit into
masterfrom
migrate-tests-to-vitest-p10-convert-plugins

Conversation

@kurkle

@kurkle kurkle commented Nov 26, 2026

Copy link
Copy Markdown
Member

Piece P10 of openspec/changes/migrate-tests-to-vitest. It follows #12436 (Vitest beside Karma) and #12444 (fixtures under Vitest), and uses the same recipe as #12496, #12498, #12499, #12505 and #12506. Base: f92cce7.

What was missing

plugin.decimation, plugin.filler, plugin.legend, plugin.title and plugin.tooltip still ran under Karma/Jasmine. Open pull requests touch these files. By design D13 they do not hold the conversion; they are listed below.

What changed

Each file is renamed with git mv from *.tests.js to *.spec.js, so git follows every rename: decimation 100%, filler, legend and title 97%, tooltip 92%. The idioms are converted with the table in design D5:

Jasmine Vitest Uses
describe('auto', jasmine.fixture.specs(...)) deleted; fixtures.spec.js already runs these directories 4 (filler, legend, title, tooltip)
spyOn(o, 'm') vi.spyOn(o, 'm').mockImplementation(() => {}) 3 (console.warn twice in filler, tooltip.update once)
spyOn(o, 'm').and.callThrough() vi.spyOn(o, 'm') 2 (tooltip.update, positioners.test)
.calls.count() / .calls.first().args / .calls.reset() .mock.calls.length / .mock.calls[0] / .mockClear() 1 / 3 / 2
.calls.first().object .mock.contexts[0] 1
jasmine.objectContaining / jasmine.any expect.objectContaining / expect.any 18 / 4
jasmine.triggerMouseEvent( triggerMouseEvent( 45

plugin.decimation uses no Jasmine idiom; only the rename moves it.

Two idioms beyond the D5 table, both in plugin.title. They are added to the D5 table in design.md:

  • jasmine.createSpy('padding').and.returnValue(value) becomes vi.fn(() => value).
  • padding.calls.mostRecent().args[0] becomes padding.mock.lastCall[0].

The recorded this. The positioner test asserts fn.mock.contexts[0] instanceof Tooltip. src/plugins/plugin.tooltip.js calls the positioner with .call(this, ...) from the Tooltip instance (lines 651, 1012 and 1219). So the recorded this is never undefined or null, and the strict-mode difference in D5 does not apply.

No deliberate-break check. None of the five files has a function(done) test, a beforeEach/afterEach hook or this. state. No expectation runs inside a callback: the legend onClick/onHover/onLeave callbacks only assign local variables, and the tests assert after await triggerMouseEvent(...). Every expectation runs in a test body, so there is no expectation whose failure could be lost.

Stale comments are deleted:

  • // Test the rectangle element at the top of plugin.legend, plugin.title and plugin.tooltip.
  • A commented-out // jasmine.createSpy('warn'); in plugin.filler.

toEqual stays toEqual. No imports are added and test/setup.js is unchanged.

openspec/changes/migrate-tests-to-vitest/tasks.md: 10.2, 10.3 and 10.4 are ticked. 10.1 stays open until the rebase comments are posted after merge.

Open pull requests that touch these files

Each of these gets a comment with the rebase recipe (the table in D5) after this merges. The list was checked with gh pr list against the five spec paths.

Spec file Pull requests
plugin.decimation #12284, #12341
plugin.filler #12326, #12381
plugin.legend #11825, #12205, #12242, #12316, #12346
plugin.tooltip #11849, #12275

No open pull request touches plugin.title.

Counts

Local runs on macOS on f92cce7, full suite of each runner, per browser:

Chrome / Chromium Firefox
Karma before 931 (915 tests + 16 fixture placeholders) 931 (915 + 16)
Karma after 824 (812 tests + 12 fixture placeholders) 824 (812 + 12)
Vitest before 935 935
Vitest after 1038 1038
  • Without placeholders, Karma falls by 103 tests per browser and Vitest rises by 103.
  • The 4 fixture placeholders went with the deleted jasmine.fixture.specs lines.
  • Running Karma with --grep on each file before the change gave, per browser:
File Karma --grep run Tests Placeholder
plugin.decimation 10 10 0
plugin.filler 13 12 1
plugin.legend 36 35 1
plugin.title 13 12 1
plugin.tooltip 35 34 1
  • The tests were counted with a regex that also matches it (. That regex finds 97 literal it calls; loops generate the other 6:
    • legend: +3 from the position × font-size loop and +1 from a left/right forEach.
    • title: +1 from the padding forEach.
    • tooltip: +1 from the line/bar forEach.
  • All 206 runs of the converted specs pass (103 tests in each of the two browsers).
  • Before the rename, Vitest runs none of these specs: vitest run --browser.headless test/specs/plugin.decimation test/specs/plugin.filler test/specs/plugin.legend test/specs/plugin.title test/specs/plugin.tooltip exits 1 with "No test files found, exiting with code 1".
  • Karma passes 824 of 824 in each browser.
  • Vitest shows the same 15 local image failures before and after: 8 fixtures in Chromium and 7 in Firefox. They are under plugin.filler/line, scale.time, scale.timeseries and scale.radialLinear/ticks-below-zero (that last one in Chromium only). These are known macOS rendering differences; CI on Ubuntu is the judge.

How to try it

pnpm exec vitest run --browser.headless test/specs/plugin.decimation.spec.js test/specs/plugin.filler.spec.js test/specs/plugin.legend.spec.js test/specs/plugin.title.spec.js test/specs/plugin.tooltip.spec.js
pnpm exec karma start ./karma.conf.cjs --single-run --browsers chrome,firefox

…ecs under Vitest

Rename plugin.{decimation,filler,legend,title,tooltip}.tests.js to
*.spec.js and convert their Jasmine idioms with the table in design D5.
The four fixture lines go; fixtures.spec.js already runs those
directories. The D5 table gains the two spy idioms title uses:
.and.returnValue(v) and .calls.mostRecent().args.
@netlify

netlify Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for chartjs-docs canceled.

Name Link
🔨 Latest commit b5beb4f
🔍 Latest deploy log https://app.netlify.com/projects/chartjs-docs/deploys/6b07b75703dda7c18ec0379b

@github-actions

Copy link
Copy Markdown

Size Change: 0 B

Total Size: 364 kB

ℹ️ View Unchanged
Filename Size
dist/chart.cjs 82 kB
dist/chart.js 82.3 kB
dist/chart.umd.js 72.5 kB
dist/chart.umd.min.js 72.5 kB
dist/chunks/helpers.dataset.cjs 25.8 kB
dist/chunks/helpers.dataset.js 25.6 kB
dist/helpers.cjs 1.52 kB
dist/helpers.js 1.33 kB

compressed-size-action

@kurkle
kurkle marked this pull request as ready for review November 26, 2026 04:40
@kurkle
kurkle merged commit 40729cb into master Nov 26, 2026
8 checks passed
@kurkle
kurkle deleted the migrate-tests-to-vitest-p10-convert-plugins branch November 26, 2026 14:00
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