Jest framework - Running Tests

Gathering coverage and test information using the SeaLights Node.jsTest Listener is done in a few steps:

See 'Generating an Agent token' for instructions on how to generate a token

Starting the Test Listener

First, the SeaLights server needs to be notified that a test stage is starting.

Sample command
Unix: ./node_modules/.bin/slnodejs start --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId --teststage "Unit Tests" Windows: call .\node_modules\.bin\slnodejs start --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId --teststage "Unit Tests"

See 'Node.js Command Reference - Starting a test stage' for full parameter details

Running your tests - Functional Tests

Before running your functional tests you need to set up the backend server to receive the test footprints. See 'Using Node.js Agents - Running backend server using SeaLights agent'

Once set up you now run your tests normally while generating one or more JUnit XML result files to be reported to the SeaLights server.

Running your tests - Unit Tests

In order to report the test and coverage information to SeaLights you need to run Jest while producing coverage information and a JUnit results file.

For the JUnit results file, you can use the jest-junit reporter. See https://www.npmjs.com/package/jest-junit for details.

For the coverage, you need to run Jest with the --coverage flag. This generates a coverage/coverage-final.json file

Upload coverage report files

Once done running the unit tests you upload the coverage report files to the SeaLights server using the nycReport option

Sample command for a single file
Unix: ./node_modules/.bin/slnodejs nycReport --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId Windows: call .\node_modules\.bin\slnodejs nycReport --tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId

Upload test results report files

Once done running the tests you upload the test results file to the SeaLights server using the uploadReports option

Sample command for a single file
Unix: ./node_modules/.bin/slnodejs uploadReports --tokenfile /path/to/sltoken.txt --buildsessionidfile buildSessionId --reportFile junit.xml Windows: call .\node_modules\.bin\slnodejs uploadReports--tokenfile \path\to\sltoken.txt --buildsessionidfile buildSessionId --reportFile junit.xml

Ending the Test Stage

Finally, the server needs to be notified that a test stage has ended.

Sample command

Samples

Running unit tests using Jest

Update the jest config with the following
Sample script running the Unit Tests on Unix