Skip to content

chore(client): migrate test setup to Vitest 4 - #550

Merged
serendipty01 merged 3 commits into
roostorg:mainfrom
serendipty01:fix-client-vitest
Jul 7, 2026
Merged

chore(client): migrate test setup to Vitest 4#550
serendipty01 merged 3 commits into
roostorg:mainfrom
serendipty01:fix-client-vitest

Conversation

@serendipty01

@serendipty01 serendipty01 commented May 21, 2026

Copy link
Copy Markdown
Contributor

Context & Requests for Reviewers

Follow-up to the client's Vitest 4 migration (vitest ^4.1.0 is already on main). Three Jest-era leftovers remained, one of which breaks a pre-push gate:

  • npm run test:prepush is broken on main — it passes Jest's --watchAll=false flag, which Vitest rejects (CACError: Unknown option --watchAll), so check:prepush can't run at all. Fixed to vitest run.
  • eslint/__tests__/customRules.test.js (the test for our in-repo custom ESLint rule) was still CommonJS and used the legacy Linter config shape with no TypeScript parser — meaning the rule's as-cast scenarios were never actually parsed as TS. Rewritten to ESM + ESLint 9 flat-config API (new Linter({ configType: 'flat' })) with @typescript-eslint/parser.
  • Test files were not type-checked anywhere, and vitest/globals types leaked into the app's tsconfig. Added a dedicated tsconfig.test.json (extends the app config, adds vitest/globals + node); the app tsconfig.json now excludes test files, so production code can no longer silently reference test globals. npm run lint gains a tsc --noEmit -p tsconfig.test.json gate, and the new config is wired into vite.config.ts, .eslintrc.cjs, and .dockerignore.

Note for reviewers: the full client suite has 6 failures that also fail on pristine main (Sidebar ×3, Calendar ×2, MergedReportsComponent ×1) — pre-existing and out of scope for this PR.

Tests

cd client && npm install
npm run lint          # includes the new tsc -p tsconfig.test.json gate — 0 errors
npm run test:prepush  # now actually runs; only the 6 pre-existing main failures

For contrast: on main, npm run test:prepush exits immediately with CACError: Unknown option --watchAll.

🤖 AI Usage Disclosure

Generated with Claude Code

Summary by CodeRabbit

  • Tests

    • Improved test runner setup with one-time execution and TypeScript type checking for tests.
    • Updated ESLint test coverage to work with the latest configuration style.
  • Bug Fixes

    • Reduced false positives in linting and type checking by separating app and test TypeScript settings.
    • Prevented test files from being included in regular app builds.

Copilot AI review requested due to automatic review settings May 21, 2026 19:31
@coderabbitai

coderabbitai Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a dedicated TypeScript test configuration wired into Vite's test typecheck and ESLint's parser project list, excludes test files from the main tsconfig, updates npm scripts and devDependencies, and migrates the ESLint custom rule test harness to an ESM flat-config Linter setup.

Changes

Test TypeScript Config and ESLint Harness Update

Layer / File(s) Summary
Dedicated test tsconfig and typecheck wiring
client/tsconfig.test.json, client/tsconfig.json, client/vite.config.ts, client/.eslintrc.cjs, client/.dockerignore
New test-scoped tsconfig with test type definitions; main tsconfig excludes test/spec files; Vite test config adds a typecheck block pointing to the new tsconfig; ESLint parserOptions.project includes it; .dockerignore excludes the new file from build context.
npm scripts and devDependencies
client/package.json
test:prepush switches to vitest run --passWithNoTests; lint adds a tsc --noEmit -p tsconfig.test.json step before ESLint; jsdom added as a devDependency.
ESLint rule test converted to ESM flat-config Linter
client/eslint/__tests__/customRules.test.js
ESLint rule test rewritten from CommonJS/non-flat Linter to ESM imports and a flat-config Linter instance, registering the rule via plugins.local.rules and configuring the TypeScript parser under languageOptions.parser.

Estimated code review effort: 2 (Simple) | ~12 minutes

Suggested reviewers: cassidyjames, julietshen, vinaysrao1, juanmrad

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is concise and accurately summarizes the main change: migrating the client test setup to Vitest 4.
Description check ✅ Passed The description covers context and testing well, with only the checklist section from the template missing.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR migrates client-side tests and tooling toward Vitest, updating configuration, scripts, and test implementations accordingly.

Changes:

  • Add Vitest globals typing and update test runner scripts for CI/pre-push behavior.
  • Migrate Jest-style mocks to Vitest mocks in a RuleFormUtils test.
  • Update ESLint custom rule test harness to use an in-config plugin rule definition and TypeScript parser.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
client/tsconfig.json Adds Vitest global typings to TypeScript configuration.
client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts Replaces Jest mocking with Vitest mocking utilities.
client/src/graphql/inputHelpers.test.ts Updates inline snapshots formatting (likely aligning with Vitest output).
client/package.json Updates pre-push test command and adds jsdom dependency.
client/eslint/tests/customRules.test.js Refactors ESLint rule test harness to use flat-config style plugin definition and TS parser.
Files not reviewed (1)
  • client/package-lock.json: Language not supported

Comment thread client/tsconfig.json Outdated
Comment thread client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts Outdated
Comment thread client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts Outdated
Comment thread client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts Outdated
Comment thread client/eslint/__tests__/customRules.test.js Outdated

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts (1)

99-113: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Test intent mismatch in non-boolean case.

Line 99 says this case “should show comparator/threshold”, but Line 111 asserts false. Please align the test name or the expected value so the behavior is unambiguous.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts` around
lines 99 - 113, The test name and assertion disagree: the "Condition with input
and selected signal with non-boolean output should show comparator/threshold"
case currently asserts false; update either the test description or the
assertion to match intended behavior. Locate the test in RuleFormUtils.test.ts
that mocks getConditionInputScalarType and calls
shouldConditionPromptForComparatorAndThreshold; if non-boolean output should
prompt for comparator/threshold, change the expect(...).toEqual(false) to
expect(...).toEqual(true); otherwise rename the it(...) description to reflect
that the function should return false for this setup.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts`:
- Around line 99-113: The test name and assertion disagree: the "Condition with
input and selected signal with non-boolean output should show
comparator/threshold" case currently asserts false; update either the test
description or the assertion to match intended behavior. Locate the test in
RuleFormUtils.test.ts that mocks getConditionInputScalarType and calls
shouldConditionPromptForComparatorAndThreshold; if non-boolean output should
prompt for comparator/threshold, change the expect(...).toEqual(false) to
expect(...).toEqual(true); otherwise rename the it(...) description to reflect
that the function should return false for this setup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 605e56d2-0e64-4112-a420-d65a77bbf868

📥 Commits

Reviewing files that changed from the base of the PR and between d8edc58 and 10ac746.

📒 Files selected for processing (4)
  • client/eslint/__tests__/customRules.test.js
  • client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts
  • client/tsconfig.test.json
  • client/vite.config.ts
✅ Files skipped from review due to trivial changes (1)
  • client/tsconfig.test.json

@cassidyjames cassidyjames added javascript Updates or related to JavaScript code dependencies Deals with dependencies, including PRs that update a dependency file labels May 21, 2026

@coderabbitai coderabbitai Bot 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts (1)

99-113: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix the non-boolean test intent/assertion mismatch.

Line 99 says this case should show comparator/threshold, but Lines 111-113 assert false. This makes the test ambiguous and can mask regressions. Please align either the title or the expectation.

Suggested fix (if the title is the intended behavior)
-      expect(shouldConditionPromptForComparatorAndThreshold(condition)).toEqual(
-        false,
-      );
+      expect(shouldConditionPromptForComparatorAndThreshold(condition)).toEqual(
+        true,
+      );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts` around
lines 99 - 113, The test title says the condition "should show
comparator/threshold" but the assertion expects false; update the assertion in
RuleFormUtils.test.ts so that
shouldConditionPromptForComparatorAndThreshold(condition) returns true (or
alternatively change the test title to reflect that it should not show
comparator), referencing the test case that constructs a RuleFormLeafCondition
with sampleSignal and the mocked getConditionInputScalarType returning
GQLScalarType.Number; ensure the expectation matches the intended behavior of
shouldConditionPromptForComparatorAndThreshold.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts`:
- Around line 99-113: The test title says the condition "should show
comparator/threshold" but the assertion expects false; update the assertion in
RuleFormUtils.test.ts so that
shouldConditionPromptForComparatorAndThreshold(condition) returns true (or
alternatively change the test title to reflect that it should not show
comparator), referencing the test case that constructs a RuleFormLeafCondition
with sampleSignal and the mocked getConditionInputScalarType returning
GQLScalarType.Number; ensure the expectation matches the intended behavior of
shouldConditionPromptForComparatorAndThreshold.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 177ba57e-fd21-4f76-a557-024809bb87f6

📥 Commits

Reviewing files that changed from the base of the PR and between 10ac746 and d7a6c7f.

⛔ Files ignored due to path filters (1)
  • client/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (8)
  • client/.eslintrc.cjs
  • client/eslint/__tests__/customRules.test.js
  • client/package.json
  • client/src/graphql/inputHelpers.test.ts
  • client/src/webpages/dashboard/rules/rule_form/RuleFormUtils.test.ts
  • client/tsconfig.json
  • client/tsconfig.test.json
  • client/vite.config.ts
✅ Files skipped from review due to trivial changes (2)
  • client/src/graphql/inputHelpers.test.ts
  • client/tsconfig.test.json

@serendipty01
serendipty01 force-pushed the fix-client-vitest branch 2 times, most recently from fbadd52 to 2edd83f Compare May 22, 2026 08:39
- Replace --watchAll=false (Jest-only flag) with vitest run in test:prepush
- Add jsdom to devDependencies (no longer bundled in Vitest 2+)
- Add vitest/globals to tsconfig types for vi global type support
- Rewrite eslint/customRules test to use ESLint 9 flat config Linter API
  with @typescript-eslint/parser (defineRule removed in ESLint 9)
- Migrate RuleFormUtils.test.ts from jest.mock/jest.requireActual to
  vi.mock/vi.importActual (jest.mock not hoisted by Vite transform)
- Update inputHelpers.test.ts inline snapshots to Vitest serializer format
resolve: fix-client-vitest .dockerignore conflict
@serendipty01 serendipty01 changed the title fix(client): migrate test setup to Vitest 4 chore(client): migrate test setup to Vitest 4 Jul 7, 2026
@serendipty01
serendipty01 requested a review from Copilot July 7, 2026 13:31

Copilot AI 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.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.

@taobojlen

Copy link
Copy Markdown
Contributor

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@julietshen julietshen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

tested locally and everything works, thanks!

@taobojlen taobojlen 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.

LGTM, thank you for this!

i'll open a PR stacked on top of this that also fixes the failing tests and runs them in CI.

Comment thread client/package.json
"build": "vite build",
"test": "vitest --passWithNoTests",
"test:prepush": "vitest --watchAll=false --passWithNoTests",
"test:prepush": "vitest run --passWithNoTests",

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.

nit: we could run this with --typecheck instead of needing the separate typechecking step. i'm not sure which is preferable!

@serendipty01
serendipty01 merged commit c5b0b48 into roostorg:main Jul 7, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Deals with dependencies, including PRs that update a dependency file javascript Updates or related to JavaScript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants