Testing Overview
View Exports SVG uses automated tests to ensure code quality and prevent regressions. The project includes tests for both the extension and the webview client.Test Framework
The extension uses different testing frameworks for different parts:- Extension: VS Code Extension Test Runner with Mocha
- Client: Vitest with React Testing Library
Running Tests
Extension Tests
To run the extension test suite:- Runs the
pretestscript automatically - Compiles the extension and builds the client
- Downloads VS Code (if needed)
- Launches tests in a VS Code instance
- Displays test results in the terminal
Tests run in an isolated VS Code instance to prevent interference with your development environment.
Pre-test Build
Thepretest script runs automatically before tests:
npm run compile:clean- Cleans the output directorynpm run client:build- Builds the webview UInpm run compile- Compiles the extension
package.json:274
Client Tests
The webview client has its own test suite:Test Structure
Extension Test Files
Extension tests are located insrc/test/:
Test Runner Configuration
The test runner is configured insrc/test/runTest.ts:
src/test/runTest.ts:23
Test Suite Loader
The test suite is loaded bysrc/test/suite/index.ts, which:
- Configures Mocha test runner
- Discovers test files
- Handles test reporting
- Manages test lifecycle
Writing Tests
Extension Test Example
Extension tests use Mocha and VS Code’s testing API:Test Utilities
Tests for utility functions focus on:- Input validation
- Edge cases
- Expected outputs
- Error handling
unaryExpression.test.ts- Tests unary expression parsingbinaryExpression.test.ts- Tests binary expression parsinglogicalExpression.test.ts- Tests logical expression parsing
Test Fixtures
Test assets are stored insrc/test/assets/:
- Sample TypeScript/JavaScript files
- SVG components
- Mock workspace structures
Test Coverage
The test suite covers:Core Functionality
- Extension activation
- Command registration
- File scanning and processing
- SVG component extraction
- Property parsing
Utilities
- File utilities: Scanning, filtering, grouping
- Property utilities: Expression parsing, property extraction
- VS Code utilities: URI handling, theme management
Edge Cases
- Empty files
- Invalid SVG components
- Missing exports
- Malformed expressions
Continuous Integration
Tests run automatically in CI/CD:- Pre-commit - Husky runs linting checks
- Pre-publish - Full test suite runs before packaging
package.json:275
Debugging Tests
Debug Extension Tests
- Open the test file in VS Code
- Set breakpoints
- Open the Debug panel (
Ctrl+Shift+D) - Select “Extension Tests” configuration
- Press
F5to start debugging
Debug Client Tests
Verbose Output
The test runner includes--verbose flag:
package.json:273
Test Workspace
Tests run against a test workspace defined inworkspaceTest.code-workspace. This provides:
- Isolated test environment
- Controlled workspace structure
- Predictable test conditions
Common Test Scenarios
Testing File Scanning
Tests verify:- Workspace scanning for SVG files
- Directory filtering
- File type detection
- Export detection
src/test/suite/utilities/files/scanning.test.ts
Testing Property Parsing
Tests verify:- JSX property extraction
- Expression evaluation
- Type handling
src/test/suite/utilities/properties/
Testing VS Code Integration
Tests verify:- Command registration
- Webview creation
- Configuration access
src/test/suite/extension.test.ts
Best Practices
Troubleshooting
Tests Not Running
Issue: Tests fail to startSolution: Ensure pre-test build succeeds:
VS Code Not Downloading
Issue: Test runner can’t download VS CodeSolution: Check internet connection and proxy settings
Test Timeout
Issue: Tests timeoutSolution: Increase timeout in test suite:
Workspace Issues
Issue: Test workspace state persistsSolution: The test runner automatically cleans the user data directory before each run (see
src/test/runTest.ts:18).
Next Steps
- Learn about the build process
- Understand the project architecture
- Set up your development environment