Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: test name overwrite, fix skipped handling, docs #73

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions cypress/integration/results/steps.test.js
Original file line number Diff line number Diff line change
@@ -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);
Expand All @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/*",
Expand All @@ -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",
Expand Down
1 change: 1 addition & 0 deletions reporter/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions reporter/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 - <key, value> format
Expand Down
3 changes: 3 additions & 0 deletions reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {});
4 changes: 4 additions & 0 deletions reporter/mocha-allure/AllureInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
6 changes: 4 additions & 2 deletions reporter/mocha-allure/AllureReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ module.exports = class AllureReporter {
}

startHook(hook) {
if (!this.currentSuite) {
if (!this.currentSuite || isEmpty(hook)) {
return;
}
/**
Expand All @@ -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
Expand Down Expand Up @@ -730,3 +730,5 @@ module.exports = class AllureReporter {
return executable.startStep(message());
}
};

const isEmpty = (hook) => hook && hook.body === 'function () {}';
3 changes: 2 additions & 1 deletion reporter/stubbedAllure.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ const stubbedAllure = {
stepEnd: () => {},
endStep: () => {},
fileAttachment: () => {},
testParameter: () => {}
testParameter: () => {},
testName: () => {}
};
15 changes: 14 additions & 1 deletion writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down