Skip to content

Make the ResizeObserver test mock constructible under any vitest - #18

Merged
and3rn3t merged 1 commit into
mainfrom
fix/vitest5-resize-observer
Sep 19, 2026
Merged

and3rn3t merged 1 commit into
mainfrom
fix/vitest5-resize-observer

Conversation

@and3rn3t

Copy link
Copy Markdown
Owner

Why

Dependabot #15 bumps vitest from 3.2.6 to 5.0.1, two major versions, to close two moderate advisories (vitest and @vitest/mocker, path traversal / arbitrary file read). On that version 10 of the 144 tests fail:

TypeError: ... is not a constructor
  ❯ new Mock node_modules/vitest/dist/chunks/spy.*.js
  ❯ node_modules/recharts/lib/component/ResponsiveContainer.js:101

Recharts calls new ResizeObserver(...), and our mock was built with vi.fn().mockImplementation(...). Whether a vitest mock function can be used as a constructor is an implementation detail, and it changed in v5. Every Recharts-backed test (the Dashboard page and integration specs) fails.

A plain class does the same job without depending on that detail.

Verified

vitest result
3.2.6 (current pin) 144/144 pass
5.0.1 (what #15 proposes) 144/144 pass

Lint clean and vitest run --coverage passes on both. This change is version-independent, so it is safe to land ahead of the bump.

Also

web/coverage/ was in neither web/.gitignore nor the eslint ignorePatterns, so running vitest run --coverage wrote instrumented copies of the source that eslint then reported errors on, and left them untracked. Both now ignore it.

🤖 Generated with Claude Code

Recharts calls `new ResizeObserver(...)`, and the mock was built with
`vi.fn().mockImplementation(...)`. Whether a vitest mock function can be used
as a constructor is an implementation detail, and it changed in vitest 5:
every Recharts-backed test fails there with "... is not a constructor",
10 of the 144 in this suite.

A plain class does the same job without depending on that detail. Verified
both ways: 144/144 on the pinned vitest 3.2.6, and 144/144 on vitest 5.0.1,
which is what Dependabot #15 proposes. That PR cannot go green without this.

Also stop the generated coverage/ directory leaking into lint and git. It was
in neither web/.gitignore nor the eslint ignorePatterns, so running
`vitest run --coverage` produced instrumented copies of the source that
eslint then reported errors on, and left them untracked in the working tree.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 19, 2026 04:51
@github-actions

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved review issues remain.

Review effort: Lite
Findings: None

What changed in this PR

Updates the ResizeObserver test mock for Vitest compatibility and excludes generated coverage artifacts.

Changes:

  • Replaces the function mock with a constructible class.
  • Ignores coverage output in Git and ESLint.
File Description
web/​src/​test/​setup.js Provides a constructible ResizeObserver mock.
web/​.gitignore Ignores generated coverage output.
web/​.eslintrc.cjs Excludes coverage output from linting.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@and3rn3t and3rn3t self-assigned this Sep 19, 2026
@and3rn3t
and3rn3t merged commit 2931c72 into main Sep 19, 2026
18 checks passed
@and3rn3t
and3rn3t deleted the fix/vitest5-resize-observer branch September 19, 2026 04:53
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