# Running Tests

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

There are 4 basic steps to gathering coverage and test information using the SeaLights Node.js Agent (`slnodejs`).

1. Start the test stage with `slnodejs start ...`
2. Run the Tests
3. Upload Test Reports
4. End the test stage with `slnodejs end...`

Use the Lab ID to connect the test listener to the application under test. For Unit Tests, see [Unit Tests](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/running-tests/unit-tests.md).

## Starting the Test Stage <a href="#starting-the-test-stage" id="starting-the-test-stage"></a>

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

```sh
// Unix: 
npx slnodejs start --tokenfile /path/to/sltoken.txt --labid "<Lab ID>" --teststage "Functional Tests" 

// Windows: 
call npx slnodejs start --tokenfile \path\to\sltoken.txt --labid "<Lab ID>" --teststage "Functional Tests"
```

{% hint style="info" %}
See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/command-reference.md#starting-a-test-stage) for full parameter details
{% endhint %}

## Running your tests <a href="#running-your-tests" id="running-your-tests"></a>

### Functional Tests <a href="#functional-tests" id="functional-tests"></a>

Before running your functional tests you need to set up the backend server to receive the test footprints. See [Running Backend Server](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/backend-server-application/running-backend-server.md)

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.

### Unit Tests <a href="#unit-tests" id="unit-tests"></a>

As the Unit Tests are not run against a backend server, you need to run the actual tests using the Sealights Node.js Agent while generating one or more JUnit XML result files to be reported to the SeaLights server. Note that both Junit and Coverage reports must be uploaded for SeaLights to reflect data for your Unit Tests.

For clarification, see: [Unit Tests](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/running-tests/unit-tests.md)

## Upload report files <a href="#upload-report-files" id="upload-report-files"></a>

### Test Case JUnit Report <a href="#test-case-junit-report" id="test-case-junit-report"></a>

The `slnodejs uploadReports` command can be used to upload the junit.xml file

```sh
Unix:
npx slnodejs uploadReports --tokenfile /path/to/sltoken.txt --labid "<Lab ID>" --reportFile "/path/to/junit_report.xml"

Windows:
call npx slnodejs uploadReports --tokenfile \path\to\sltoken.txt --labid "<Lab ID>" --reportFile "\path\to\junit_report.xml"
```

{% hint style="info" %}

* See [Uploading Reports - More options](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/advanced-features/uploading-reports-more-options.md#uploading-multiple-files) for information on how to upload multiple files
* See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/command-reference.md#upload-report-files) for full parameter details
  {% endhint %}

### Coverage (nyc) Report <a href="#coverage-nyc-report" id="coverage-nyc-report"></a>

The `slnodejs uploadReports` command can be used to upload the coverage file generated by nyc

```sh
Unix:
npx slnodejs nycReport --token $SL_TOKEN --labid $LABID --report "path/to/coverage/coverage-final.json"

Windows:
call npx slnodejs nycReport --token $SL_TOKEN --labid $LABID --report "\path\to\coverage\coverage-final.json"
```

## Ending the Test Stage <a href="#ending-the-test-stage" id="ending-the-test-stage"></a>

Finally, notify the server that a test stage has ended.

```sh
Unix:
npx slnodejs end --tokenfile /path/to/sltoken.txt --labid "<Lab ID>"

Windows:
call npx slnodejs end --tokenfile \path\to\sltoken.txt --labid "<Lab ID>"
```

{% hint style="info" %}
See [Command Reference](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/command-reference.md#ending-a-test-stage) for full parameter details
{% 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.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.
