diff --git a/README.md b/README.md index b310f17..09f1823 100644 --- a/README.md +++ b/README.md @@ -114,9 +114,15 @@ This options could be passed: ``` - via `command line`: +as [Cypress environment variables](https://docs.cypress.io/guides/guides/environment-variables#Option-4-env) are used please take into account that cli should have only one argument `--env` or `-e`, otherwise values will not be passed - ```js + ```bash yarn cypress run --env allure=true,allureResultsPath=someFolder/results + + yarn cypress run --env TAGS='@smoke',allure=true + + # for windows: + yarn cypress run --env "TAGS=@smoke","allure=true" ``` - via `Cypress environment variables`: @@ -218,6 +224,7 @@ Allure API available: - label(name: LabelName, value: string) - parameter(name: string, value: string) - testParameter(name: string, value: string) +- testName(name: string) - link(url: string, name?: string, type?: LinkType) - issue(name: string, url: string) - tms(name: string, url: string) diff --git a/cypress/integration/results/steps.test.js b/cypress/integration/results/steps.test.js index 832139b..2596b37 100644 --- a/cypress/integration/results/steps.test.js +++ b/cypress/integration/results/steps.test.js @@ -1,9 +1,6 @@ // TODO prepare tests for chainer parsing before(() => { - Cypress.Cookies.defaults({ - whitelist: 'session' - }); cy.log(`------ SETTING MAGIC NUMBER ----> 42`); cy.setCookie('session', '42'); Cypress.env('session', 42); @@ -13,7 +10,9 @@ describe('Cypress commands steps', () => { it('should produce allure steps for cypress chainer commands', () => { cy.log('before command'); cy.allure().startStep('step before "this is custom"'); - cy.thisiscustom('customname'); + cy.thisiscustom('customname').then(() => { + cy.allure().testName('new name'); + }); cy.allure().endStep(); cy.allure() .startStep('step nested 1') diff --git a/package.json b/package.json index 87fac2b..4d411e5 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "scripts": { "semantic-release": "semantic-release", "test": "yarn cypress run --config integrationFolder=cypress/integration/results,testFiles=**/*.spec.js,video=false", + "test:debug": "yarn cypress open --config integrationFolder=cypress/integration/results,testFiles=**/*.test.js,video=false", "test:prepare:basic": "node cypress/scripts/runner basic", "test:prepare:cucumber": "node cypress/scripts/runner cucumber", "fixtures:clear": "rm -r cypress/fixtures/*", @@ -38,7 +39,7 @@ "dependencies": { "allure-js-commons": "^2.0.0-beta.6", "crypto-js": "3.3.0", - "uuid": "^7.0.2" + "uuid": "8.3.2" }, "devDependencies": { "@types/fs-extra": "^8.1.0", diff --git a/reporter/commands.js b/reporter/commands.js index 356a756..f098276 100644 --- a/reporter/commands.js +++ b/reporter/commands.js @@ -7,6 +7,7 @@ Cypress.Commands.add('allure', () => { const childCommands = { parameter: (allure, name, value) => allure.parameter(name, value), testParameter: (allure, name, value) => allure.testParameter(name, value), + testName: (allure, name) => allure.testName(name), severity: (allure, level) => allure.severity(level), testAttachment: (allure, name, content, type) => allure.testAttachment(name, content, type), diff --git a/reporter/index.d.ts b/reporter/index.d.ts index 4bd3e00..55b44ab 100644 --- a/reporter/index.d.ts +++ b/reporter/index.d.ts @@ -154,6 +154,12 @@ declare global { * Add test case ID from Allure TestOps to link automated test */ testID(id: string): Allure + /** + * Overwrite test name for report. + * Will be applied when results are stored to allure-results folder + * @param name + */ + testName(name: string): Allure /** * Attach environmental info * @param info - format diff --git a/reporter/index.js b/reporter/index.js index d7c932f..0168704 100644 --- a/reporter/index.js +++ b/reporter/index.js @@ -148,3 +148,6 @@ Cypress.Screenshot.defaults({ } } }); + +// need empty after hook to prohibit cypress stop the runner when there are skipped tests in the end +after(() => {}); diff --git a/reporter/mocha-allure/AllureInterface.js b/reporter/mocha-allure/AllureInterface.js index 41779b5..8e6b8b3 100644 --- a/reporter/mocha-allure/AllureInterface.js +++ b/reporter/mocha-allure/AllureInterface.js @@ -89,6 +89,10 @@ Allure.prototype.testParameter = function (name, value) { this.reporter.currentTest.addParameter(name, value); }; +Allure.prototype.testName = function (name) { + this.reporter.currentTest.addParameter('OverwriteTestName', name); +}; + Allure.prototype.label = function (name, value) { if (this.reporter.currentTest) { const labelIndex = (name) => diff --git a/reporter/mocha-allure/AllureReporter.js b/reporter/mocha-allure/AllureReporter.js index 39a9a2d..3f46cf8 100644 --- a/reporter/mocha-allure/AllureReporter.js +++ b/reporter/mocha-allure/AllureReporter.js @@ -346,7 +346,7 @@ module.exports = class AllureReporter { } startHook(hook) { - if (!this.currentSuite) { + if (!this.currentSuite || isEmpty(hook)) { return; } /** @@ -367,7 +367,7 @@ module.exports = class AllureReporter { } endHook(hook, failed = false) { - if (!this.currentSuite) { + if (!this.currentSuite || isEmpty(hook)) { return; } // should define results property for all or each hook @@ -730,3 +730,5 @@ module.exports = class AllureReporter { return executable.startStep(message()); } }; + +const isEmpty = (hook) => hook && hook.body === 'function () {}'; diff --git a/reporter/stubbedAllure.js b/reporter/stubbedAllure.js index 00aead2..f3be772 100644 --- a/reporter/stubbedAllure.js +++ b/reporter/stubbedAllure.js @@ -40,5 +40,6 @@ const stubbedAllure = { stepEnd: () => {}, endStep: () => {}, fileAttachment: () => {}, - testParameter: () => {} + testParameter: () => {}, + testName: () => {} }; diff --git a/writer.js b/writer.js index 0b70ff7..588ed23 100644 --- a/writer.js +++ b/writer.js @@ -69,10 +69,11 @@ function allureWriter(on, config) { tests.forEach((test) => { const fileName = `${test.uuid}-result.json`; const testResultPath = path.join(resultsDir, fileName); + const testResult = overwriteTestNameMaybe(test); !fs.existsSync(testResultPath) && fs.writeFileSync( testResultPath, - JSON.stringify(test) + JSON.stringify(testResult) ); }); if (attachments) { @@ -117,4 +118,16 @@ const writeInfoFile = (fileName, data, resultsDir) => { } }; +const overwriteTestNameMaybe = (test) => { + const overrideIndex = test.parameters.findIndex( + (p) => p.name === 'OverwriteTestName' + ); + if (overrideIndex !== -1) { + test.name = test.parameters[overrideIndex].value; + test.fullName = test.parameters[overrideIndex].value; + test.parameters.splice(overrideIndex, 1); + } + return test; +}; + module.exports = allureWriter; diff --git a/yarn.lock b/yarn.lock index 10c057e..98382cc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8362,6 +8362,11 @@ util@~0.10.1: dependencies: inherits "2.0.3" +uuid@8.3.2: + version "8.3.2" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2" + integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg== + uuid@^3.3.2, uuid@^3.3.3: version "3.4.0" resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"