Overview
The project uses Jest as its testing framework to validate AST transformations. Each transformer in the deobfuscation pipeline has corresponding unit tests.Jest Configuration
The project uses a minimal Jest configuration:jest.config.js
Uses
babel-jest to transpile ES6+ syntax in test files and source codeRuns tests in a Node.js environment (not browser/jsdom)
Automatically clears mock calls between tests
Generates code coverage reports during test runs
Uses V8’s built-in coverage instrumentation for better performance
Test File Structure
Transformer tests follow the naming pattern:refactor-obfuscated-code-jscodeshift-{N}.test.js
Example Test: Void0Transformer
mitmproxy/src/javascript/refactor-obfuscated-code-jscodeshift-0.test.js
Test Utilities
File Verification Utility
TheverifyFileExists utility is used across all transformer tests:
Base name of the output file (typically a UUID)
The transformer step number (0-10)
The expected transformed JavaScript code
- The output file
{outputBaseName}-0.jsexists - Its contents match the expected output exactly
Test Structure Pattern
All transformer tests follow a consistent structure:1. Import Dependencies
1. Import Dependencies
2. Create Test AST
2. Create Test AST
3. Describe Test Suite
3. Describe Test Suite
4. Create Transformer Instance
4. Create Transformer Instance
5. Execute and Verify
5. Execute and Verify
Running Tests
Run All Tests
**/*.test.js.
Run Specific Test File
Run Tests in Watch Mode
Run with Coverage Report
coverage/ directory.
Coverage Reports
WithcollectCoverage: true, Jest generates coverage reports in multiple formats:
Viewing Coverage
- Statement coverage
- Branch coverage
- Function coverage
- Line coverage
Test Examples
Testing Simple Transformations
Testing Variable Renaming
Testing Complex AST Manipulation
Test Data Management
Using UUID for Test Isolation
Each test generates unique output files using UUIDs:Debugging Tests
Enable Debugger in Tests
Inspect Output Files
Since transformers write output files during tests, you can examine them:Verbose Test Output
Best Practices
Test Each Transformation Independently - Each transformer has its own test file that validates only that specific transformation.
Use Minimal Test Cases
Use Minimal Test Cases
Focus on the smallest code snippet that exercises the transformation:
Test Edge Cases
Test Edge Cases
Include tests for:
- Empty input
- Nested structures
- Multiple occurrences
- Already-transformed code (idempotency)
Verify File Output
Verify File Output
Always use
verifyFileExists to ensure:- Transform executed successfully
- Output file was created
- Output matches expectations exactly
Integration Testing
While unit tests cover individual transformers, integration testing uses the full pipeline:test-output.js with expected deobfuscated code.
Continuous Integration
From README.md:10-13:A CI/CD pipeline is planned to:
- Detect when bet365 updates their obfuscated code
- Run the full test suite
- Ensure deobfuscation continues to work
- Maintain functional backup scripts
Test Coverage Goals
| Component | Target Coverage |
|---|---|
| Transformers | 100% |
| Utilities | 90%+ |
| Integration | Key workflows |
Coverage reports are generated automatically on every test run with the current configuration.
Related Resources
- Jest Documentation
- jscodeshift Testing
- AST Explorer for developing test cases
