← All install guides

Agent-friendly version of this page: /install/mocha.md

Installing TestGlance for Mocha

1. Make tests emit JUnit XML

Install the JUnit reporter:

npm install --save-dev mocha-junit-reporter
# or: pnpm add -D mocha-junit-reporter
# or: yarn add -D mocha-junit-reporter

Run Mocha with the JUnit reporter in CI. Either pass it on the command line:

mocha --reporter mocha-junit-reporter \
      --reporter-options mochaFile=test-results/mocha.xml

…or configure it in .mocharc.json:

{
  "reporter": "mocha-junit-reporter",
  "reporter-option": ["mochaFile=test-results/mocha.xml"]
}

If you want the spec output AND the JUnit XML at the same time, use mocha-multi-reporters:

npm install --save-dev mocha-multi-reporters
{
  "reporter": "mocha-multi-reporters",
  "reporter-option": ["configFile=mocha-reporter-config.json"]
}
// mocha-reporter-config.json
{
  "reporterEnabled": "spec, mocha-junit-reporter",
  "mochaJunitReporterReporterOptions": {
    "mochaFile": "test-results/mocha.xml"
  }
}

2. Add the TestGlance step to CI

If the project already has a CI workflow that runs the tests, add this step to the test job (after the test step), and merge the permissions: block at the workflow's top level:

permissions:
  contents: read
  pull-requests: write
 
# ...inside the test job, after the test step:
- uses: testglance/action@v1
  if: always()
  with:
    github-token: ${{ github.token }}

If no CI workflow runs the tests yet, create .github/workflows/testglance.yml that runs the project's tests and then runs the TestGlance step.

if: always() matters — TestGlance should still run when tests fail. TestGlance auto-discovers anything matching **/test-results/*.xml, so no report-path is needed when reports land under test-results/.

3. Confirm with the user before committing

Summarize the diff and ask the user to confirm before staging or committing. Do not push.