Set up Vitest Testing Infrastructure and Core Utilities Tests (vertex app)#3692
Conversation
Add Vitest-based testing to the vertex package: introduces vitest.config.ts and vitest.setup.ts and updates package.json and tsconfig to support tests. Adds dev dependencies for vitest, @testing-library/react, @testing-library/jest-dom, @testing-library/user-event, jsdom and @vitejs/plugin-react to enable running React component tests in a jsdom environment.
Add comprehensive unit tests for core utility modules (clientCache, cohortName, getApiErrorMessage, rememberedAccounts, sessionManager, status, urlHelpers, userPreferences). Remove obsolete responsive.ts. Update Vitest config to set jsdom URL and enhance vitest.setup.ts to polyfill/localize localStorage and sessionStorage in the test environment to ensure consistent behavior across tests.
Add a comprehensive testing guide and expose test npm scripts. Updated src/vertex/README.md to list `npm run test`, `npm run test:watch`, and `npm run test:coverage` and added src/vertex/app/_docs/internal/TESTING.md which documents Vitest/React Testing Library usage, file organization, mocking guidance, coverage expectations, and a PR checklist to standardize how tests are written and run across the Vertex project.
Run TypeScript type checking and test coverage in the safe-checks CI job by adding a `tsc --noEmit` step and a `npm run test:coverage` step under src/vertex. Configure Vitest coverage to use the V8 provider and emit text, JSON, and HTML reports; coverage thresholds are present but intentionally commented out for now.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds Vitest/RTL testing infrastructure for ChangesVertex Testing Infrastructure and Utility Tests
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsErrors were encountered while retrieving linked issues. Errors (1)
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. Comment |
|
New azure vertex changes available for preview here |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/vertex/core/utils/clientCache.test.ts (1)
6-9: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAvoid pinning the cache version string in the test.
CLIENT_CACHE_VERSIONis a release knob, so every intentional version bump will break this suite even ifrunClientCacheMaintenance()still behaves correctly. Prefer deriving the current version from the module behavior or importing the constant if you want an exact-value assertion here.🤖 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 `@src/vertex/core/utils/clientCache.test.ts` around lines 6 - 9, The test is hard-coding the client cache version string, which makes it brittle whenever the cache version is intentionally bumped. Update the assertions in clientCache.test.ts to use the source of truth for the version, either by importing CLIENT_CACHE_VERSION or by deriving the expected value from the module behavior around runClientCacheMaintenance(). Keep the rest of the key checks (VERSION_KEY, QUERY_CACHE_PREFIX, MISMATCH_LOG_KEY) intact and avoid pinning an exact release-specific literal in the test.
🤖 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.
Inline comments:
In @.github/workflows/safe-checks.yml:
- Around line 101-104: Update the safe-checks workflow job to use Node 20.19+
instead of Node 18 so the new Type Check and Test & Coverage steps run on a
supported runtime. Locate the job that uses actions/setup-node in the workflow
and bump the configured Node version to 20.19.0 or newer, keeping the rest of
the job steps unchanged.
---
Nitpick comments:
In `@src/vertex/core/utils/clientCache.test.ts`:
- Around line 6-9: The test is hard-coding the client cache version string,
which makes it brittle whenever the cache version is intentionally bumped.
Update the assertions in clientCache.test.ts to use the source of truth for the
version, either by importing CLIENT_CACHE_VERSION or by deriving the expected
value from the module behavior around runClientCacheMaintenance(). Keep the rest
of the key checks (VERSION_KEY, QUERY_CACHE_PREFIX, MISMATCH_LOG_KEY) intact and
avoid pinning an exact release-specific literal in the test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 26b288fb-68b6-49f7-bf53-c21e59310e95
⛔ Files ignored due to path filters (1)
src/vertex/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (16)
.github/workflows/safe-checks.ymlsrc/vertex/README.mdsrc/vertex/app/_docs/internal/TESTING.mdsrc/vertex/core/utils/clientCache.test.tssrc/vertex/core/utils/cohortName.test.tssrc/vertex/core/utils/getApiErrorMessage.test.tssrc/vertex/core/utils/rememberedAccounts.test.tssrc/vertex/core/utils/responsive.tssrc/vertex/core/utils/sessionManager.test.tssrc/vertex/core/utils/status.test.tssrc/vertex/core/utils/urlHelpers.test.tssrc/vertex/core/utils/userPreferences.test.tssrc/vertex/package.jsonsrc/vertex/tsconfig.jsonsrc/vertex/vitest.config.tssrc/vertex/vitest.setup.ts
💤 Files with no reviewable changes (1)
- src/vertex/core/utils/responsive.ts
|
New azure vertex changes available for preview here |
Update clientCache tests to consistently reference window.localStorage and to use explicit fakeLocalStorage objects for failure scenarios. Replace spyOn-based mutations with temporary Object.defineProperty swaps that simulate getItem/setItem/removeItem failures, then restore the original storage. Also update assertions to read from window.localStorage and ensure tests remain resilient to storage errors.
|
New azure vertex changes available for preview here |
Description
This PR establishes the foundational automated testing infrastructure for the Vertex project using Vitest and React Testing Library. It fulfills Phase 1 and partially Phase 2 of our testing implementation plan.
Additionally, it introduces unit tests for several highly stable core utilities, establishes internal testing documentation for future contributors, and integrates automated test runs directly into our GitHub Actions CI pipeline to prevent regressions.
What was changed
🛠️ Infrastructure & Tooling
vitest,jsdom, and@testing-library/*tailored for the Next.js App Router environment (vitest.config.ts,vitest.setup.ts).npm run test,npm run test:watch, andnpm run test:coveragetopackage.json..github/workflows/safe-checks.ymlto automatically runType Check(npx tsc --noEmit) andTest & Coverage(npm run test:coverage) on Pull Requests.🧪 Unit Tests Added
Added comprehensive unit tests for the following core utilities:
clientCache.tscohortName.tsgetApiErrorMessage.tsrememberedAccounts.tssessionManager.tsstatus.tsurlHelpers.tsuserPreferences.ts📚 Documentation & Cleanup
src/vertex/app/_docs/internal/TESTING.md.README.mdto reference the new testing scripts.src/vertex/core/utils/responsive.ts(deprecated/unused).Type of change
How Has This Been Tested?
npm run test:coveragelocally and verified all tests pass.vitestcorrectly uses thejsdomenvironment and alias mappings (@/)..github/workflows/safe-checks.ymllocally/remotely to ensure the pipeline correctly executes the Type Check and Test steps.Checklist
What are the relevant tickets?
Summary by CodeRabbit
isDesktop,isMobile,isTablet).