microsoft / microsoft/vscode-react-native

[Feature] Add unit tests for killPort command

Open Beginner friendly
#2,951 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement follow-up
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 test to ensure new tests pass
  • Verify test coverage includes all code paths
  • Check that mocks properly stub VS Code APIs and ChildProcess

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.