# 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](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/running-tests/unit-tests "mention").

## 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 [#starting-a-test-stage](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/command-reference#starting-a-test-stage "mention") 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](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/backend-server-application/running-backend-server "mention")

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](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/running-tests/unit-tests "mention")

## 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-multiple-files](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/advanced-features/uploading-reports-more-options#uploading-multiple-files "mention") for information on how to upload multiple files
* See [#upload-report-files](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/command-reference#upload-report-files "mention") 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 [#ending-a-test-stage](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/command-reference#ending-a-test-stage "mention") for full parameter details
{% endhint %}
