Skip to Content
GuidesProgrammatic Usage

Programmatic Usage

The programmatic APIs allow integrating TSTyche with other tools.

Requirements

If you plan to use TypeScript, the lowest supported version is 5.4. The module and moduleResolution compiler options must be set to at least "node16".

tstyche/tag

The tstyche/tag entry point provides a tagged template function that runs TSTyche programmatically.

The function runs in the same process, streaming error messages and test results to the stderr and stdout in real-time.

Use the --quiet command line option to suppress standard output and focus solely on errors.

Usage

Call the function with the same arguments you would pass to the tstyche command:

import from "tstyche/tag"; // Equivalent to 'tstyche query-params --only multiple' await `query-params --only multiple`;

The function returns a promise that resolves if the test run is successful and rejects if it fails, making it suitable for runtime tests:

import from "node:test"; import from "tstyche/tag"; ("generate types", async () => { const = (import.meta); // ... await `--quiet --root ${}`; });

tstyche/tstyche

The full programmatic APIs is available from the tstyche/tstyche entry point:

import { Runner } from "tstyche/tstyche"; console.log(Runner.version);

This is consider a power user feature. More documentation may or may not be provided in the future.

Runner

The tstyche command is responsible to read configuration and to select test files. That is done before test runner is invoked.

To run the tests, the Runner class can be used directly. All you have to do is to provide configuration and list of the test files:

import { Config, Runner } from "tstyche/tstyche"; const resolvedConfig = Config.resolve(); const runner = new Runner(resolvedConfig); await runner.run(["./typetests/toBeNumber.tst.ts"]);
Last updated on