- ๐งช 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
- ๐ 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
.
- ๐ 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 }}
- ๐ See your test results in Captain!
Take a look at the final workflow!