Skip to main content

Testing

QuickJS-ng has a comprehensive test suite to ensure correctness and ECMAScript compliance. This guide covers how to run tests and work with the test262 compliance suite.

Running Tests

Basic Test Suite

Run the basic QuickJS test suite:
This executes the test suite defined in tests.conf using the run-test262 tool.

Manual Test Execution

You can also run the test runner directly:

Test262 Compliance Suite

Test262 is the official ECMAScript conformance test suite. QuickJS-ng runs this suite to ensure spec compliance.

Running test262

To run the full test262 suite:
This command:
  1. Initializes the test262 submodule if needed
  2. Runs all applicable test262 tests
  3. Reports pass/fail statistics
The test262 suite is extensive and may take several minutes to complete.

Fast test262 Subset

For quicker feedback during development, run a smaller subset:

Updating test262 Results

After implementing a new feature that changes test262 results:
This updates the error/pass report files, which should be committed with your changes.

Checking test262 Results

Verify that test262 results match expected outcomes:
This runs test262 with the -E flag to check against expected results.

Specialized Tests

API Tests

Test the C API:

Standalone Compilation Test

Test JavaScript-to-executable compilation:

Examples Tests

If built with examples enabled:

Microbenchmarks

Run performance microbenchmarks:
This executes tests/microbench.js to measure performance of common operations.

Platform-Specific Testing

Windows (MSVC)

Windows (MinGW)

Emscripten

WASI

CI Test Matrix

The continuous integration pipeline tests QuickJS-ng across:

Operating Systems

  • Ubuntu Linux (latest, 24.04)
  • macOS (latest)
  • Windows (latest, Server 2019)
  • FreeBSD
  • OpenBSD
  • Cygwin

Architectures

  • x86 (32-bit)
  • x64 (64-bit)
  • ARM64
  • RISC-V (riscv64)
  • s390x

Build Configurations

  • Debug builds
  • Release builds
  • Shared library builds
  • Example builds
  • Amalgamated builds

Compilers

  • GCC
  • Clang
  • MSVC (Visual Studio 2022)
  • MinGW (mingw32, mingw64, ucrt64, clang64)
  • TCC (Tiny C Compiler)
  • Clang-CL

Sanitizers

  • AddressSanitizer (ASan)
  • UndefinedBehaviorSanitizer (UBSan)
  • MemorySanitizer (MSan)
  • ThreadSanitizer (TSan, separate workflow)

Special Builds

  • Emscripten (WebAssembly)
  • WASI
  • Android (arm64-v8a)
  • iOS
  • Parserless builds
  • mimalloc integration

Test Runner Options

The run-test262 tool supports several options:

Common Options

  • -c <file> - Use configuration file
  • -m - Run in multi-threaded mode
  • -a - Run all tests
  • -u - Update test results
  • -E - Check expected results
  • -t <threads> - Number of threads (default: auto)

Configuration Files

  • tests.conf - Basic QuickJS test suite
  • test262.conf - Full test262 suite
  • test262-fast.conf - Fast test262 subset

Writing Tests

Test File Format

QuickJS tests are JavaScript files that throw exceptions on failure:

Adding Tests

  1. Create a new .js file in the tests/ directory
  2. Add test cases that throw on failure
  3. Add the test to the appropriate .conf file
  4. Run the test suite to verify

Debugging Test Failures

Run a Single Test

Enable Debug Output

Use Sanitizers

Build with sanitizers to catch memory errors:

Valgrind

Run tests under Valgrind for memory debugging:
QuickJS-ng has a dedicated Valgrind CI workflow for automated memory leak detection.

Performance Testing

View Engine Statistics

This shows memory usage and allocation statistics.

Benchmark Suite

Run the microbenchmark suite:
The benchmarks test:
  • Arithmetic operations
  • Function calls
  • Object creation
  • Array operations
  • String manipulation
  • Regular expressions

Best Practices

  • Always run make test before submitting pull requests
  • Run test262 for changes affecting ECMAScript compliance
  • Test on multiple platforms when making platform-specific changes
  • Use sanitizers during development to catch memory errors early
  • Add tests for bug fixes to prevent regressions
  • Add tests for new features to ensure they work correctly
  • Update test262 results when implementing new ECMAScript features