Unit Tests - SeaLights Node.js Agent
Unit Testing is done in the CI, after your project has been scanned but before your project is deployed.
Since the Unit Tests are not run against a backend server, you need to use the SeaLights Node agent to report the beginning and end of the test stage “Unit Tests” and to upload the coverage reports generated by your Unit Tests.
For Unit Test coverage to be correctly reflected in SeaLights, you must complete the following steps in order:
Start the test stage with
slnodejs start ...
Run the Unit Tests
Upload the Reports
Junit XML report file
slnodejs uploadReports
Coverage file
slnodejs nycReport
End the test stage with
slnodejs end...
For example, the whole process might look like:
#start the test stage
npx slnodejs start --token $SL_TOKEN --buildsessionid $BUILDSESSIONID --teststage "Unit Tests"
#run the unit tests
npm run test
#upload the Junit XML report
npx slnodejs uploadReports --token $SL_TOKEN --buildsessionid $BUILDSESSIONID --reportFile "path/to/junit.xml"
#upload the coverage report
npx slnodejs nycReport --token $SL_TOKEN --buildsessionid $BUILDSESSIONID --report "path/to/coverage/coverage-final.json"
#end the test stage
npx slnodejs end --token $SL_TOKEN --buildsessionid $BUILDSESSIONID
When working with Unit Tests, we recommend using the Build Session ID instead of a Lab ID. For this reason, the examples above do not include the use of a --labid
parameter