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

cypress-mochawesome-reporter

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-mochawesome-reporter - npm Package Compare versions

Comparing version

to
3.8.0

@@ -1,6 +0,5 @@

const path = require('path');
module.exports = {
defaultHtmlOutputFolder: 'cypress/reports/html',
defaultConfigOutput: 'cypress/.tmp/cypressMochawesomeReporterConfig.json',
cucumberStepsContextKey: '__cucumber_source__',
};
const path = require('path');
const fse = require('fs-extra');
const { debugLog, log } = require('./logger');
const { debugLog } = require('./logger');
const consts = require('./consts');
let gherkin;
try {
gherkin = require('@cucumber/gherkin-utils');
} catch {}
function enhanceReport(report, mochawesomeOptions, screenshotsDir) {

@@ -16,2 +22,5 @@ const baseFolder = extrapolateBaseFolder(report.results);

suite.fullFile = fullFile;
suite.tests.forEach((test) => {
setCucumberCode(test);
});
});

@@ -26,2 +35,3 @@ attachMediaToSuiteTestsContext(result.suites, mochawesomeOptions, screenshotsDir, baseFolder);

test.context = attachMediaToTestContext(test.context, mochawesomeOptions, screenshotsDir, baseFolder);
setCucumberCode(test);
});

@@ -151,5 +161,12 @@ }

function convertImageToBase64(screenshotsDir, imagePath) {
const imgPath = path.join(screenshotsDir, imagePath);
const contents = 'data:image/png;base64, ' + fse.readFileSync(imgPath, { encoding: 'base64' });
return contents;
if (fse.pathExistsSync(imagePath)) {
return convertImg(imagePath);
} else {
const imgPath = path.join(screenshotsDir, imagePath);
return convertImg(imgPath);
}
function convertImg(pathToFile) {
return 'data:image/png;base64, ' + fse.readFileSync(pathToFile, { encoding: 'base64' });
}
}

@@ -186,4 +203,36 @@

/**
* if '__cucumber_source__' is found in the context, beautify it an replace the code block
*/
function setCucumberCode(test) {
if (test.context) {
let context = JSON.parse(test.context);
if (!Array.isArray(context)) {
context = [context];
}
// the context can be encountered multiple times if the test is retried
// only use the first occurence but remove of all them from the context
const cucumberFound = context.some(({ title, value }) => {
if (title === consts.cucumberStepsContextKey) {
test.code = beautifyCucumber(value);
return true;
}
});
if (cucumberFound) {
test.context = JSON.stringify(context.filter(({ title }) => title !== consts.cucumberStepsContextKey));
}
}
}
function beautifyCucumber(gherkinDocument) {
if (!gherkin) {
console.error('@cucumber/gherkin-utils is not available');
return 'ERROR: @cucumber/gherkin-utils is not available';
}
return gherkin.pretty(gherkinDocument, 'gherkin');
}
module.exports = {
enhanceReport,
};
{
"name": "cypress-mochawesome-reporter",
"version": "3.7.0",
"version": "3.8.0",
"description": "Zero config Mochawesome reporter for Cypress with screenshots",

@@ -22,3 +22,3 @@ "engines": {

"lerna": "lerna",
"install-examples": "lerna exec --scope @example/* \"npm i\"",
"install-examples": "lerna exec --concurrency 1 --scope @example/* \"npm i\"",
"test:prepare": "lerna run --stream --no-bail --concurrency 1 --scope @example/* test",

@@ -44,2 +44,3 @@ "test": "cypress run",

"devDependencies": {
"@badeball/cypress-cucumber-preprocessor": "^19.2.0",
"cypress": "^13.1.0",

@@ -55,4 +56,5 @@ "lerna": "^7.1.4"

"plugin.js",
"index.d.ts"
"index.d.ts",
"cucumberSupport.js"
]
}

@@ -87,4 +87,12 @@ # cypress-mochawesome-reporter

4. run cypress
4. (optional, if your are using `cypress-cucumber-preprocessor`) Add to `cypress/support/step_definitions/index.js`
```javascript
import 'cypress-mochawesome-reporter/cucumberSupport';
```
> ⚠️ `cypress-cucumber-preprocessor` uses the same hooks as `cypress-mochawesome-reporter`, you also need to install [cypress-on-fix](https://github.com/bahmutov/cypress-on-fix). Full example of using `cypress-mochawesome-reporter` with `cypress-cucumber-preprocessor` can be found [here](examples/cucumber).
5. run cypress
## Custom options

@@ -117,3 +125,3 @@

| name | type | default | description |
|-----------------------| --------- | ------- |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| --------------------- | --------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `embeddedScreenshots` | `boolean` | `false` | Embedded external screenshots into HTML using base64, use with `inlineAssets` option to produce a single HTML file |

@@ -140,2 +148,3 @@ | `ignoreVideos` | `boolean` | `false` | Will not copy videos recorded by Cypress nor show them in the mochawesome report. Requires that Cypress config option `video` is set to `true` for the option to have any effect<br/>Because mochawesome doesn't support context per spec file, each test will have the whole spec file video. More info can be found [here](https://github.com/LironEr/cypress-mochawesome-reporter/issues/43) |

6. [Using `cypress-mochawesome-reporter` with `cypress-parallel`](examples/cypress-parallel)
7. [Using `cypress-mochawesome-reporter` with `cypress-cucumber-preprocessor`](examples/cucumber)

@@ -142,0 +151,0 @@ Run `npm i` in root directory then: