Skip to content

[Feature] Add unit tests for StopPackager command #2765

Description

@ConnorQi01

Summary

The StopPackager command has two distinct code paths in onBeforeExecute and an optional-chaining call in baseFn that are not covered by any unit tests, while its symmetric counterpart StartPackager received full unit test coverage in PR #2756.

Why this is useful

Adds deterministic coverage for the packager stop lifecycle, ensuring both the direct-AppLauncher path and the selectProject() fallback behave correctly; also explicitly validates the no-op case when getPackager() returns undefined.

Suggested scope

  • Test onBeforeExecute when called with an AppLauncher instance (should assign directly without calling selectProject)
  • Test onBeforeExecute when called with a non-AppLauncher argument (should call selectProject)
  • Test baseFn when getPackager() returns a real packager (should call stop())
  • Test baseFn when getPackager() returns undefined (should not throw due to optional chaining)
  • Follow the proxyquire/sinon pattern established in test/extension/commands/startPackager.test.ts

Evidence

  • src/extension/commands/stopPackager.ts: two branches in onBeforeExecute (lines 18–25), optional-chain call getPackager()?.stop() in baseFn (line 30)
  • test/extension/commands/startPackager.test.ts: reference pattern for the sister command, merged in PR Add StartPackager branch tests #2756
  • No existing file test/extension/commands/stopPackager.test.ts
  • No open issue matching this work found via gh issue list

Validation

  • npm test passes with the new test file included
  • All four branches produce the expected stub call counts

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