Skip to main content

Running Tests

Quick Test Run

Run all tests in parallel (recommended):
Or use the npm script:
This builds the test infrastructure and runs all test suites using multiple worker threads.
By default, hereby uses one worker per CPU core. Adjust with --workers=<number>.

Serial Test Execution

Run tests sequentially for debugging:

Test Suites

TypeScript has several test suites organized by type:
Tests in tests/cases/compiler/ verify compiler behavior:
These test compilation, emit, and error detection.

Running Specific Tests

By Name Pattern

Run tests matching a regex:
Examples:

By Runner

Specify which test runner to use:
Available runners:
  • conformance - Conformance suite
  • compiler - Compiler suite
  • fourslash - Language service suite
  • project - Project suite

From Failed Tests File

Rerun previously failed tests:
Failed tests are tracked in .failed-tests.

Test Options

Watch Mode

Automatically rerun tests when files change:
You must specify --tests or --failed to use watch mode.
Example:
This watches:
  • Test infrastructure (built/local/run.js)
  • Test cases (tests/cases/**)
  • Test libraries (tests/lib/**)

Debugging Tests

Inspector Mode

Run tests with Node.js inspector:
Example:
Then open chrome://inspect in Chrome or attach from VS Code.

VS Code Debugging

1

Create Launch Configuration

Copy .vscode/launch.template.json to .vscode/launch.json:
2

Open Test File

Open the .ts test file you want to debug in VS Code.
3

Launch Debugger

Press F5 or select Run > Start Debugging.The configuration runs Mocha with the currently open test file name.
4

Set Breakpoints

Set breakpoints in either:
  • Test files (tests/cases/**)
  • Compiler source (src/**)
The debugger uses source maps, so breakpoints in TypeScript source work directly.

Test Baselines

Most tests generate baseline files to detect output changes:

Baseline Files

Compiler tests generate:
  • .js - Emitted JavaScript
  • .d.ts - Emitted declarations (in .js file)
  • .errors.txt - Compiler errors
  • .types - Type of each expression
  • .symbols - Symbol for each identifier
  • .js.map - Source maps (if requested)

Comparing Baselines

After running tests, compare changes:
Or manually with git:
Set the DIFF environment variable to use your preferred diff tool:

Accepting Baselines

If the baseline changes are correct:
This copies tests/baselines/local/* to tests/baselines/reference/.
Carefully review baseline changes before accepting! Unexpected changes may indicate bugs.

Writing New Tests

Adding a Compiler Test

1

Create Test File

Add a .ts file in tests/cases/compiler/:
tests/cases/compiler/myNewFeature.ts
2

Add Metadata

Use comment tags to configure test behavior:
3

Run the Test

4

Accept Baselines

Multi-File Tests

Use @filename tags to simulate multiple files:

Conformance Tests

For spec compliance tests, add files to appropriate subdirectories:
Conformance test names must be unique across all test directories.

Test Infrastructure

The test runner is built from src/testRunner/:
Output: built/local/run.js

Test Harness

The harness code in src/harness/ provides utilities:
  • Compiler host implementations
  • Virtual file systems
  • Baseline management
  • Test configuration parsing

ESLint Rule Tests

TypeScript includes custom ESLint rules with their own tests:
Or:
These tests are separate from the main compiler test suite.

Continuous Integration

Sharded Testing

CI systems can split tests across multiple machines:

Coverage Reports

Generate test coverage with c8:
Coverage reports are written to the coverage/ directory.

Troubleshooting

Build the test infrastructure:
Regenerate baselines:
Increase timeout:
Watch mode is experimental. Use manual reruns:
Ensure you’ve built tests with source maps:
Source maps are enabled by default in Herebyfile.mjs.

Test Guidelines

Test Requirements

Every PR should include:
  • At least one test that fails without your changes
  • Reasonable permutations of the fix/feature
  • Updated baselines if output changes
  • Test names that clearly describe what they test

Next Steps

Debugging

Learn debugging techniques

Building

Build system reference