Simplify some tests, remove some tests - #33
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
WalkthroughThe pull request consolidates Vitest configuration, adds ChangesTest infrastructure and configuration
Transformer parser tests
Editor configuration
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
packages/config/src/features/loader/resolve.test.ts (1)
12-13: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMock
process.cwdinstead of mutating the global working directory.Using
process.chdirmutates the working directory for the entire process. This is a known anti-pattern in testing, as it can cause flaky behaviour if tests run concurrently or asynchronous operations are pending. Mockingprocess.cwdis a safer alternative that preserves test isolation.
packages/config/src/features/loader/resolve.test.ts#L12-L13: replace the lifecycleprocess.chdircalls with a mock (requires importingvifromvitest).-beforeEach(() => process.chdir(dir)); -afterEach(() => process.chdir(cwd)); +beforeEach(() => { vi.spyOn(process, 'cwd').mockReturnValue(dir); }); +afterEach(() => { vi.restoreAllMocks(); });
packages/config/src/features/loader/resolve.test.ts#L34-L35: update the inline reset to override the mock instead of changing the real directory.- process.chdir(cwd); + vi.spyOn(process, 'cwd').mockReturnValue(cwd);🤖 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 `@packages/config/src/features/loader/resolve.test.ts` around lines 12 - 13, In packages/config/src/features/loader/resolve.test.ts lines 12-13, import vi from vitest and replace the beforeEach/afterEach process.chdir calls with a process.cwd mock that returns the test directory and restores isolation afterward. At lines 34-35, update the inline reset to override the process.cwd mock rather than changing the real working directory.
🤖 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 `@packages/config/src/features/catalogue/storage.test.ts`:
- Around line 44-50: Update the test “passes existing content to the formatter
when the file already exists” to spy on the formatter and capture its
invocation, importing vi from vitest as needed. Configure the mock to preserve
or expose the existingContent argument, then assert that the second write passes
the previously written catalogue content to the formatter instead of only
asserting that the call resolves.
---
Nitpick comments:
In `@packages/config/src/features/loader/resolve.test.ts`:
- Around line 12-13: In packages/config/src/features/loader/resolve.test.ts
lines 12-13, import vi from vitest and replace the beforeEach/afterEach
process.chdir calls with a process.cwd mock that returns the test directory and
restores isolation afterward. At lines 34-35, update the inline reset to
override the process.cwd mock rather than changing the real working directory.
🪄 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: 2cfa1fa6-f7a2-4cda-88a9-3b16dc5dc03f
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (18)
.vscode/extensions.json.vscode/settings.jsonpackage.jsonpackages/config/src/__fixtures__/bucket.tspackages/config/src/features/catalogue/extractor.test.tspackages/config/src/features/catalogue/merge.test.tspackages/config/src/features/catalogue/path.test.tspackages/config/src/features/catalogue/storage.test.tspackages/config/src/features/loader/resolve.test.tspackages/config/src/features/watch.test.tspackages/config/src/features/workers/extract-worker.test.tspackages/config/src/features/workers/shared.test.tspackages/plugin-unplugin/src/index.test.tspackages/transform-js/src/generator.test.tspackages/transform-js/src/parser.test.tspackages/transform-jsx/src/generator.test.tspackages/transform-jsx/src/parser.test.tsvitest.config.ts
💤 Files with no reviewable changes (10)
- packages/transform-jsx/src/generator.test.ts
- packages/config/src/fixtures/bucket.ts
- packages/transform-js/src/generator.test.ts
- packages/config/src/features/watch.test.ts
- packages/config/src/features/catalogue/extractor.test.ts
- packages/config/src/features/catalogue/merge.test.ts
- packages/config/src/features/workers/extract-worker.test.ts
- packages/config/src/features/workers/shared.test.ts
- packages/config/src/features/catalogue/path.test.ts
- packages/plugin-unplugin/src/index.test.ts
| it('passes existing content to the formatter when the file already exists', async () => { | ||
| const path = join(dir, 'existing.json'); | ||
| await writeCatalogueMessages(makeBucket(), 'en', [message], path); | ||
| await writeCatalogueMessages(bucket, 'en', [message], path); | ||
| // Second write should read the existing file first (no throw). | ||
| await expect( | ||
| writeCatalogueMessages(makeBucket(), 'en', [message], path), | ||
| ).resolves.toBeUndefined(); | ||
| await expect(writeCatalogueMessages(bucket, 'en', [message], path)).resolves.toBeUndefined(); | ||
| }); | ||
|
|
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert that existingContent is correctly passed to the formatter.
The test title states that it verifies existing content is passed to the formatter. However, the mock formatter currently drops this argument, and the test merely checks that the function resolves without throwing. To ensure functional correctness, spy on the formatter and explicitly assert that it receives the existing content.
💡 Proposed fix (requires importing `vi` from `vitest`)
it('passes existing content to the formatter when the file already exists', async () => {
const path = join(dir, 'existing.json');
await writeCatalogueMessages(bucket, 'en', [message], path);
- // Second write should read the existing file first (no throw).
- await expect(writeCatalogueMessages(bucket, 'en', [message], path)).resolves.toBeUndefined();
+
+ const spy = vi.spyOn(bucket.formatter, 'stringify');
+ await writeCatalogueMessages(bucket, 'en', [message], path);
+
+ expect(spy).toHaveBeenCalledWith(
+ [message],
+ expect.objectContaining({ existingContent: JSON.stringify([message]) })
+ );
});📝 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.
| it('passes existing content to the formatter when the file already exists', async () => { | |
| const path = join(dir, 'existing.json'); | |
| await writeCatalogueMessages(makeBucket(), 'en', [message], path); | |
| await writeCatalogueMessages(bucket, 'en', [message], path); | |
| // Second write should read the existing file first (no throw). | |
| await expect( | |
| writeCatalogueMessages(makeBucket(), 'en', [message], path), | |
| ).resolves.toBeUndefined(); | |
| await expect(writeCatalogueMessages(bucket, 'en', [message], path)).resolves.toBeUndefined(); | |
| }); | |
| it('passes existing content to the formatter when the file already exists', async () => { | |
| const path = join(dir, 'existing.json'); | |
| await writeCatalogueMessages(bucket, 'en', [message], path); | |
| const spy = vi.spyOn(bucket.formatter, 'stringify'); | |
| await writeCatalogueMessages(bucket, 'en', [message], path); | |
| expect(spy).toHaveBeenCalledWith( | |
| [message], | |
| expect.objectContaining({ existingContent: JSON.stringify([message]) }) | |
| ); | |
| }); |
🤖 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 `@packages/config/src/features/catalogue/storage.test.ts` around lines 44 - 50,
Update the test “passes existing content to the formatter when the file already
exists” to spy on the formatter and capture its invocation, importing vi from
vitest as needed. Configure the mock to preserve or expose the existingContent
argument, then assert that the second write passes the previously written
catalogue content to the formatter instead of only asserting that the call
resolves.
Summary by CodeRabbit
Developer Experience
Testing