-
Notifications
You must be signed in to change notification settings - Fork 0
chore: Tests + Version #29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Caution Review failedThe pull request is closed. WalkthroughUpdates tests to stub VITE_API_URL with vi.stubEnv, instantiate ApiClient after stubbing, pass a per-request nonce to ApiClient.get/post in tests, and unstub envs in afterEach. Separately, Node version pins and enforcement were added (.nvmrc, .tool-versions, mise.toml, package.json), and engine-strict was enabled in .npmrc. Changes
Sequence Diagram(s)sequenceDiagram
participant T as Test
participant E as Environment (VITE_API_URL)
participant C as ApiClient
participant F as fetch (network)
T->>E: vi.stubEnv('VITE_API_URL', url)
T->>C: new ApiClient() -- reads VITE_API_URL
T->>C: C.get(path, nonce) / C.post(path, nonce, payload)
C->>F: perform fetch(...) -- includes nonce per-request handling
T->>T: afterEach -> vi.unstubAllEnvs()
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (6)
✨ Finishing Touches
🧪 Generate 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @gocanto, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
I've addressed an issue in the client tests to ensure they are more robust and isolated. The primary goal was to correctly handle the VITE_API_URL environment variable within the test suite. This change ensures that each test runs with a predictable environment, preventing potential side effects from previous tests and making the test suite more reliable.
Highlights
- Test Environment Setup: The VITE_API_URL environment variable is now properly stubbed using
vi.stubEnvwithin thebeforeEachhook, ensuring each test runs with a clean and controlled environment. This replaces the previous global assignment. - Test Environment Teardown: Added
vi.unstubAllEnvs()to theafterEachhook to clean up any stubbed environment variables after each test. This prevents environment variable leakage between tests, ensuring test isolation and reliability.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request correctly refactors the client tests to use vi.stubEnv for setting environment variables, which is a great improvement for ensuring test isolation and preventing state leakage. The cleanup in afterEach with vi.unstubAllEnvs is also a good practice. I've added a couple of minor suggestions to align the code formatting with the existing style in the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
tests/stores/api/client.test.ts(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/stores/api/client.test.ts (2)
src/stores/api/client.ts (1)
ApiClient(29-134)tests/setup.ts (1)
LocalStorageMock(5-19)
🪛 GitHub Actions: Test Format Workflow
tests/stores/api/client.test.ts
[error] 13-27: git diff --exit-code failed with exit code 1. Uncommitted changes detected in tests/stores/api/client.test.ts (indentation changes in beforeEach/afterEach blocks).
🔇 Additional comments (1)
tests/stores/api/client.test.ts (1)
17-19: Good fix: stub env before constructing ApiClientStubbing VITE_API_URL via vi.stubEnv and instantiating the client afterwards ensures the base URL is read correctly. localStorage.clear in beforeEach is appropriate isolation.
tests/stores/api/client.test.ts
Outdated
| vi.stubGlobal('fetch', vi.fn()); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Unstub stubbed globals in teardown to avoid leaks
vi.restoreAllMocks won’t revert vi.stubGlobal. Add vi.unstubAllGlobals() in afterEach so fetch doesn’t remain mocked across other tests.
🏁 Script executed:
#!/bin/bash
# Locate the client test file
TEST_FILE=$(fd client.test.ts | head -n 1)
echo "Client test file: $TEST_FILE"
# Show stubGlobal usage
echo "=== stubGlobal context ==="
rg -n -C3 "vi.stubGlobal" "$TEST_FILE" || true
# Show afterEach or teardown
echo "=== afterEach context ==="
rg -n -C3 "afterEach" "$TEST_FILE" || trueLength of output: 913
Add vi.unstubAllGlobals() in teardown to clean up stubbed globals
The existing afterEach calls restore mocks and environments but doesn’t revert globals stubbed with vi.stubGlobal. Without unstubbing, fetch remains mocked across tests.
• File: tests/stores/api/client.test.ts
• Location: inside the existing afterEach block
Suggested diff:
afterEach(() => {
vi.restoreAllMocks();
vi.unstubAllEnvs();
+ vi.unstubAllGlobals();
});📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| vi.stubGlobal('fetch', vi.fn()); | |
| }); | |
| afterEach(() => { | |
| vi.restoreAllMocks(); | |
| vi.unstubAllEnvs(); | |
| vi.unstubAllGlobals(); | |
| }); |
🤖 Prompt for AI Agents
In tests/stores/api/client.test.ts around lines 20 to 21, the afterEach block
restores mocks/environments but does not revert globals stubbed with
vi.stubGlobal (e.g., fetch), so add a call to vi.unstubAllGlobals() inside the
existing afterEach to ensure any globally stubbed values are removed between
tests; keep it alongside the existing restore calls so cleanup runs after each
test.
tests/stores/api/client.test.ts
Outdated
| vi.restoreAllMocks(); | ||
| vi.unstubAllEnvs(); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Add vi.unstubAllGlobals and fix formatting to unblock CI
- Add vi.unstubAllGlobals() to properly revert the fetch stub after each test.
- The “Test Format Workflow” failed due to indentation changes. Run your repo’s formatter and commit the result.
Proposed change:
afterEach(() => {
- vi.restoreAllMocks();
- vi.unstubAllEnvs();
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+ vi.unstubAllEnvs();
});To fix and verify formatting locally:
🏁 Script executed:
#!/bin/bash
# Format the changed test file and verify no further diffs remain.
npx prettier --write tests/stores/api/client.test.ts
# If your repo uses a specific script, prefer it, e.g.:
# pnpm format
# or
# npm run format
# Show if Prettier made changes that need committing
git diff -- tests/stores/api/client.test.ts
# Optional: ensure CI’s format check would pass for this file
npx prettier --check tests/stores/api/client.test.tsLength of output: 1089
Add missing vi.unstubAllGlobals() in afterEach and commit formatting
Tests/stores/api/client.test.ts needs to clean up the fetch stub and keep CI happy:
• In the afterEach block, insert vi.unstubAllGlobals() between vi.restoreAllMocks() and vi.unstubAllEnvs().
• Run your formatter (e.g. pnpm format, npm run format or npx prettier --write tests/stores/api/client.test.ts) and commit the result so indentation changes are captured and the CI format check passes.
Proposed diff:
tests/stores/api/client.test.ts
afterEach(() => {
- vi.restoreAllMocks();
- vi.unstubAllEnvs();
+ vi.restoreAllMocks();
+ vi.unstubAllGlobals();
+ vi.unstubAllEnvs();
});📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| vi.restoreAllMocks(); | |
| vi.unstubAllEnvs(); | |
| }); | |
| tests/stores/api/client.test.ts | |
| afterEach(() => { | |
| vi.restoreAllMocks(); | |
| vi.unstubAllGlobals(); | |
| vi.unstubAllEnvs(); | |
| }); |
🤖 Prompt for AI Agents
In tests/stores/api/client.test.ts around lines 24 to 26, the afterEach cleanup
is missing a call to vi.unstubAllGlobals(), so insert a call to
vi.unstubAllGlobals() between vi.restoreAllMocks() and vi.unstubAllEnvs(), then
run the project formatter (e.g. pnpm format / npm run format / npx prettier
--write tests/stores/api/client.test.ts) and commit the formatted file so CI
format checks pass.
ff429c8 to
706d39b
Compare
Summary
Testing
npx vitest run tests/stores/api/client.test.tshttps://chatgpt.com/codex/tasks/task_e_6899cc90f2fc8333891024def255a9ea
Summary by CodeRabbit
Tests
Chores