fix: remove deprecation warning from uloop update#913
Conversation
📝 WalkthroughWalkthroughThis change adds test coverage for CLI update functionality and refactors the CLI implementation to remove shell mode from npm spawn calls while exporting previously private functions for testing purposes. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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.
🧹 Nitpick comments (1)
Packages/src/Cli~/src/__tests__/cli-update.test.ts (1)
100-128: Consider adding test cases for error paths.The test effectively verifies the success path and confirms no shell option (line 114). However, consider adding test cases for:
- Non-zero exit code from install
- Spawn error event
These would improve coverage of the error handling in
updateCli().💡 Optional: Add error path test cases
it('handles non-zero exit code from npm install', () => { const updateChild = createMockChildProcess(); const exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => undefined as never); jest.spyOn(console, 'error').mockImplementation(() => {}); mockSpawn.mockReturnValue(updateChild); updateCli(); updateChild.emitClose(1); expect(exitSpy).toHaveBeenCalledWith(1); }); it('handles spawn error', () => { const updateChild = createMockChildProcess(); const exitSpy = jest.spyOn(process, 'exit').mockImplementation(() => undefined as never); jest.spyOn(console, 'error').mockImplementation(() => {}); mockSpawn.mockReturnValue(updateChild); updateCli(); updateChild.emitError(new Error('ENOENT')); expect(exitSpy).toHaveBeenCalledWith(1); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Packages/src/Cli`~/src/__tests__/cli-update.test.ts around lines 100 - 128, Add two tests under the existing suite exercising error paths for updateCli(): one that simulates a non-zero install exit and one that simulates a spawn error. For each test use createMockChildProcess() and mockSpawn.mockReturnValue(...) (or mockReturnValueOnce if ordering matters), spy on process.exit (mockImplementation to avoid real exit) and stub console.error, call updateCli(), then for the first test call updateChild.emitClose(1) and assert process.exit was called with 1, and for the second call updateChild.emitError(new Error('ENOENT')) and assert process.exit was called with 1; reference updateCli, mockSpawn, createMockChildProcess, emitClose and emitError to locate code to change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@Packages/src/Cli`~/src/__tests__/cli-update.test.ts:
- Around line 100-128: Add two tests under the existing suite exercising error
paths for updateCli(): one that simulates a non-zero install exit and one that
simulates a spawn error. For each test use createMockChildProcess() and
mockSpawn.mockReturnValue(...) (or mockReturnValueOnce if ordering matters), spy
on process.exit (mockImplementation to avoid real exit) and stub console.error,
call updateCli(), then for the first test call updateChild.emitClose(1) and
assert process.exit was called with 1, and for the second call
updateChild.emitError(new Error('ENOENT')) and assert process.exit was called
with 1; reference updateCli, mockSpawn, createMockChildProcess, emitClose and
emitError to locate code to change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 894e5651-df2f-4d2c-9192-a407e262654c
📒 Files selected for processing (3)
Packages/src/Cli~/src/__tests__/cli-update.test.tsPackages/src/Cli~/src/cli.tsPackages/src/Cli~/src/project-root.ts
Summary
uloop updateand version detectionTesting
Summary by cubic
Remove shell mode from
npminvocations inuloop updateand version detection to eliminate the deprecation warning and run commands directly. Adds a regression test and guards the CLI entry point underJestso update helpers can be tested safely.Written for commit 80c4e85. Summary will update on new commits.
Overview
This PR removes the
shell: trueoption from npm commands in the CLI update workflow and adds regression tests to verify the fix. The changes prevent deprecation warnings from npm while maintaining functional equivalence of the command invocations.Changes
Test Coverage
Packages/src/Cli~/src/__tests__/cli-update.test.ts(+129 lines)child_process.spawngetInstalledVersion()correctly parses npm list output and invokes the callback with the resolved versionupdateCli()spawns the global install command without enabling shell modeshellpropertylaunch-unitymodule to isolate update logic testingCore Changes
Packages/src/Cli~/src/cli.ts(+6/-7 lines)getInstalledVersion()andupdateCli()functions to enable testingshell: truefrom bothspawn()calls ingetInstalledVersion()andupdateCli()process.env.JEST_WORKER_ID === undefined)Minor Updates
Packages/src/Cli~/src/project-root.ts(+1/-1 lines)hasUloopInstalled()to use consistent parentheses syntaxImpact