Skip to content

Added vitest for frontend unit tests#387

Merged
tuj merged 4 commits into
release/3.0.0from
feature/js-unittests
Apr 23, 2026
Merged

Added vitest for frontend unit tests#387
tuj merged 4 commits into
release/3.0.0from
feature/js-unittests

Conversation

@tuj

@tuj tuj commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Link to issue

#380

Link to ticket

https://leantime.itkdev.dk/#/tickets/showTicket/7203

Description

Added vitest for frontend unit tests.
Rewrite playwright unit tests as vitest unit tests.

Checklist

  • My code is covered by test cases.
  • My code passes our test (all our tests).
  • My code passes our static analysis suite.
  • My code passes our continuous integration process.

@tuj tuj added this to the 3.0.0 milestone Apr 17, 2026
@tuj tuj self-assigned this Apr 17, 2026
@tuj tuj added the enhancement New feature or request label Apr 17, 2026
@tuj
tuj requested a review from turegjorup April 17, 2026 12:55
@tuj tuj added the version 3 Issues related to the release of version 3 label Apr 22, 2026
@turegjorup

Copy link
Copy Markdown
Contributor

Code Review

Overview

Introduces Vitest for fast JS unit testing alongside the existing Playwright suite. Renames 5 existing pure-function tests from .spec.js to .test.js, adds a new id-from-path.test.js, wires up a CI workflow, Taskfile target, and separate Playwright/Vitest test matchers so the two runners don't overlap. Verified locally: all 39 tests pass in ~2s.

What's good

  • Clean separation via testMatch in playwright.config.ts and include in vitest.config.js — no risk of double-running.
  • Good regression coverage, particularly campaigns-button-promise-chain.test.js (promise chain setLoading(false) regression) and id-from-path.test.js (null/undefined/number edge cases).
  • CI workflow (vitest.yaml) follows the existing Docker-based pattern.
  • README + CHANGELOG + Taskfile all updated — low friction for contributors.

Issues & suggestions

1. Unused dependency: @testing-library/react (package.json)
Added to devDependencies but not imported anywhere. setup.js only uses @testing-library/jest-dom/vitest. Either drop it (and probably jsdom) until a component test lands, or add at least one component test to justify the dep weight.

2. jsdom env costs ~8s of setup for tests that don't need it (vitest.config.js)
The test output shows environment 8.06s — all current tests are pure function tests on plain JS modules and would run in node env. Consider defaulting to environment: "node" and opt-in to jsdom per-file via // @vitest-environment jsdom once component tests arrive.

3. Inconsistent test API style
Five files use test.describe / test (Playwright-style, preserved from the rename — works in vitest as a compat alias but not officially documented); the new id-from-path.test.js uses idiomatic describe / it. Pick one and stick to it — I'd recommend describe/it for forward-compat safety.

4. Timing-based flakiness in promise chain tests (campaigns-button-promise-chain.test.js)
await new Promise((resolve) => setTimeout(resolve, 50)) to wait for microtasks is brittle on slow CI. Better: have onClick return its promise chain so the test can await it directly, or use await new Promise(setImmediate) / vi.waitFor.

5. README guidance on when to use Vitest vs Playwright (README.md)
"…located in assets/tests/ alongside the Playwright tests." A one-liner on when to use which (pure utilities → Vitest, UI/flow → Playwright) would help future contributors choose correctly.

Risks

  • Low. Changes are additive; existing Playwright tests are untouched beyond the matcher filter.
  • The new devDep footprint is sizable (jsdom pulls ~20+ transitive deps) — worth trimming if not used.

Verdict

Solid foundation, ready to merge after (optionally) trimming the unused @testing-library/react dep and unifying the describe/test style. Items 2, 4, 5 are follow-ups, not blockers.

@turegjorup turegjorup left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Claude Code flagged a few things, but no blockers.

@tuj
tuj merged commit 3bc4899 into release/3.0.0 Apr 23, 2026
17 checks passed
@turegjorup
turegjorup deleted the feature/js-unittests branch April 24, 2026 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request version 3 Issues related to the release of version 3

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants