microsoft / microsoft/vscode-react-native
[Feature] Add unit tests for killPort command
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.7k
- Forks
- 295
- Avg merge
- 11h 17m
- Merged PRs (30d)
- 24
Description
Summary
The killPort command (src/extension/commands/killPort.ts) allows users to kill processes running on specific ports via the command palette, but currently lacks unit test coverage.
Motivation
- Test coverage gap:
src/extension/commands/killPort.ts(40 lines) has no corresponding test file - User-facing functionality: Command prompts user for port input and executes
npx kill-port - Error handling: Needs validation for invalid port inputs, command failures, and cancellation
- Process execution: Uses ChildProcess to run external command, needs mocking
- Pattern consistency: Most other command palette commands have test files
Current State
- Source file:
src/extension/commands/killPort.ts - No test file in
test/extension/commands/ - Command extends ReactNativeCommand base class
- Uses VS Code showInputBox for user input
- Executes
npx kill-port <port>via ChildProcess
Suggested Implementation
Add test/extension/commands/killPort.test.ts with coverage for:
- Valid port input and successful kill
- Invalid port input (non-numeric, empty)
- User cancellation (no input provided)
- ChildProcess execution failure
- Logger output verification
Follow existing test patterns from launchAndroidEmulator.test.ts and networkView.test.ts.
Validation
- Run
npm testto ensure new tests pass - Verify test coverage includes all code paths
- Check that mocks properly stub VS Code APIs and ChildProcess
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/extension/commands/killPort.ts, then compare test patterns in launchAndroidEmulator.test.ts and networkView.test.ts. Add test/extension/commands/killPort.test.ts covering valid, invalid, cancelled, and failed ChildProcess cases, including logger output. Run npm test and confirm all code paths are covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react-native, typescript
- Domain
- devtools, testing
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100