Skip to content

[Feature] Add unit tests for RestartPackager command #2773

Description

@ConnorQi01

Summary

The RestartPackager command (src/extension/commands/restartPackager.ts) has no dedicated unit tests. It calls ProjectVersionHelper.getReactNativePackageVersionsFromNodeModules as a version check before invoking packager.restart(port), but neither the success path nor the failure path is currently exercised in the test suite.

Why this is useful

CleanRestartPackager — the sibling command that performs the same restart step plus extra cleanup — already has comprehensive unit tests following the proxyquire + sinon pattern. Adding equivalent coverage for RestartPackager closes a visible gap in the packager command family and makes regressions on the version-check/restart flow detectable before release.

Suggested scope

  • Add test/extension/commands/restartPackager.test.ts following the same proxyquire pattern used in cleanRestartPackager.test.ts
  • Test: happy path — version check resolves, packager restarts with the port returned by SettingsHelper.getPackagerPort
  • Test: version check rejects — error propagates and packager.restart is not called
  • Test: correct port value is forwarded to packager.restart

Evidence

  • src/extension/commands/restartPackager.ts — calls ProjectVersionHelper.getReactNativePackageVersionsFromNodeModules(nodeModulesRoot) then packager.restart(port)
  • test/extension/commands/cleanRestartPackager.test.ts — established proxyquire + sinon pattern ready to reuse
  • test/extension/commands/ directory — sibling commands (killPort, installPods, startPackager, etc.) all have dedicated test files; restartPackager is the only packager-related command without one

Validation

  • Run npm test (or the mocha suite for test/extension/commands/) and confirm the new test file passes
  • Confirm no regression in existing packager command tests

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    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