test: 补充 zip-options / i18n / user / plugin-config 测试#52
Conversation
…and plugin-config New test files: - tests/zip-options-file.test.ts: zipOptionsForPayloadFile with real files (magic bytes, extensions, empty files) - tests/i18n.test.ts: t() translation function (en/zh, interpolation, fallback) - tests/user.test.ts: userCommands login/logout/me with API mocking - tests/plugin-config.test.ts: sentry plugin detection via filesystem 234 tests pass, 0 failures.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThis PR adds four Bun test suites covering i18n translation behavior, Sentry plugin detection, user authentication commands, and file compression option selection. ChangesUnit Test Coverage
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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: 9
🤖 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 `@tests/i18n.test.ts`:
- Around line 48-54: The test currently only asserts a non-empty string for
unknown keys; update the test in the 'returns the key itself or a fallback for
an unknown key' case to assert the exact fallback by checking that
t('this_key_does_not_exist_at_all') strictly equals the input key (i.e., result
=== 'this_key_does_not_exist_at_all') after calling i18next.changeLanguage('en')
so the test fails if a different fallback is returned; reference the existing
test block, the t(...) call, and the literal key string to locate and change the
expectation.
- Line 7: Await the i18next language switch and tighten the unknown-key
assertion: change the test to await i18next.changeLanguage('en') before calling
i18next.t(...) to ensure deterministic results, and update the unknown-key test
to assert that i18next.t('some_missing_key') returns the key itself (i.e. equals
'some_missing_key') instead of merely checking for a non-empty string; refer to
i18next.changeLanguage and i18next.t in tests/i18n.test.ts to locate and fix the
two spots.
In `@tests/plugin-config.test.ts`:
- Around line 1-7: The import from 'bun:test' is spread across multiple lines
and fails Biome's single-line import rule; collapse it into a single-line import
so the named symbols (afterEach, beforeEach, describe, expect, test) are
imported in one statement from 'bun:test' (i.e., replace the multi-line import
block with a single-line import that lists those identifiers and imports from
'bun:test').
- Around line 25-29: The test currently force-unwraps the result with a non-null
assertion on sentryPlugin which can throw before the assertion runs; remove the
`!` so `sentryPlugin` is allowed to be undefined (e.g., const sentryPlugin =
plugins.find(...)) and let the existing test
`expect(sentryPlugin).toBeDefined()` fail naturally; update any TypeScript
typing only if needed so the variable can be undefined rather than
force-unwrapped.
In `@tests/user.test.ts`:
- Around line 1-8: Run Biome's automated organize-imports and formatting on the
test file to resolve CI failures: re-run the import organizer on the top import
statement that includes afterEach, beforeEach, describe, expect, spyOn, test so
the named imports are ordered per Biome rules, and apply Biome/formatting to fix
the malformed block around lines 121-126 (the test/assert block causing
formatting errors); you can do this by running Biome (e.g., biome format --apply
or biome check --apply) on the file and committing the resulting changes.
- Around line 89-93: Remove the unused callCount variable and its increment
inside the mock implementation to satisfy the linter: delete the `let callCount
= 0;` declaration and the `callCount++;` line in the
`questionSpy.mockImplementation(async (prompt: string) => { ... })` block so the
mock only returns the expected values without tracking an unused counter.
- Around line 80-86: The test "calls saveSession after replaceSession" only
asserts saveSessionSpy was called; change it to assert call order by ensuring
replaceSessionSpy was called before saveSessionSpy after invoking
userCommands.login (e.g., compare replaceSessionSpy.mock.invocationCallOrder[0]
and saveSessionSpy.mock.invocationCallOrder[0] or use a Jest helper that checks
call order). Reference the existing spies saveSessionSpy and replaceSessionSpy
and update the expectation(s) to fail if saveSessionSpy executes before
replaceSessionSpy.
In `@tests/zip-options-file.test.ts`:
- Around line 1-8: The import block in tests/zip-options-file.test.ts
incorrectly imports the unused symbol ZIP_ENTRY_SNIFF_BYTES and the imports are
not organized; remove ZIP_ENTRY_SNIFF_BYTES from the import list and
reorder/organize the imports (e.g., group and alphabetize module imports) so
only used symbols like zipOptionsForPayloadFile are imported from
'../src/utils/zip-options' and the top-level imports (bun:test, fs, os, path)
follow the project's import ordering rules.
- Around line 23-58: The byte-array literals used in Buffer.from calls
(pngMagic, hermesMagic, jpegMagic in tests/zip-options-file.test.ts) are not
formatted to match the Biome formatter; run the repository formatter (Biome/your
project's format script) or your editor's autoformat on that file and commit the
resulting changes so the magic-byte arrays are rewrapped/spaced according to the
formatter, ensuring Buffer.from([...]) lines for pngMagic, hermesMagic and
jpegMagic match CI expectations.
🪄 Autofix (Beta)
✅ Autofix completed
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: db493286-561a-4f68-9e02-8ee0d314ec62
📒 Files selected for processing (4)
tests/i18n.test.tstests/plugin-config.test.tstests/user.test.tstests/zip-options-file.test.ts
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 3 file(s) based on 4 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 3 file(s) based on 4 unresolved review comments. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
新增测试文件
新增 4 个测试文件,32 个新测试用例,覆盖之前完全没有测试的模块。
tests/zip-options-file.test.ts(8 tests)zipOptionsForPayloadFile— 通过真实文件系统测试魔数检测和压缩策略:tests/i18n.test.ts(7 tests)i18n
t()翻译函数:tests/user.test.ts(11 tests)userCommandslogin/logout/me:ok)tests/plugin-config.test.ts(6 tests)Sentry 插件检测:
detect()文件系统探测测试结果:234 pass, 0 fail
Summary by CodeRabbit