Options
All
  • Public
  • Public/Protected
  • All
Menu

Module Guide: Getting started Node.js

Index

Variables

GettingStartedNodejsGuide

GettingStartedNodejsGuide: "" = ''

Getting started with Siesta in Node.js environment

Siesta is a stress-free JavaScript/TypeScript testing tool. It is ubiquitous - tests can be run in browsers, Node.js and Deno, on Linux, macOS and Windows.

In this guide, we assume a setup, pointed toward running tests in Node.js.

Siesta supports all maintained LTS releases of Node.js.

Installation

npm install @bryntum/siesta --save-dev

Basics

To familiarize yourself with the basic Siesta concepts, which are common for all execution environments, please check the Siesta test basics guide.

Importing API

When targeting Node.js environment for running tests, import the Siesta API from the @bryntum/siesta/nodejs.js entry file.

Launching individual test

Let's assume we have the following Siesta test file, called basic_test.t.js.

import { it } from "@bryntum/siesta/nodejs.js"

it('Basic Siesta test', async t => {
t.true(true, "That's true")

t.true(false, "That's not true")
})


it('Deep equality should work', async t => {
t.equal([ 1, 2, 3 ], [ 3, 2, 1 ], "Arrays are deeply equal")

t.expect(
{ receivedKey : 'receivedValue', commonKey : 'commonValue' }
).toEqual(
{ expectedKey : 'expectedValue', commonKey : 'commonValue' }
)
})

We can launch it, as a regular Node.js script:

node tests/basic/basic_test.t.js

You should see something like: Launching test directly

Launching several tests

To launch several tests, you need to use the Siesta launcher. Siesta launcher is an executable file, called siesta. Usually to access it in your local package installation, you use the npx command, provided by the npm package manager:

npx siesta --help

To launch several tests, pass a matching glob pattern as the 1st argument for the launcher. It can be also a directory name, in such case Siesta will pick up all *.t.m?js files in it, recursively. To resolve the glob pattern, Siesta uses the glob npm library, please refer to its documentation for details on globs resolution.

IMPORTANT: Don't forget to quote your glob pattern with single quotes, otherwise it will be expanded by the shell.

Some examples:

Launch all tests in tests directory:

npx siesta tests

Launch all tests in tests directory, with custom extension:

npx siesta 'tests/**/*.test.js'

Launch all tests in tests directory, which have characters 1 or 2 in their names:

npx siesta 'tests/**/*@(1|2)*.t.js'

Debugging

You can debug a Siesta test as any other regular Node.js script. For that, place the debugger statement somewhere in the test code and then start the test with the --inspect-brk option. Note, that due to this issue, starting your test with just --inspect may result in your breakpoint being ignored.

You need to place the --inspect-brk option right after the node executable, before the test file - otherwise it will be passed to the script, instead of the node.

For example, for the test above:

node --inspect-brk tests/basic/basic_test.t.js

Then open the console in any Chrome tab and click the "Dedicated DevTools for Node.js" icon in the bottom-left.

Further reading

Configuring the test suite: Siesta project guide

COPYRIGHT AND LICENSE

MIT License

Copyright (c) 2009-2021 Bryntum, Nickolay Platonov

Generated using TypeDoc