-
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
327 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env node | ||
|
||
const { Command } = require('commander'); | ||
const fse = require('fs-extra'); | ||
const { setSimpleConfig } = require('./lib/config'); | ||
const { log, initDebugLog, debugLog } = require('./lib/logger'); | ||
const generateReport = require('./lib/generateReport'); | ||
const consts = require('./lib/consts'); | ||
const packageJson = require('./package.json'); | ||
|
||
(async () => { | ||
const program = new Command(); | ||
program | ||
.name('generate-mochawesome-report') | ||
.description('CLI merge and generate Cypress Mochawesome report') | ||
.version(packageJson.version) | ||
.option('-c, --config <path>', 'should be the same as "configOutput" reporter option', consts.defaultConfigOutput) | ||
.option('-o, --output <path>', 'report output folder') | ||
.option('--debug', 'print debug logs', false); | ||
|
||
program.parse(); | ||
const options = program.opts(); | ||
|
||
initDebugLog(options.debug === true); | ||
|
||
debugLog(`cwd: ${process.cwd()}`); | ||
|
||
log(`read config from ${options.config}`); | ||
|
||
const config = await fse.readJson(options.config); | ||
debugLog(`config: ${JSON.stringify(config)}`); | ||
|
||
if (options.output) { | ||
debugLog(`override output with: ${options.output}`); | ||
config.outputDir = options.output; | ||
config.reporterOptions.reportDir = options.output; | ||
} | ||
|
||
setSimpleConfig(config); | ||
|
||
log('generate report'); | ||
await generateReport(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
node_modules | ||
cypress/reports | ||
cypress/screenshots | ||
cypress/videos | ||
runner-results | ||
multi-reporter-config.json | ||
.tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Setup with `cypress-parallel` | ||
|
||
1. Follow the steps in the [main README](../../README.md) to setup the reporter. | ||
|
||
1. Change `cypress.config.js` to only use `beforeRunHook`, otherwise the reporter will try to create multiple HTML reporters without all the tests. | ||
|
||
```js | ||
const { defineConfig } = require('cypress'); | ||
const { beforeRunHook } = require('cypress-mochawesome-reporter/lib'); | ||
|
||
module.exports = defineConfig({ | ||
video: true, | ||
retries: 0, | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
on('before:run', async (details) => { | ||
await beforeRunHook(details); | ||
}); | ||
}, | ||
}, | ||
}); | ||
``` | ||
|
||
1. How to run: | ||
|
||
1. Because cypress parallel runs in threads you will need to manually clear the report output folder before run. | ||
|
||
1. Set `cypress-parallel` reporter to `cypress-mochawesome-reporter` | ||
|
||
```sh | ||
cypress-parallel -s cy:run -t 2 -d 'cypress/e2e/**/*.cy.js' -r 'cypress-mochawesome-reporter' -o 'cypressParallel=true'" | ||
``` | ||
1. Create report after test run: | ||
```sh | ||
npx generate-mochawesome-report | ||
``` | ||
Example scripts section in `package.json`: | ||
```json | ||
"scripts": { | ||
"cy:run": "cypress run", | ||
"cy:run:parallel": "cypress-parallel -s cy:run -t 2 -d 'cypress/e2e/**/*.cy.js' -r 'cypress-mochawesome-reporter' -o 'cypressParallel=true'", | ||
"clean": "rimraf cypress/reports", | ||
"generate-report": "generate-mochawesome-report", | ||
"test": "npm run clean && npm run cy:run:parallel || true && npm run generate-report" | ||
}, | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { defineConfig } = require('cypress'); | ||
const { beforeRunHook } = require('cypress-mochawesome-reporter/lib'); | ||
|
||
module.exports = defineConfig({ | ||
video: true, | ||
retries: 0, | ||
e2e: { | ||
setupNodeEvents(on, config) { | ||
on('before:run', async (details) => { | ||
await beforeRunHook(details); | ||
}); | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
it('fail test #tag1', () => { | ||
cy.visit('site/index.html'); | ||
|
||
cy.screenshot('custom-name'); | ||
|
||
cy.get('#todo-list li').should('have.length', 10); | ||
}); | ||
|
||
describe('Test 1 #tag2', () => { | ||
it('default todos exists', () => { | ||
cy.visit('site/index.html'); | ||
|
||
cy.get('#todo-list li').should('have.length', 4); | ||
|
||
cy.screenshot(); | ||
}); | ||
|
||
describe('hierarchy', () => { | ||
it('fail test hierarchy #tag3', () => { | ||
cy.visit('site/index.html'); | ||
|
||
cy.screenshot('custom-name2'); | ||
|
||
cy.get('#todo-list li').should('have.length', 10); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
describe('Test 2', () => { | ||
it('todo exists', () => { | ||
cy.visit('site/index.html'); | ||
|
||
cy.get('#todo-list').should('be.visible'); | ||
}); | ||
|
||
it('add context to mochawesome report', () => { | ||
cy.visit('site/index.html'); | ||
|
||
cy.get('#todo-list > li').then(($liElements) => { | ||
cy.addTestContext(`There were ${$liElements.length.toString()} items found in the todo-list`); | ||
}); | ||
}); | ||
|
||
it.skip('skipped test', () => { | ||
cy.visit('site/index.html'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
describe('Test 3 - fail before hook', () => { | ||
before(() => { | ||
cy.visit('site/index.html'); | ||
|
||
cy.get('#todo-list li').should('have.length', 10); | ||
}); | ||
|
||
it('before hook fail', () => { | ||
cy.visit('site/index.html'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
describe('Test 4 - fail beforeEach hook', () => { | ||
beforeEach(() => { | ||
cy.visit('site/index.html'); | ||
|
||
cy.get('#todo-list li').should('have.length', 10); | ||
}); | ||
|
||
it('beforeEach hook fail 1', () => { | ||
cy.visit('site/index.html'); | ||
}); | ||
|
||
it('beforeEach hook fail 2', () => { | ||
cy.visit('site/index.html'); | ||
}); | ||
}); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// *********************************************************** | ||
// This example support/index.js is processed and | ||
// loaded automatically before your test files. | ||
// | ||
// This is a great place to put global configuration and | ||
// behavior that modifies Cypress. | ||
// | ||
// You can change the location of this file or turn off | ||
// automatically serving support files with the | ||
// 'supportFile' configuration option. | ||
// | ||
// You can read more here: | ||
// https://on.cypress.io/configuration | ||
// *********************************************************** | ||
|
||
// Import commands.js using ES2015 syntax: | ||
import './commands'; | ||
|
||
import 'cypress-mochawesome-reporter/register'; | ||
|
||
// Alternatively you can use CommonJS syntax: | ||
// require('./commands') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "@example/simple", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"cy:run": "cypress run", | ||
"cy:run:parallel": "cypress-parallel -s cy:run -t 2 -d 'cypress/e2e/**/*.cy.js' -r 'cypress-mochawesome-reporter' -o 'cypressParallel=true'", | ||
"clean": "rimraf cypress/reports", | ||
"generate-report": "generate-mochawesome-report", | ||
"test": "npm run clean && npm run cy:run:parallel || true && npm run generate-report" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
"cypress": "^12.3.0", | ||
"cypress-mochawesome-reporter": "../../", | ||
"cypress-parallel": "^0.13.0", | ||
"rimraf": "^5.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<body> | ||
<h1>TODO list</h1> | ||
<ul id="todo-list"> | ||
<li>todo1</li> | ||
<li>todo2</li> | ||
<li>todo3</li> | ||
<li>todo4</li> | ||
</ul> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.