Skip to the content.

c8js

Table of contents

Namespaces

Classes

Interfaces

Type Aliases

Variables

Functions

Type Aliases

Watermark

Ƭ Watermark: [low: number, high: number]

Thresholds for low and high code coverage watermarks, in percentage.

Variables

commands

Const commands: Object

Common commands for c8js.

Type declaration

Name Type Description
node Promise<string> A new promise that resolves to the path of node.
npm Promise<string> A new promise that resolves to the path of npm.
npx Promise<string> A new promise that resolves to the path of npx.

version

Const version: string

The version string of c8js.

Functions

checkCoverage

checkCoverage(options?): Promise<void>

Checks that code coverage is within the specified thresholds.

Parameters

Name Type Description
options? Options & Partial<Options> Options for the function.

Returns

Promise<void>

A promise that resolves if code coverage is within the thresholds, and rejects if an error occurs. If code coverage is under the specified thresholds, the promise will reject with a LowCoverageError.


default

default(command, options?): Promise<Result>

Executes a command, generates a coverage report and optionally checks that code coverage is within the specified thresholds.

By default, if the command exits with a nonzero code this function will throw an error without generating a coverage report. This behavior can be changed with the option throwExecError.

This function does not spawn a shell to parse the command line, so don’t put any additional spaces or quotes around the command or the arguments.

Parameters

Name Type Description
command string | Promise<string> The command to run. This can be a binary executable or a Node.js module. If a promise is specified, the resolved value will be used.
options? Options Options for the function.

Returns

Promise<Result>

A promise that settles after the command has terminated. The promise will resolve with an object similar to the return value of child_process.spawnSync with an additional property holding the coverage map. If the option checkCoverage (or [100] 100) is set to true and code coverage is under the specified thresholds, the promise will reject with a LowCoverageError.

default(command, args?, options?): Promise<Result>

Executes a command, generates a coverage report and optionally checks that code coverage is within the specified thresholds.

By default, if the command exits with a nonzero code this function will throw an error without generating a coverage report. This behavior can be changed with the option throwExecError.

This function does not spawn a shell to parse the command line, so don’t put any additional spaces or quotes around the command or the arguments.

Parameters

Name Type Description
command string | Promise<string> The command to run. This can be a binary executable or a Node.js module. If a promise is specified, the resolved value will be used.
args? readonly string[] A list of arguments passed to the command.
options? Options Options for the function.

Returns

Promise<Result>

A promise that settles after the command has terminated. The promise will resolve with an object similar to the return value of child_process.spawnSync with an additional property holding the coverage map. If the option checkCoverage (or [100] 100) is set to true and code coverage is under the specified thresholds, the promise will reject with a LowCoverageError.


exec

exec(command, options?): Promise<Result>

Parameters

Name Type
command string | Promise<string>
options? Options & Partial<Options>

Returns

Promise<Result>

exec(command, args?, options?): Promise<Result>

Executes a command, ensuring that temporary code coverage data is created.

This function does not spawn a shell to parse the command line, so don’t put any additional spaces or quotes around the command or the arguments.

Parameters

Name Type Description
command string | Promise<string> The command to run. This can be a binary executable or a Node.js module. If a promise is specified, the resolved value will be used.
args? readonly string[] A list of arguments passed to the command.
options? Options & Partial<Options> Options for the function.

Returns

Promise<Result>

A promise that settles after the command has terminated. The promise will resolve with an object similar to the return value of child_process.spawnSync.


report

report(options?): Promise<CoverageMap>

Generates a coverage report and optionally checks that code coverage is within the specified thresholds.

Parameters

Name Type Description
options? Options & Partial<Options> Options for the function.

Returns

Promise<CoverageMap>

A promise that resolves with a coverage map, and rejects if an error occurs. If the option checkCoverage (or [100] 100) is set to true and code coverage is under the specified thresholds, the promise will reject with a LowCoverageError.