> For the complete documentation index, see [llms.txt](https://docs.sealights.io/knowledgebase/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/legacy-commands-deprecated/running-tests/unit-tests.md).

# Unit Tests

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:

1. Start the test stage with `slnodejs start ...`
2. Run the Unit Tests
3. Upload the Reports
   1. Junit XML report file `slnodejs uploadReports`
   2. Coverage file `slnodejs nycReport`
4. End the test stage with `slnodejs end...`

For example, the whole process might look like:

{% code overflow="wrap" lineNumbers="true" %}

```
#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
```

{% endcode %}

{% hint style="info" %}
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
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/legacy-commands-deprecated/running-tests/unit-tests.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
