/mocha

How to integrate Captain with Mocha

Primary LanguageJavaScript

Getting Captain working with Mocha

  1. ๐Ÿงช Ensure Mocha produces JSON output

By default, Mocha can produce JSON output with npx mocha "test-pattern" -R json --reporter-option output=report.json, but it will squash the default spec reporter. To use multiple reporters with Mocha, you need to install a library. Once installed, create a config file at multi-reporters.json containing:

{
  "reporterEnabled": "spec,json",
  "jsonReporterOptions": {
    "output": "tmp/report.json"
  }
}

Then, you can use both the spec and json reporters with this command:

npx mocha "test-pattern" -R @rwx-research/mocha-multi-reporters --reporter-options configFile=multi-reporters.json
  1. ๐Ÿ” Create an Access Token

Create an Access Token for your organization within Captain (more documentation here).

Add the new token as an action secret to your repository. Conventionally, we call this secret RWX_ACCESS_TOKEN.

  1. ๐Ÿ’Œ Install the Captain CLI, and then call it when running tests

See the full documentation on test suite integration.

  - name: Run tests
    run: |
      captain run --suite-id captain-examples-mocha --test-results tmp/report.json -- \
        npm test
    env:
      RWX_ACCESS_TOKEN: ${{ secrets.RWX_ACCESS_TOKEN }}
  1. ๐ŸŽ‰ See your test results in Captain!

Take a look at the final workflow!