microsoft / microsoft/vscode-react-native

[Feature] Add unit tests for selectAndInsertDebugConfiguration command

Open
#2,947 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 selectAndInsertDebugConfiguration.ts command handles adding debug configurations to launch.json via VS Code UI but currently lacks unit test coverage.

Motivation

  • Test coverage gap: Command file (likely 100+ lines) has no corresponding test file
  • Critical functionality: Modifies launch.json files, user-facing workflow
  • Complex logic: QuickPick UI, JSON manipulation, file operations
  • Quality assurance: Prevent regressions in debug config insertion

Current State

  • Source file: src/extension/commands/selectAndInsertDebugConfiguration.ts
  • Test file: Does not exist
  • Related functionality: Debug configuration provider, launch.json completions

Expected Command Functionality

Based on naming and related files, the command likely:

  • Shows QuickPick menu with available debug configurations
  • Inserts selected configuration into workspace launch.json
  • Handles multiple workspace folders
  • Creates launch.json if it doesn't exist
  • Validates and formats JSON properly
  • Integrates with VS Code's debug configuration system

Proposed Changes

Create test/extension/commands/selectAndInsertDebugConfiguration.test.ts with coverage for:

  1. Configuration selection:

    • Mock QuickPick UI
    • Test configuration list population
    • Test user selection handling
    • Test cancellation handling
  2. launch.json manipulation:

    • Test insertion into existing launch.json
    • Test creation of new launch.json
    • Test JSON formatting and validation
    • Test duplicate configuration prevention (if applicable)
  3. Workspace handling:

    • Single workspace folder scenario
    • Multi-root workspace scenario
    • Workspace folder selection logic
  4. Error handling:

    • File write errors
    • Invalid JSON in existing launch.json
    • Missing workspace folder
    • User cancellation

Test Structure Example

describe('selectAndInsertDebugConfiguration', () => {
  let command: SelectAndInsertDebugConfiguration;
  let mockQuickPick: vscode.QuickPick<any>;
  let fsWriteMock: sinon.SinonStub;

  beforeEach(() => { /* setup */ });

  describe('configuration selection', () => {
    it('should show available debug configurations', async () => { /* ... */ });
    it('should handle user selection', async () => { /* ... */ });
    it('should handle cancellation', async () => { /* ... */ });
  });

  describe('launch.json modification', () => {
    it('should insert config into existing launch.json', async () => { /* ... */ });
    it('should create launch.json if missing', async () => { /* ... */ });
    it('should prevent duplicate configurations', async () => { /* ... */ });
  });

  describe('workspace handling', () => {
    it('should work in single-root workspace', async () => { /* ... */ });
    it('should prompt for folder in multi-root workspace', async () => { /* ... */ });
  });
});

Investigation Needed

Before implementation, review the source file to understand:

  1. Exact UI flow and user interactions
  2. JSON manipulation approach
  3. Integration with debug configuration provider
  4. Error scenarios to test

Benefits

  • Validate JSON manipulation logic
  • Ensure proper QuickPick UI behavior
  • Prevent regressions in launch.json modifications
  • Document expected command workflow
  • Improve reliability of debug config insertion

Technical Considerations

  • Need to mock VS Code APIs: vscode.window.showQuickPick, vscode.workspace.fs
  • Test JSON parsing/stringifying edge cases
  • Verify proper workspace folder handling
  • Mock file system operations

References

  • Source: src/extension/commands/selectAndInsertDebugConfiguration.ts
  • Related: ReactNativeDebugConfigProvider, LaunchJsonCompletionProvider
  • Similar patterns: Commands that modify files (revertOpenModule, etc.)

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 by reading src/extension/commands/selectAndInsertDebugConfiguration.ts and related ReactNativeDebugConfigProvider and LaunchJsonCompletionProvider code to confirm the command's actual UI and JSON flow. Add test/extension/commands/selectAndInsertDebugConfiguration.test.ts using mocked VS Code APIs, covering selection, cancellation, workspace handling, launch.json creation or insertion, and errors. Done means the command's documented workflows and edge cases have regression coverage.

Written by the indexing model from the issue text.

Assessment

Tech stack
react-native, typescript, vscode
Domain
developer-experience, devtools, testing-qa
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.