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

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

The question should be specific, self-contained, and written in natural language.
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.
