Skip to content

[Feature] Add unit tests for CleanRestartPackager command #2663

@ConnorQi01

Description

@ConnorQi01

Summary

The CleanRestartPackager command (src/extension/commands/cleanRestartPackager.ts) has no dedicated unit tests. It implements a 4-step flow (kill Metro port, clean Metro cache, clean Watchman cache, restart packager) with platform-specific branching (Windows vs macOS/Linux), but test/extension/commands/ only contains commands.test.ts and installPods.test.ts.

Why this is useful

Without unit tests, regressions in any of the four steps — especially the platform-specific killMetroProcess logic or the deleteDirectory recursion — go undetected until a user reports a broken "Clean & Restart Packager" command. Adding tests brings this command to the same coverage level as installPods.

Suggested scope

  • Add test/extension/commands/cleanRestartPackager.test.ts using proxyquire or sinon stubs to mock ChildProcess, fs, and ProjectVersionHelper
  • Cover: Windows path (netstat/taskkill), macOS/Linux path (lsof/kill), Metro cache absent, Watchman unavailable, and error-tolerant paths
  • No smoke test needed; unit coverage is sufficient for this command

Evidence

  • src/extension/commands/cleanRestartPackager.ts — 152 lines, 4 private methods, platform branching at line 58
  • test/extension/commands/ — only commands.test.ts and installPods.test.ts exist (no coverage for this command)
  • installPods.test.ts provides a direct pattern to follow for command-level unit tests

Validation

  • Run npm test (unit suite) and confirm the new test file is picked up and passes
  • Verify Windows and non-Windows branches are both exercised via mocked HostPlatform.getPlatformId()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions