New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cypress-multi-reporters

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-multi-reporters - npm Package Compare versions

Comparing version 2.0.1 to 2.0.3

CHANGELOG.md

5

index.js

@@ -1,4 +0,5 @@

/* global require, module */
var MultiReporters = require('./lib/MultiReporters');
'use strict';
const MultiReporters = require('./lib/MultiReporters');
module.exports = MultiReporters;

132

lib/MultiReporters.js

@@ -1,4 +0,4 @@

/* global require, module, console */
'use strict';
var _ = {
const _ = {
get: require('lodash/get'),

@@ -10,19 +10,48 @@ camelCase: require('lodash/camelCase'),

};
var debug = require('debug')('mocha:reporters:MultiReporters');
var fs = require('fs');
var util = require('util')
var mocha = require('mocha');
var Base = mocha.reporters.Base;
var createStatsCollector = require('mocha/lib/stats-collector');
var path = require('path');
const debug = require('debug')('mocha:reporters:MultiReporters');
const fs = require('fs');
const util = require('util');
const mocha = require('mocha');
const {Base} = mocha.reporters;
const path = require('path');
let createStatsCollector;
let mocha6plus;
try {
const json = JSON.parse(
fs.readFileSync(`${path.dirname(require.resolve('mocha')) }/package.json`, 'utf8')
);
const {version} = json;
// istanbul ignore else
if (version >= '6') {
createStatsCollector = require('mocha/lib/stats-collector');
mocha6plus = true;
}
else {
mocha6plus = false;
}
}
// eslint-disable-next-line no-unused-vars
catch (e) {
// istanbul ignore next
console.warn('Couldn\'t determine Mocha version');
}
function MultiReporters(runner, options) {
createStatsCollector(runner);
// istanbul ignore else
if (mocha6plus) {
createStatsCollector(runner);
}
Base.call(this, runner);
if (_.get(options, 'execute', true)) {
options = this.getOptions(options);
this._reporters = _.get(options, 'reporterEnabled', 'tap').split(',').map(
let enabledReporters = _.get(options, 'reporterEnabled', 'tap');
if (!Array.isArray(enabledReporters)) {
enabledReporters = enabledReporters.split(',');
}
this._reporters = enabledReporters.map(
function processReporterEnabled(name, index) {

@@ -33,3 +62,3 @@ debug(name, index);

var reporterOptions = this.getReporterOptions(options, name);
const reporterOptions = this.getReporterOptions(options, name);

@@ -40,3 +69,3 @@ //

//
var Reporter = _.get(mocha, ['reporters', name], null);
let Reporter = _.get(mocha, ['reporters', name], null);

@@ -58,8 +87,8 @@ //

catch (_err) {
_err.message.indexOf('Cannot find module') !== -1 ? console.warn('"' + name + '" reporter not found')
: console.warn('"' + name + '" reporter blew up with error:\n' + _err.stack);
_err.message.indexOf('Cannot find module') !== -1 ? console.warn(`"${ name }" reporter not found`)
: console.warn(`"${ name }" reporter blew up with error:\n${ _err.stack}`);
}
}
else {
console.warn('"' + name + '" reporter blew up with error:\n' + err.stack);
console.warn(`"${ name }" reporter blew up with error:\n${ err.stack}`);
}

@@ -72,3 +101,4 @@ }

runner, {
reporterOptions: reporterOptions
reporterOptions,
reporterOption: reporterOptions
}

@@ -78,5 +108,6 @@ );

else {
console.error('Reporter does not found!', name);
console.error('Reporter not found!', name);
}
}.bind(this)
},
this
);

@@ -91,3 +122,3 @@ }

MultiReporters.prototype.done = function (failures, fn) {
var numberOfReporters = _.size(this._reporters);
const numberOfReporters = _.size(this._reporters);

@@ -99,7 +130,7 @@ if (numberOfReporters === 0) {

var reportersWithDoneHandler = this._reporters.filter(function (reporter) {
return typeof reporter.done === 'function';
const reportersWithDoneHandler = this._reporters.filter(function (reporter) {
return reporter && (typeof reporter.done === 'function');
});
var numberOfReportersWithDoneHandler = _.size(reportersWithDoneHandler);
const numberOfReportersWithDoneHandler = _.size(reportersWithDoneHandler);

@@ -110,3 +141,3 @@ if (numberOfReportersWithDoneHandler === 0) {

var done = _.after(numberOfReportersWithDoneHandler, function() {
const done = _.after(numberOfReportersWithDoneHandler, function() {
fn(failures);

@@ -122,3 +153,6 @@ });

debug('options', options);
var resultantOptions = _.merge({}, this.getDefaultOptions(), this.getCustomOptions(options));
const cmrOutput = _.get(options, 'reporterOptions.cmrOutput');
const resultantOptions = _.merge({}, this.getDefaultOptions(), this.getCustomOptions(options), cmrOutput ? {cmrOutput} : null);
debug('options file (resultant)', resultantOptions);

@@ -129,6 +163,6 @@ return resultantOptions;

MultiReporters.prototype.getCustomOptions = function (options) {
var customOptionsFile = _.get(options, 'reporterOptions.configFile');
let customOptionsFile = _.get(options, 'reporterOptions.configFile');
debug('options file (custom)', customOptionsFile);
var customOptions;
let customOptions;
if (customOptionsFile) {

@@ -139,10 +173,10 @@ customOptionsFile = path.resolve(customOptionsFile);

try {
if ('.js' === path.extname(customOptionsFile)) {
customOptions = require(customOptionsFile);
}
else {
customOptions = JSON.parse(fs.readFileSync(customOptionsFile).toString());
}
if ('.js' === path.extname(customOptionsFile)) {
customOptions = require(customOptionsFile);
}
else {
customOptions = JSON.parse(fs.readFileSync(customOptionsFile).toString().trim());
}
debug('options (custom)', customOptions);
debug('options (custom)', customOptions);
}

@@ -155,3 +189,3 @@ catch (e) {

else {
customOptions = _.get(options, "reporterOptions");
customOptions = _.get(options, 'reporterOptions');
}

@@ -163,6 +197,6 @@

MultiReporters.prototype.getDefaultOptions = function () {
var defaultOptionsFile = require.resolve(MultiReporters.CONFIG_FILE);
const defaultOptionsFile = require.resolve(MultiReporters.CONFIG_FILE);
debug('options file (default)', defaultOptionsFile);
var defaultOptions = fs.readFileSync(defaultOptionsFile).toString();
let defaultOptions = fs.readFileSync(defaultOptionsFile).toString();
debug('options (default)', defaultOptions);

@@ -182,13 +216,27 @@

MultiReporters.prototype.getReporterOptions = function (options, name) {
var _name = name;
var commonReporterOptions = _.get(options, 'reporterOptions', {});
const _name = name;
const commonReporterOptions = _.get(options, 'reporterOptions', {});
debug('reporter options (common)', _name, commonReporterOptions);
name = [_.camelCase(name), 'ReporterOptions'].join('');
var customReporterOptions = _.get(options, [name], {});
const customReporterOptions = _.get(options, [name], {});
debug('reporter options (custom)', _name, customReporterOptions);
var resultantReporterOptions = _.merge({}, commonReporterOptions, customReporterOptions);
const resultantReporterOptions = _.merge({}, commonReporterOptions, customReporterOptions);
debug('reporter options (resultant)', _name, resultantReporterOptions);
let cmrOutput = _.get(options, 'cmrOutput');
if (cmrOutput) {
if (!Array.isArray(cmrOutput)) {
cmrOutput = cmrOutput.split(':').map((cmrOutputReporter) => {
return cmrOutputReporter.split('+');
});
}
cmrOutput.forEach(([targetName, prop, output]) => {
if (resultantReporterOptions[prop] && _name === targetName) {
resultantReporterOptions[prop] = resultantReporterOptions[prop].replace(/\{id\}/gu, output);
}
});
}
return resultantReporterOptions;

@@ -195,0 +243,0 @@ };

{
"name": "cypress-multi-reporters",
"version": "2.0.1",
"version": "2.0.3",
"description": "Generate multiple mocha reports in a single mocha execution.",
"main": "index.js",
"nyc": {
"reporter": [
"html",
"text"
]
},
"scripts": {
"devtest": "jenkins-mocha --no-coverage --timeout 5000 tests/**/*.test.js*",
"lint": "eslint --ext .js .",
"test": "JENKINS_MOCHA_COVERAGE=true jenkins-mocha --timeout 5000 tests/**/*.test.js*"
"devtest": "nyc mocha --require node_modules/chai/register-expect.js --no-coverage --timeout 5000 tests/**/*.test.js*",
"lint": "eslint .",
"test": "nyc mocha --require node_modules/chai/register-expect.js --timeout 5000 tests/**/*.test.js*",
"deploy:prepare": "./scripts/create_npmrc_file.sh",
"release": "standard-version",
"release:trigger": "./scripts/trigger-release.sh"
},
"author": "Stanley Ng <stanleyhlng77-dev@yahoo.com.hk",
"contributors": [
"Yousaf Nabi <yousafn@gmail.com>",
"Brett Zamir"
],
"repository": {
"type": "git",
"url": "https://github.com/you54f/mocha6-multi-reporters"
"url": "https://github.com/you54f/cypress-multi-reporters"
},
"engines": {
"node": ">=6.0.0"
},
"bugs": "https://github.com/you54f/cypress-multi-reporters/issues",
"homepage": "https://github.com/you54f/cypress-multi-reporters",
"license": "MIT",
"dependencies": {
"debug": "^3.1.0",
"lodash": "^4.16.4"
"debug": "^4.3.7",
"lodash": "^4.17.21"
},
"devDependencies": {
"chai": "^3.5.0",
"coveralls": "^2.11.14",
"eslint": "^3.9.0",
"eslint-config-defaults": "^9.0.0",
"jenkins-mocha": "^2.6.0",
"mocha": "^6.0.0",
"mocha-lcov-reporter": "^1.2.0",
"pre-commit": "^1.1.3",
"root-require": "^0.3.1",
"sinon": "^1.17.6"
"@commitlint/cli": "19.5.0",
"@commitlint/config-conventional": "19.5.0",
"chai": "5.1.2",
"coveralls": "3.1.1",
"eslint": "9.13.0",
"eslint-config-defaults": "9.0.0",
"husky": "9.1.6",
"mocha": "8.4.0",
"mocha-lcov-reporter": "1.3.0",
"nyc": "17.1.0",
"sinon": "19.0.2",
"standard-version": "9.5.0"
},
"peerDependencies": {
"mocha": ">=3.1.2"
},
"keywords": [

@@ -37,9 +60,12 @@ "mocha",

],
"pre-commit": [
"lint",
"test"
],
"eslintConfig": {
"extends": "defaults"
},
"husky": {
"hooks": {
"lint": "lint",
"test": "test",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}

@@ -1,17 +0,17 @@

mocha-multi-reporters
===
## cypress-multi-reporters
Generate multiple mocha reports in a single mocha execution.
[![npm version](https://img.shields.io/npm/v/mocha-multi-reporters.svg?style=flat-square)](https://www.npmjs.com/package/mocha-multi-reporters)
[![StyleCI](https://styleci.io/repos/48823069/shield)](https://styleci.io/repos/48823069)
[![Build Status](https://travis-ci.org/stanleyhlng/mocha-multi-reporters.svg)](https://travis-ci.org/stanleyhlng/mocha-multi-reporters)
[![Coverage Status](https://coveralls.io/repos/stanleyhlng/mocha-multi-reporters/badge.svg?branch=master&service=github)](https://coveralls.io/github/stanleyhlng/mocha-multi-reporters?branch=master)
[![Dependency Status](https://img.shields.io/david/stanleyhlng/mocha-multi-reporters.svg?style=flat-square)](https://david-dm.org/stanleyhlng/mocha-multi-reporters)
[![devDependency Status](https://img.shields.io/david/dev/stanleyhlng/mocha-multi-reporters.svg?style=flat-square)](https://david-dm.org/stanleyhlng/mocha-multi-reporters#info=devDependencies)
![npm version](https://img.shields.io/npm/v/cypress-multi-reporters.svg)
![npm](https://img.shields.io/npm/dm/cypress-multi-reporters.svg)
[![Build Status](https://travis-ci.org/you54f/cypress-multi-reporters.svg)](https://travis-ci.org/you54f/cypress-multi-reporters)
[![Coverage Status](https://coveralls.io/repos/YOU54F/cypress-multi-reporters/badge.svg?branch=master&service=github)](https://coveralls.io/github/YOU54F/cypress-multi-reporters?branch=master)
[![Dependency Status](https://img.shields.io/david/you54f/cypress-multi-reporters.svg?style=flat-square)](https://david-dm.org/you54f/cypress-multi-reporters)
[![devDependency Status](https://img.shields.io/david/dev/you54f/cypress-multi-reporters.svg?style=flat-square)](https://david-dm.org/you54f/cypress-multi-reporters#info=devDependencies)
## Install
```
npm install mocha-multi-reporters --save-dev
npm install cypress-multi-reporters --save-dev
```

@@ -27,3 +27,3 @@

```bash
$ ./node_modules/.bin/mocha --reporter mocha-multi-reporters
$ ./node_modules/.bin/mocha --reporter cypress-multi-reporters
mocha-test #1

@@ -49,4 +49,68 @@ ✓ sample test #1.1

### Advanced
### Configuring reporters
Set the reporters configuration using `--reporter-options configFile=config.json`.
- Include reporters in `reporterEnabled` as a comma-delimited list
```js
{
"reporterEnabled": "spec, @my-org/custom"
}
```
- Specify each reporter's configuration using its camel-cased name, followed by `reporterOptions`, as key.
> For scoped reporters such as example @myorg/custom, remove all special characters.
```js
{
"reporterEnabled": "spec, @my-org/custom",
"myOrgCustomReporterOptions": {
// [...]
}
}
```
- You can also use a `.js` file to use Javascript logic to configure the reporters.
Ex:
```js
// Set the reporters configuration using `--reporter-options configFile=reporterConfig.js`.
// In reporterConfig.js
const locale = process.env.SITE_LOCALE;
module.exports = {
"reporterEnabled": "mochawesome, mocha-junit-reporter",
"mochawesomeReporterOptions": {
"reportDir": `.reports/${locale}`
},
"mochaJunitReporterReporterOptions": {
"mochaFile": `./junit/${locale}/[hash].xml`
};
```
This is useful, for example, if you need to run CI jobs on multiple sites using a script like:
```bash
#!/bin/bash
# By default run on all sites but you can pass paramenters to run on other sites
args="$@"
allsites="US UK AU"
sites=${args:-$allsites}
echo "Will run on $sites"
success=0
for site in $sites
do
echo "Running on $site"
export SITE_LOCALE="$site"
npx cypress run --reporter-options configFile=reporterConfig.js
ret_code=$?
if [ $ret_code -ne 0 ]; then
echo "Run for $site - Exited with an ERROR: $ret_code"
success=$ret_code
fi
done
echo "All sites finished running. Exiting with $success"
exit $success
```
#### Examples:
* Generate `spec` and `json` reports.

@@ -62,3 +126,3 @@

```bash
$ ./node_modules/.bin/mocha --reporter mocha-multi-reporters --reporter-options configFile=config.json
$ ./node_modules/.bin/mocha --reporter cypress-multi-reporters --reporter-options configFile=config.json
mocha-test #1

@@ -155,3 +219,3 @@ ✓ sample test #1.1

```bash
$ ./node_modules/.bin/mocha --reporter mocha-multi-reporters --reporter-options configFile=config.json
$ ./node_modules/.bin/mocha --reporter cypress-multi-reporters --reporter-options configFile=config.json

@@ -193,3 +257,3 @@ 1..4

```bash
$ ./node_modules/.bin/mocha --reporter mocha-multi-reporters --reporter-options configFile=config.json
$ ./node_modules/.bin/mocha --reporter cypress-multi-reporters --reporter-options configFile=config.json

@@ -223,9 +287,36 @@ 1..4

* When calling Mocha programmatically
### `cmrOutput` option
Note that when Mocha is called programmatically, it is passed an options object when created. This object is usually derived from a config file that your mocha test runner reads prior to instantiation. This is the object that must contain a key `reporter` with a value of `mocha-multi-reporters` for this plugin to be used. You can also pass the key `reporterOptions` with a value of any of the above listed config files (including the `reporterEnabled` subkey and any other plugin configuration information.) This removes the requirement to have an intermediate configuration file specifically for the multireporter configuration.
This option lets you dynamically replace the output files of reporter options.
In your Mocha `--reporterOptions`, specify `cmrOutput` with a plug-sign-separated
list of the reporter name, the property on that reporter's options to have replaced, and the dynamic ID you would like substituted. If you need multiple reporters
to have dynamic output, add additional plus-sign-separated lists separated by colons.
```sh
mocha --reporter cypress-multi-reporters --reporterOptions configFile=cypress-multi-reporters.json,cmrOutput=@mochajs/json-file-reporter+output+specialID tests
```
```js
var mocha = new Mocha({
reporter: "mocha-multi-reporters",
// cypress-multi-reporters.json
{
"mochajsJsonFileReporterReporterOptions": {
"output": "tests/results/file-{id}.json"
},
"reporterEnabled": "spec, @mochajs/json-file-reporter"
}
```
This will produce an `output` for `@mochajs/json-file-reporter`
`reporterOptions` with the value:
> tests/results/file-specialID.json
### Programmatic
Note that when Mocha is called programmatically, it is passed an options object when created. This object is usually derived from a config file that your mocha test runner reads prior to instantiation. This is the object that must contain a key `reporter` with a value of `cypress-multi-reporters` for this plugin to be used. You can also pass the key `reporterOptions` with a value of any of the above listed config files (including the `reporterEnabled` subkey and any other plugin configuration information.) This removes the requirement to have an intermediate configuration file specifically for the multireporter configuration.
```js
const mocha = new Mocha({
reporter: "cypress-multi-reporters",
timeout: config.testTimeout || 60000,

@@ -250,2 +341,3 @@ slow: config.slow || 10000,

Copyright(c) 2019 Yousaf Nabi
Copyright(c) 2017 Stanley Ng

@@ -252,0 +344,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc