Testing Philosophy
Correctness and reliability are taken extremely seriously in Oxc. We spend significant effort on strengthening the test infrastructure to prevent problems from propagating to downstream tools.
- Unit/Integration tests - Standard Rust tests in
tests/directories - Conformance tests - Testing against external suites (Test262, Babel, TypeScript, Prettier)
- Snapshot tests - Tracking expected outputs using
insta
Quick Test Commands
Essential Commands
Conformance Tests by Tool
NAPI Tests
Conformance Test Suites
Oxc uses Git submodules for conformance testing:Test262 - ECMAScript Specification
Location:tasks/coverage/test262/
- Official JavaScript test suite from TC39
- Tests compliance with ECMAScript specification
- Used by: parser, semantic, codegen, transformer, minifier, estree
Babel - JavaScript Transformation
Location:tasks/coverage/babel/
- Comprehensive transformation and parsing tests
- Covers modern JavaScript features and edge cases
- Used by: parser, semantic, codegen, transformer, minifier
TypeScript - TypeScript Syntax
Location:tasks/coverage/typescript/
- Microsoft’s TypeScript compiler tests
- Ensures correct handling of TypeScript syntax and semantics
- Used by: parser, semantic, codegen, transformer, estree
Prettier - Code Formatting
Location:tasks/prettier_conformance/prettier/
- Prettier’s comprehensive formatting test suite
- Ensures code formatting matches industry standards
- Used by: formatter
Managing Submodules
Crate-Specific Testing
oxc_parser
Strategy: Conformance testing only (no unit tests)tasks/coverage/misc/pass/- Should parse successfullytasks/coverage/misc/fail/- Should fail to parse
oxc_linter
Strategy: Inline tests in rule files Test pattern:crates/oxc_linter/src/rules/<plugin>/<rule>.rs
Running tests:
oxc_formatter
Strategy: Prettier conformance only (no unit tests)oxc_transformer
Strategy: Multiple approaches- Unit tests:
crates/oxc_transformer/tests/integrations/ - Conformance:
tasks/transform_conformance/ - Babel plugins:
tasks/transform_conformance/tests/babel-plugin-*/
oxc_minifier
Strategy: Unit tests with size trackingtests/ecmascript/- ECMAScript operationstests/peephole/- Peephole optimizationstests/mangler/- Name mangling
oxc_codegen
Strategy: Integration testscrates/oxc_codegen/tests/integration/
js.rs- JavaScript code generationts.rs- TypeScript code generationsourcemap.rs- Source map generationcomments.rs- Comment preservation
oxc_isolated_declarations
Strategy: Snapshot testing withinsta
- Input:
tests/fixtures/*.{ts,tsx} - Output:
tests/snapshots/*.snap
oxc_semantic
Strategy: Multiple testing approaches- Conformance tests (
tests/conformance/) - Contract-as-code for symbols and references - Integration tests (
tests/integration/) - Scopes, symbols, modules, classes, CFG - Snapshot tests (
tests/main.rs) - Scope trees, bindings, symbols, references - Coverage tests - Via Test262, Babel, TypeScript suites
Other Crates
Snapshot Testing
Oxc uses theinsta crate for snapshot testing.
How Snapshots Work
- Snapshots track failing tests, not passing ones
- Located in
tasks/coverage/snapshots/and crate-specific directories - Formats:
.snap- Failure counts.snap.md- Detailed failure information
Managing Snapshots
Snapshot Best Practices
- Review carefully - Snapshots should reflect expected behavior
- Commit snapshots - Always commit snapshot files with your changes
- Update when needed - Update snapshots when behavior intentionally changes
- Check diffs - Review snapshot diffs to understand test changes
NAPI Testing
NAPI packages use Vitest for testing Node.js bindings.Setup
Package-Specific Tests
test/ directory (TypeScript files)
Adding New Tests
Where to Add Tests
| Component | Location |
|---|---|
| Parser | tasks/coverage/misc/pass/ or fail/ |
| Linter | Inline in rule files |
| Formatter | Prettier conformance suite |
| Minifier | crates/oxc_minifier/tests/ |
| Transformer | crates/oxc_transformer/tests/integrations/ |
| Codegen | crates/oxc_codegen/tests/integration/ |
| Isolated Declarations | crates/oxc_isolated_declarations/tests/fixtures/ |
| Semantic | crates/oxc_semantic/tests/ |
| NAPI | napi/<package>/test/ |
Test Writing Guidelines
Debugging Tests
Running Specific Tests
Using Examples for Debugging
Searching Test Suites
Conformance test suites are pre-cloned and searchable:Code Coverage
Generate code coverage reports:target/llvm-cov/html/.
Continuous Integration
Oxc runs extensive tests in CI:- All unit and integration tests
- All conformance tests
- Snapshot validation
- Linting and formatting checks
- NAPI tests on multiple platforms
- Documentation builds
Next Steps
- Learn how to Add Linter Rules
- Review the Architecture
- Check the FAQ for testing tips