microsoft / microsoft/vscode-react-native

[Feature] Add unit tests for testDevEnvironment command

Closed
#2,943 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 testDevEnvironment.ts command implements environment validation for React Native development but currently lacks unit test coverage.

Motivation

  • Test coverage gap: src/extension/commands/testDevEnvironment.ts (77 lines) has no test file
  • Critical functionality: Validates development environment setup across platforms
  • Complex logic: Multi-platform checks (Expo, Windows, macOS), project detection
  • Integration point: Uses validation service that needs testing

Current State

  • Source file: src/extension/commands/testDevEnvironment.ts (77 lines)
  • Test file: Does not exist
  • Related tested services: ValidationCategoryE, RNProjectObserver, ProjectVersionHelper

Command Functionality

The testDevEnvironment command:

  • Works without requiring a project (requiresProject = false)
  • Detects Expo managed apps
  • Identifies RN Windows and macOS projects
  • Runs platform-specific validation checks
  • Integrates with validation service infrastructure

Proposed Changes

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

  1. Project selection handling:

    • Test behavior when no workspace is found
    • Test with valid project
    • Test error handling for WorkspaceNotFound
  2. Platform detection:

    • Test Expo project detection via ExponentHelper
    • Test RN Windows project detection
    • Test RN macOS project detection
    • Test fallback behavior when detection fails
  3. Validation execution:

    • Mock runChecks() with different shouldCheck combinations
    • Test validation with project context
    • Test validation without project context
    • Verify correct validation categories are passed
  4. RNProjectObserver integration:

    • Test project observer creation
    • Test version detection flow
    • Test graceful degradation on observer creation failure

Test Structure Example

describe('TestDevEnvironment', () => {
  let command: TestDevEnvironment;
  let mockProject: sinon.SinonStubbedInstance<AppLauncher>;
  let runChecksMock: sinon.SinonStub;

  describe('platform detection', () => {
    it('should detect Expo managed app', async () => { /* ... */ });
    it('should detect RN Windows project', async () => { /* ... */ });
    it('should detect RN macOS project', async () => { /* ... */ });
  });

  describe('validation execution', () => {
    it('should run checks with correct categories when project exists', async () => { /* ... */ });
    it('should run checks without project context', async () => { /* ... */ });
  });

  describe('error handling', () => {
    it('should handle WorkspaceNotFound gracefully', async () => { /* ... */ });
    it('should handle project observer creation failure', async () => { /* ... */ });
  });
});

Benefits

  • Ensure environment validation works across all platforms
  • Validate error handling for missing workspaces
  • Document expected behavior for different project types
  • Prevent regressions in validation service integration
  • Improve reliability of development environment checks

Technical Notes

  • Command has requiresTrust = false and requiresProject = false — unique properties to test
  • Uses async project detection with error recovery
  • Integrates with validation service (runChecks)
  • Platform detection logic is conditional and needs comprehensive testing

References

  • Source: src/extension/commands/testDevEnvironment.ts
  • Related: ValidationCategoryE, RNProjectObserver, runChecks
  • Similar patterns: Commands with optional project context

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/testDevEnvironment.ts and compare similar command tests under test/extension/commands. Create test/extension/commands/testDevEnvironment.test.ts, covering missing and valid workspaces, Expo, RN Windows and macOS detection, validation categories, optional project context, and observer failures. Run the targeted test and confirm all listed paths and error cases are covered.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.