> 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/capturing-tests/mocha-tests-framework.md).

# Mocha Tests framework

## Mocha test framework <a href="#mocha-test-framework" id="mocha-test-framework"></a>

SeaLights integrates with **Mocha** through the `slnodejs mocha` wrapper, which runs SeaLights as a Mocha reporter and reports test results to the server.

{% hint style="warning" %}
Remove any existing `--reporter` configuration from your Mocha setup — SeaLights runs as a reporter internally and conflicting reporters can break reporting. To keep other reporters, use the [multiple reporters](https://file+.vscode-resource.vscode-cdn.net/c%3A/Work/Customers/GEVernova/ADO/qTestUpdate/sealights-nodejs-docs/5.2-mocha.md#multiple-reporters) setup below.&#x20;
{% endhint %}

### Basic command <a href="#basic-command" id="basic-command"></a>

Everything after `--` is passed straight to Mocha.

{% tabs %}
{% tab title="Bash" %}

```sh
npx slnodejs mocha \
  --tokenFile ./sltoken.txt \
  --buildSessionIdFile buildSessionId \
  --testStage "Unit Tests" \
  --useSlNode2 \
  -- --recursive test
```

{% endtab %}

{% tab title="GitHub Actions" %}

```yaml
- name: Mocha tests with SeaLights
  env:
    SL_TOKEN: ${{ secrets.SL_TOKEN }}
  run: |
    npx slnodejs mocha \
      --token "$SL_TOKEN" \
      --buildSessionIdFile buildSessionId \
      --testStage "Unit Tests" \
      --useSlNode2 \
      -- --recursive test
```

{% endtab %}

{% tab title="PowerShell" %}

```powershell
npx slnodejs mocha `
  --tokenFile .\sltoken.txt `
  --buildSessionIdFile buildSessionId `
  --testStage "Unit Tests" `
  --useSlNode2 `
  -- --recursive test
```

{% endtab %}

{% tab title="Azure DevOps" %}

```yaml
- script: |
    npx slnodejs mocha \
      --token "$(SL_TOKEN)" \
      --buildSessionIdFile buildSessionId \
      --testStage "Unit Tests" \
      --useSlNode2 \
      -- --recursive test
  displayName: Mocha tests with SeaLights
```

{% endtab %}
{% endtabs %}

Replace `--recursive test` with your actual Mocha arguments.

### Parameters <a href="#parameters" id="parameters"></a>

| Parameter                                   | Purpose                                          |
| ------------------------------------------- | ------------------------------------------------ |
| `--tokenFile` / `--token`                   | SeaLights authentication                         |
| `--buildSessionIdFile` / `--buildSessionId` | Build session identifier                         |
| `--testStage`                               | Stage name (e.g. `"Unit Tests"`)                 |
| `--useSlNode2`                              | Use the v2 Node agent runtime                    |
| `--`                                        | Separates SeaLights options from Mocha arguments |

### Multiple reporters <a href="#multiple-reporters" id="multiple-reporters"></a>

To run SeaLights alongside other reporters (e.g. Allure, JUnit), install `mocha-multi-reporters` and create a `config.json`:

```json
{
    "reporterEnabled": "slnodejs/tsOutputs/mocha-reporter/index, allure-mocha, mocha-junit-reporter",
    "seaLightsReporterReporterOptions": {},
    "mochaJunitReporterReporterOptions": {
        "mochaFile": "results/junit-custom.xml"
    },
    "allureMochaReporterOptions": {
        "resultsDir": "results/allure"
    }
}
```

Then run:

```sh
npx slnodejs mocha \
  --tokenFile ./sltoken.txt --buildSessionIdFile buildSessionId \
  --testStage "Unit Tests" --useSlNode2 \
  -- --reporter-options configFile=config.json
```

### Suite mapping <a href="#suite-mapping" id="suite-mapping"></a>

To map functional tests to Mocha **suites** instead of individual tests:

```sh
npx slnodejs mocha ... -- --reporter-options reportSuites=true
```

***

**Back to →** [Capturing Tests](https://file+.vscode-resource.vscode-cdn.net/c%3A/Work/Customers/GEVernova/ADO/qTestUpdate/sealights-nodejs-docs/capturing-tests.md)


---

# 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/capturing-tests/mocha-tests-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.
