Publish and view Mocha test results in Github Actions
Publish and display test results from Mocha directly in the GitHub Actions summary using a single command in your workflow file.
GitHub Actions does not provide a built-in feature for visualizing Mocha test results. If tests fail, you can search through the console output or download and examine the results file — a frustrating process.
The github-actions-ctrf package is perfect for this as it allows you to publish and view test results directly in the Github Action summary of any workflow making it easier to understand your test results.
It’s easy to implement, you don’t need to use a custom action or worry about permissions or tokens, there are no limitations on report size and you can apply to any branch, even publicly forked repositories.
View Mocha test results in Github Actions without a custom action
You don’t need to use a custom action to publish and view GitHub Action test reports, let’s add github-actions-ctrf command to your workflow yaml to demonstrate.
The package uses a CTRF JSON or Common Test Report Format, it’s a standardized JSON test report that is the same structure no matter which test framework you use. With Mocha it’s easy to generate a CTRF report, check out the instructions here
After generating the report, add the following to your workflow yaml, replacing the path argument placeholder with the path of your report:
- name: Publish Test Summary Results
run: npx github-actions-ctrf ctrf/ctrf-report.json
Ensure that your GitHub Actions runner has Node.js installed
Look at the GitHub Actions summary and you will see a pretty neat test report.
If you‘d like to see a real example before taking the plunge yourself, check out the github-actions-ctrf repository actions, click the latest workflow and there you have it, a beautiful test report summary.
Many Ways to View Mocha Test Reports in GitHub Actions
There are many ways you can view Mocha test results reports in GitHub Actions using the github-actions-ctrf package. See the package documentation on GitHub for instructions on generating each one.
Publish and View Mocha Test Summary Reports in Github Actions
With the github-actions-ctrf package you can view a Mocha test report overview in the Github Actions:
Publish and View Detailed Mocha Test Reports in Github Actions
With the github-actions-ctrf package you can publish and view a detailed Mocha test report in the Github Actions:
Publish and View Failed Mocha Test Reports in Github Actions
With the github-actions-ctrf package you can publish and view a detailed Mocha test failure report in the Github Actions:
Find and View Flaky Mocha Test Reports in Github Actions
With the github-actions-ctrf package you can publish and view Mocha flaky test reports in the Github Actions, helping you detect flaky tests:
A Universal JSON Test Report — The Same Test Report With Any Tool
What’s pretty sweet about this package is that it uses a Common Test Report Format (CTRF) report. CTRF is a universal JSON test report schema that provides a standardised format for JSON test reports.
For instance, you might use Playwright for E2E and Mocha for unit testing — but you can generate the same JSON test report with both tools. Here is an overview of the main benefits of CTRF:
Consistency Across Tools: Different testing tools and frameworks often produce reports in varied formats. CTRF ensures a uniform structure, making it easier to understand and compare reports, regardless of the testing tool used.
Language and Framework Agnostic: It provides a universal reporting schema that works seamlessly with any programming language and testing framework.
Facilitates Better Analysis: With a standardised format, programmatically analysing test outcomes across multiple platforms becomes more straightforward — like using the same report to view test results in GitHub Actions Summaries.