Console output

If you’re writing a custom reporter, there’s a good chance you’ll want to print output to the console, whether that’s the browser’s developer console or the stdout stream of a server-side process. In order to make sure text-based reporters work on every supported platform, jstest includes an API for writing to the console, no matter what environment your tests are running on. If you use this API, your reporter will work on any platform that jstest supports.

The console API is found on an object called JS.Console in the browser, or require('jstest').Console on CommonJS platforms. It provides several sets of methods for performing various tasks.

Text output

Text formatting

The Console object supports the following methods for formatting text output. Each method adds the named format to the current state, and all text printed after calling the command will have that format applied.

In environments that do not support color formatting, these commands are silently ignored.

Cursor motion

The following methods can be used in some environments to move the cursor within the terminal window.

Exit status

On platforms that allow scripts to exit the current process, this command will end the process with the given status number:

Console.exit(status)

The status parameter is optional and defaults to 0.

Environment variables

The Console object also provides a uniform interface for accessing environment variables on all supported platforms. To read an environment variable, use this method:

// Returns the value of the FORMAT environment variable
var format = Console.envvar('FORMAT');