Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 25, 2025

Vitest 4.x enforces stricter validation on mock implementations—arrow functions cannot be used as constructors with new. This broke tests when mocking classes like EntityParser and xml2js.Builder.

Changes

  • tests/catalyst.test.mts: Convert EntityParser, Mx, and MxGeometry mocks to class syntax
  • tests/mx/Mx.test.mts: Convert xml2js.Builder mock to class syntax

Before/After

// Before: Arrow function mock (fails with "is not a constructor")
vi.mock('../src/puml/EntityParser.mjs', () => ({
  EntityParser: vi.fn().mockImplementation(() => ({
    parse: vi.fn().mockReturnValue([])
  }))
}));

// After: Class mock
vi.mock('../src/puml/EntityParser.mjs', () => ({
  EntityParser: class MockEntityParser {
    parse = vi.fn().mockReturnValue([])
  }
}));
Original prompt

Please look at #464 and find out why the tests have started to fail


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Convert mock implementations from arrow function syntax to class syntax
to fix "is not a constructor" errors in Vitest 4.x which has stricter
validation for mock implementations.

Co-authored-by: localgod <1308965+localgod@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 25, 2025

Deploying catalyst with  Cloudflare Pages  Cloudflare Pages

Latest commit: 03d9441
Status: ✅  Deploy successful!
Preview URL: https://922a31df.catalyst-4wt.pages.dev
Branch Preview URL: https://copilot-debug-test-failures.catalyst-4wt.pages.dev

View logs

Copilot AI changed the title [WIP] Investigate reasons for failing tests Fix test mocks for Vitest 4.x compatibility Nov 25, 2025
Copilot AI requested a review from localgod November 25, 2025 08:42
@github-actions
Copy link

github-actions bot commented Nov 25, 2025

Coverage Report for Coverage Report

Status Category Percentage Covered / Total
🔴 Lines 83.79% (🎯 85%) 274 / 327
🔴 Statements 83.28% (🎯 85%) 289 / 347
🟢 Functions 94.8% (🎯 85%) 73 / 77
🔴 Branches 62.27% (🎯 85%) 104 / 167
File CoverageNo changed files found.
Generated in workflow #1520 for commit 03d9441 by the Vitest Coverage Report Action

@localgod localgod marked this pull request as ready for review November 25, 2025 10:12
@localgod localgod merged commit aea88cc into main Nov 25, 2025
10 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.

2 participants