microsoft / microsoft/vscode-react-native

[Feature] Add unit tests for networkInspector commands

Open
#2,946 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 network inspector command files (networkInspector.ts and networkInspectorManager.ts) implement network inspection start/stop functionality but lack dedicated unit tests for command initialization and execution flow.

Motivation

  • Test coverage gap: Command files exist without corresponding command-level tests
  • Existing tests: networkInspectorManager.test.ts tests the manager class, but not the command wrappers
  • Recent work: PR #2916 added tests for networkView.ts command, establishing pattern to follow

Current State

Tested:

  • test/extension/networkInspector/networkInspectorManager.test.ts - Tests manager class
  • test/extension/commands/networkView.test.ts - Tests toggle network view command

Not Tested:

  • src/extension/commands/networkInspector.ts - Start/stop inspector commands
  • src/extension/commands/networkInspectorManager.ts - Manager integration commands

Commands to Test

From networkInspector.ts:

  1. StartNetworkInspector - Starts network inspector
  2. StopNetworkInspector - Stops network inspector

From networkInspectorManager.ts (if contains commands):

  • Manager coordination logic

Proposed Changes

Create test/extension/commands/networkInspector.test.ts to cover:

  1. StartNetworkInspector command:

    • Command initialization (codeName, label, error)
    • Project requirement validation
    • Calls network inspector manager to start
    • Error handling when start fails
  2. StopNetworkInspector command:

    • Command initialization
    • Calls network inspector manager to stop
    • Proper cleanup
    • Error handling
  3. Integration with manager:

    • Mock NetworkInspectorManager calls
    • Verify correct parameters passed
    • Test command lifecycle

Test Structure Example

describe('networkInspector commands', () => {
  let mockProject: sinon.SinonStubbedInstance<AppLauncher>;
  let networkInspectorManagerMock: sinon.SinonStubbedInstance<NetworkInspectorManager>;

  describe('StartNetworkInspector', () => {
    it('should have correct command properties', () => { /* ... */ });
    it('should start network inspector via manager', async () => { /* ... */ });
    it('should handle start failure', async () => { /* ... */ });
  });

  describe('StopNetworkInspector', () => {
    it('should have correct command properties', () => { /* ... */ });
    it('should stop network inspector via manager', async () => { /* ... */ });
    it('should handle stop failure', async () => { /* ... */ });
  });
});

Benefits

  • Complete test coverage for network inspector commands
  • Align with pattern established by networkView.test.ts
  • Complement existing networkInspectorManager.test.ts tests
  • Prevent regressions in command execution logic
  • Document expected command behavior

Context

  • Recent addition: test/extension/commands/networkView.test.ts (PR #2916)
  • Existing manager tests: test/extension/networkInspector/networkInspectorManager.test.ts
  • Integration tests: test/smoke/suites/networkInspector.test.ts
  • Command start/stop tests exist at integration level but not unit level

References

  • Source files: src/extension/commands/networkInspector.ts, networkInspectorManager.ts
  • Related test: test/extension/commands/networkView.test.ts (PR #2916)
  • Manager test: test/extension/networkInspector/networkInspectorManager.test.ts

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/networkInspector.ts and networkInspectorManager.ts, then compare the command setup and assertions in test/extension/commands/networkView.test.ts. Review test/extension/networkInspector/networkInspectorManager.test.ts and the integration test before mocking manager calls and covering initialization, validation, start/stop execution, cleanup, and failures. Run the relevant command tests to confirm the expected behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
devtools, testing
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.