Skip to content

How to integrate Captain with Mocha

Notifications You must be signed in to change notification settings

captain-examples/mocha

Repository files navigation

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!

About

How to integrate Captain with Mocha

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published