A cypress json reporter that does not block the cypress event stream
npm install cypress-json-results-non-blockingshell
$ npm i cypress-json-results-non-blocking
or using Yarn
$ yarn add -D cypress-json-results-non-blocking
`
Use
Register this plugin from your plugin file
`js
// cypress/plugins/index.js
///
const CypressReport = require('cypress-json-results-non-blocking');
let allResults
/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
module.exports = (on, config) => {
const cypressJSONReport = new CypressReport({ on });
on("before:run", (details) => {
cypressJSONReport.beforeRunHandler(details);
});
on("after:spec", (spec, results) => {
cypressJSONReport.afterSpecWithDuration(spec, results);
});
on("after:run", (results) => {
cypressJSONReport.afterRunHandler(results);
});
};
`
output:
`json
{
"results": [
{
"feature": "cypress/integration/spec.js",
"scenario": "works",
"state": "passed",
"duration": 1
},
{
"feature": "cypress/integration/spec.js",
"scenario": "is pending",
"state": "pending",
"duration": 0
}
],
"totals": {
"suites": 2,
"tests": 2,
"failed": 0,
"passed": 1,
"pending": 1,
"skipped": 0
}
}
`
Options
$3
By default, this plugin saves the JSON result into "cypress" file. You can change the output filename using the filename option
`js
...
const cypressJSONReport = new CypressReport({ on, folder: "report" });
...
`
$3
By default, this plugin saves the JSON result into "results.json" file. You can change the output filename using the filename option
`js
...
const cypressJSONReport = new CypressReport({ on, filename: "new-report-name" });
...
`
Note: the plugin assumes the output folder already exists
$3
You can automatically update a Markdown table inside the given file with the test counts. See the section below Cypress test counts for an example. The table should be surrounded with HTML comments
`
Test status | Count
---|---
Passed | 6
Failed | 0
Pending | 1
Skipped | 0
Total | 7
`
Tip: prevent the Prettier from messing with the formatting by surrounding the table with ignore comments, see How to configure Prettier and VSCode.
`
... table text ...
``