For the complete documentation index, see llms.txt. This page is also available as Markdown.

Unit Tests

Unit tests are captured after scanning but before deployment. The agent opens a test stage, you run your tests with coverage (NYC / Istanbul), and then you upload both the JUnit results and the coverage report.

For unit tests, identify the execution by Build Session ID (--buildSessionIdFile / --buildSessionId) rather than a Lab ID.

Lifecycle

1

Start the test stage

2

Run your unit tests (producing NYC coverage + JUnit XML)

3

Upload JUnit results and the NYC coverage report

4

End the test stage

Commands

npx slnodejs start \
  --tokenFile ./sltoken.txt --buildSessionIdFile buildSessionId \
  --testStage "Unit Tests"

npm test   # runs your tests with nyc, producing coverage-final.json + junit.xml

npx slnodejs uploadReports \
  --tokenFile ./sltoken.txt --buildSessionIdFile buildSessionId \
  --file ./reports/junit.xml

npx slnodejs nycReport \
  --tokenFile ./sltoken.txt --buildSessionIdFile buildSessionId \
  --report ./coverage/coverage-final.json

npx slnodejs end \
  --tokenFile ./sltoken.txt --buildSessionIdFile buildSessionId

Parameters

Parameter
Purpose

--tokenFile / --token

SeaLights authentication

--buildSessionIdFile / --buildSessionId

Build session identifier (preferred over Lab ID for unit tests)

--testStage

Stage name (e.g. "Unit Tests")

--file

Path to the JUnit XML results (uploadReports)

--report

Path to the NYC coverage file, coverage-final.json (nycReport)

--projectRoot

(nycReport, optional) Project root directory — see note below

--projectRoot for nycReport:

NYC embeds absolute file paths in coverage-final.json. In most local environments these paths already resolve correctly. In CI/Docker environments — where the workspace path may differ from where the code was built — SeaLights may fail to match coverage data to source files.

If that happens, add --projectRoot <path> (e.g. --projectRoot ./ or --projectRoot $(pwd)) so the agent can normalize the paths in the report.

Framework-specific guides

The exact way to produce coverage-final.json and junit.xml depends on your runner:


Back to → Capturing Tests

Last updated

Was this helpful?