Skip to content

Commit

Permalink
feat: option to disable logging cy commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Shevtsov committed Dec 21, 2020
1 parent 6c3fbb0 commit 1c259df
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@
```

- You can setup prefix for issue and tms links by adding env variables

- via `cypress.json`:

```json
{
"env": {
Expand All @@ -112,11 +114,22 @@
# usage: cy.allure().issue('blockerIssue', 'AST-111')
# result: https://url-to-bug-tracking-system/task-AST-111
```

- via command line:

```bash
--env issuePrefix=https://url-to-bug-tracking-system/task-,tmsPrefix=https://url-to-tms/tests/caseId-
```

- Logging of cypress commands inside Allure could be disabled with passing env variable:
- ```json
{
"env": {
"allureLogCypress": false
}
}
```

## Execution

- be sure your docker or local browser versions are next: Chrome 71+, Edge 79+. Firefox 65+
Expand Down
15 changes: 10 additions & 5 deletions reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const { AllureRuntime, InMemoryAllureWriter } = require('allure-js-commons');
const AllureReporter = require('./mocha-allure/AllureReporter');
const stubbedAllure = require('./stubbedAllure');
const allureEnabled = Cypress.env('allure') === true;
const shouldLogCypress = Cypress.env('allureLogCypress') !== false;

class CypressAllureReporter {
constructor() {
Expand All @@ -26,7 +27,10 @@ class CypressAllureReporter {
resultsDir:
Cypress.env('allureResultsPath') || 'allure-results',
writer: new InMemoryAllureWriter()
})
}),
{
logCypress: shouldLogCypress
}
);

Cypress.mocha
Expand Down Expand Up @@ -66,19 +70,20 @@ class CypressAllureReporter {
});

Cypress.on('command:enqueued', (command) => {
this.reporter.cyCommandEnqueue(command);
shouldLogCypress && this.reporter.cyCommandEnqueue(command);
});

Cypress.on('command:start', (command) => {
this.reporter.cyCommandStart(command.attributes);
shouldLogCypress &&
this.reporter.cyCommandStart(command.attributes);
});

Cypress.on('command:end', (command) => {
this.reporter.cyCommandEnd(command.attributes);
shouldLogCypress && this.reporter.cyCommandEnd(command.attributes);
});

Cypress.on('fail', (err) => {
this.reporter.cyCommandsFinish();
shouldLogCypress && this.reporter.cyCommandsFinish();
// add video to failed test case:
if (Cypress.config().video && this.reporter.currentTest) {
this.reporter.currentTest.addAttachment(
Expand Down
5 changes: 3 additions & 2 deletions reporter/mocha-allure/AllureReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const stubbedAllure = require('../stubbedAllure');
const callbacks = ['then', 'spread', 'each', 'within'];

module.exports = class AllureReporter {
constructor(runtime) {
constructor(runtime, options) {
this.suites = [];
this.steps = [];
this.commands = [];
Expand All @@ -22,6 +22,7 @@ module.exports = class AllureReporter {
this.runtime = runtime;
this.currentHook = null;
this.parentStep = null;
this.logCypress = options.logCypress || false;
}

/**
Expand Down Expand Up @@ -290,7 +291,7 @@ module.exports = class AllureReporter {
if (this.currentTest === null) {
throw new Error('finishing test while no test is running');
}
this.cyCommandsFinish(status);
this.logCypress && this.cyCommandsFinish(status);
this.finishAllSteps(status);
this.parentStep = null;

Expand Down
4 changes: 3 additions & 1 deletion reporter/stubbedAllure.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ const stubbedAllure = {
testAttachment: () => {},
step: () => {},
startStep: () => {},
endStep: () => {}
stepStart: () => {},
endStep: () => {},
stepEnd: () => {}
};

0 comments on commit 1c259df

Please sign in to comment.