microsoft / microsoft/vscode-react-native
[Feature] Add unit tests for testDevEnvironment command
Nobody has claimed this yet.
- 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:
-
Project selection handling:
- Test behavior when no workspace is found
- Test with valid project
- Test error handling for WorkspaceNotFound
-
Platform detection:
- Test Expo project detection via ExponentHelper
- Test RN Windows project detection
- Test RN macOS project detection
- Test fallback behavior when detection fails
-
Validation execution:
- Mock runChecks() with different shouldCheck combinations
- Test validation with project context
- Test validation without project context
- Verify correct validation categories are passed
-
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 = falseandrequiresProject = 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
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 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