Gathering detailed insights and metrics for mochawesome
Gathering detailed insights and metrics for mochawesome
Gathering detailed insights and metrics for mochawesome
Gathering detailed insights and metrics for mochawesome
mochawesome-merge
Merge several Mochawesome JSON reports
mochawesome-report-generator
Generates gorgeous HTML reports from mochawesome reporter.
@types/mochawesome
TypeScript definitions for mochawesome
cypress-mochawesome-reporter
Zero config Mochawesome reporter for Cypress with screenshots
npm install mochawesome
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,064 Stars
520 Commits
160 Forks
24 Watching
8 Branches
12 Contributors
Updated on 21 Nov 2024
Minified
Minified + Gzipped
JavaScript (98.64%)
HTML (1.3%)
Shell (0.06%)
Cumulative downloads
Total Downloads
Last day
-5.5%
243,366
Compared to previous day
Last week
2.6%
1,360,606
Compared to previous week
Last month
5.6%
5,688,046
Compared to previous month
Last year
19.5%
63,267,614
Compared to previous year
Mochawesome is a custom reporter for use with the Javascript testing framework, mocha. It runs on Node.js (>=10) and works in conjunction with mochawesome-report-generator to generate a standalone HTML/CSS report to help visualize your test runs.
parallel
modenpm install --save-dev mochawesome
mocha testfile.js --reporter mochawesome
1var mocha = new Mocha({
2 reporter: 'mochawesome',
3});
Since mocha@8
test files can be run in parallel using the --parallel
flag. In order for mochawesome to work properly it needs to be registered as a hook.
mocha tests --reporter mochawesome --require mochawesome/register
Mochawesome generates the following inside your project directory:
mochawesome-report/
├── assets
│  ├── app.css
│  ├── app.js
│  ├── MaterialIcons-Regular.woff
│  ├── MaterialIcons-Regular.woff2
│  ├── roboto-light-webfont.woff
│  ├── roboto-light-webfont.woff2
│  ├── roboto-medium-webfont.woff
│  ├── roboto-medium-webfont.woff2
│  ├── roboto-regular-webfont.woff
│  └── roboto-regular-webfont.woff2
├── mochawesome.html
└── mochawesome.json
The two main files to be aware of are:
mochawesome.html - The rendered report file
mochawesome.json - The raw json output used to render the report
Options can be passed to the reporter in two ways.
The reporter will try to read environment variables that begin with MOCHAWESOME_
.
1$ export MOCHAWESOME_REPORTFILENAME=customReportFilename
Note that environment variables must be in uppercase.
You can pass comma-separated options to the reporter via mocha's --reporter-options
flag. Options passed this way will take precedence over environment variables.
1$ mocha test.js --reporter mochawesome --reporter-options reportDir=customReportDir,reportFilename=customReportFilename
Alternately, reporter-options
can be passed in programatically:
1var mocha = new Mocha({
2 reporter: 'mochawesome',
3 reporterOptions: {
4 reportFilename: 'customReportFilename',
5 quiet: true,
6 },
7});
The options below are specific to the reporter. For a list of all available options see mochawesome-report-generator options.
Option Name | Type | Default | Description |
---|---|---|---|
quiet | boolean | false | Silence console messages |
reportFilename | string | mochawesome | Filename of saved report (html and json) See notes for available token replacements. |
html | boolean | true | Save the HTML output for the test run |
json | boolean | true | Save the JSON output for the test run |
consoleReporter | string | spec | Name of mocha reporter to use for console output, or none to disable console report output entirely |
Using the following tokens it is possible to dynamically alter the filename of the generated report.
timestamp
option.For example, given the spec cypress/integration/sample.spec.js
and the following config:
{
reporter: "mochawesome",
reporterOptions: {
reportFilename: "[status]_[datetime]-[name]-report",
timestamp: "longDate"
}
}
The resulting report file will be named pass_February_23_2022-sample-report.html
Note: The [name]
replacement only occurs when mocha is running one spec file per process and outputting a separate report for each spec. The most common use-case is with Cypress.
Mochawesome ships with an addContext
helper method that can be used to associate additional information with a test. This information will then be displayed inside the report.
Please note: arrow functions will not work with addContext
. See the example.
addContext(testObj, context)
param | type | description |
---|---|---|
testObj | object | The test object |
context | string|object | The context to be added to the test |
Context as a string
Simple strings will be displayed as is. If you pass a URL, the reporter will attempt to turn it into a link. If the URL links to an image or video, it will be shown inline.
Context as an object
Context passed as an object must adhere to the following shape:
1{ 2 title: 'some title'; // must be a string 3 value: { 4 } // can be anything 5}
Be sure to use ES5 functions and not ES6 arrow functions when using addContext
to ensure this
references the test object.
1const addContext = require('mochawesome/addContext');
2
3describe('test suite', function () {
4 it('should add context', function () {
5 // context can be a simple string
6 addContext(this, 'simple string');
7
8 // context can be a url and the report will create a link
9 addContext(this, 'http://www.url.com/pathname');
10
11 // context can be an image url and the report will show it inline
12 addContext(this, 'http://www.url.com/screenshot-maybe.jpg');
13
14 // context can be an object with title and value properties
15 addContext(this, {
16 title: 'expected output',
17 value: {
18 a: 1,
19 b: '2',
20 c: 'd',
21 },
22 });
23 });
24});
It is also possible to use addContext
from within a beforeEach
or afterEach
test hook.
1describe('test suite', () => {
2 beforeEach(function () {
3 addContext(this, 'some context');
4 });
5
6 afterEach(function () {
7 addContext(this, {
8 title: 'afterEach context',
9 value: { a: 1 },
10 });
11 });
12
13 it('should display with beforeEach and afterEach context', () => {
14 // assert something
15 });
16});
This project does not maintain its own type definitions, however they are available on npm from DefinitelyTyped.
$ npm install --save-dev @types/mochawesome
mochawesome is MIT licensed.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
Found 2/22 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
18 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More