microsoft / microsoft/vscode-react-native
[Feature] Add unit tests for networkInspector commands
Nobody has claimed this yet.
- 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.tstests the manager class, but not the command wrappers - Recent work: PR #2916 added tests for
networkView.tscommand, 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:
StartNetworkInspector- Starts network inspectorStopNetworkInspector- Stops network inspector
From networkInspectorManager.ts (if contains commands):
- Manager coordination logic
Proposed Changes
Create test/extension/commands/networkInspector.test.ts to cover:
-
StartNetworkInspector command:
- Command initialization (codeName, label, error)
- Project requirement validation
- Calls network inspector manager to start
- Error handling when start fails
-
StopNetworkInspector command:
- Command initialization
- Calls network inspector manager to stop
- Proper cleanup
- Error handling
-
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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