> 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/supported-test-frameworks/ava-framework.md).

# AVA framework

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

See '[Generating an Agent token](https://docs.sealights.io/knowledgebase/settings/token-access-and-management#token-list-and-token-creation-2)' for instructions on how to generate a token

## Starting the Test Listener <a href="#starting-the-test-listener" id="starting-the-test-listener"></a>

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

{% tabs %}
{% tab title="Bash" %}
{% code overflow="wrap" lineNumbers="true" %}

```
npx slnodejs start --tokenFile /path/to/sltoken.txt --buildSessionIdFile buildSessionId --testStage "Unit Tests"
```

{% endcode %}
{% endtab %}

{% tab title="PowerShell" %}
{% code overflow="wrap" lineNumbers="true" %}

```
call npx slnodejs start --tokenFile \path\to\sltoken.txt --buildSessionIdFile buildSessionId --testStage "Unit Tests"
```

{% endcode %}
{% endtab %}
{% endtabs %}

## 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 [Backend Server Application](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/node.js-agent/legacy-commands-deprecated/backend-server-application.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>

In order to report the test and coverage information to SeaLights you need to run AVA while producing coverage information and a junit results file.

* For the junit results file, you can use the **--tap** option of AVA and pipe it into the **tap-xunit** converter, then finaly redirect this into a junit.xml file. See <https://www.npmjs.com/package/tap-xunit> for details.
* For the coverage you need to run AVA with **nyc** and the **--reporter=json** option.

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

### Coverage files <a href="#coverage-files" id="coverage-files"></a>

Once done running the unit tests you upload the coverage report files to the SeaLights server using the **nycReport** option

{% tabs %}
{% tab title="Bash" %}
{% code overflow="wrap" lineNumbers="true" %}

```bash
npx slnodejs nycReport --tokenFile /path/to/sltoken.txt --buildSessionIdFile buildSessionId
```

{% endcode %}
{% endtab %}

{% tab title="PowerShell" %}
{% code overflow="wrap" lineNumbers="true" %}

```powershell
call npx slnodejs nycReport --tokenFile \path\to\sltoken.txt --buildSessionIdFile buildSessionId 
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Test results files <a href="#test-results-files" id="test-results-files"></a>

Once done running the tests you upload the test results file to the SeaLights server using the **uploadReports** option

{% tabs %}
{% tab title="Bash" %}
{% code overflow="wrap" lineNumbers="true" %}

```bash
npx slnodejs uploadReports --tokenFile /path/to/sltoken.txt --buildSessionIdFile buildSessionId --file junit.xml
```

{% endcode %}
{% endtab %}

{% tab title="PowerShell" %}
{% code overflow="wrap" lineNumbers="true" %}

```powershell
call npx slnodejs uploadReports --tokenFile \path\to\sltoken.txt --buildSessionIdFile buildSessionId --file junit.xml
```

{% endcode %}
{% endtab %}
{% endtabs %}

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

{% tabs %}
{% tab title="Bash" %}
{% code overflow="wrap" lineNumbers="true" %}

```bash
npx slnodejs end --tokenFile /path/to/sltoken.txt --buildSessionIdFile buildSessionId
```

{% endcode %}
{% endtab %}

{% tab title="PowerShell" %}
{% code overflow="wrap" lineNumbers="true" %}

```powershell
call npx slnodejs end  --tokenFile \path\to\sltoken.txt --buildSessionIdFile buildSessionId 
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Sample <a href="#sample" id="sample"></a>

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

```sh
#Install the project dependancies
npm install

# Install nyc and the tap-xunit converter
npm install nyc
npm install tap-xunit

# Install the SeaLights agents
npm i slnodejs

# Scan the source files to provide SeaLights the structure of the project
npx slnodejs scan --tokenFile sltoken.txt --buildSessionIdFile buildSessionId.txt --scanDir "src" --scmType git --es6Modules

# Notify SeaLights the Unit Tests are starting
npx slnodejs start --tokenFile sltoken.txt --buildSessionIdFile buildSessionId.txt --testStage "Unit Tests"

#Run the unit tests with nyc and creating the junit.xml report file
ENV=test npx nyc --reporter=json ./node_modules/.bin/ava --tap | ./node_modules/.bin/tap-xunit > junit.xml

# Upload the coverage and tests results to SeaLights
npx slnodejs nycReport --tokenFile sltoken.txt --buildSessionIdFile buildSessionId.txt 
npx slnodejs uploadReports --tokenFile sltoken.txt --buildSessionIdFile buildSessionId.txt --file junit.xml

# Notify SeaLights the Unit Tests have finished
npx slnodejs end --tokenFile sltoken.txt --buildSessionIdFile buildSessionId.txt
```

{% endcode %}


---

# 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/supported-test-frameworks/ava-framework.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.
