Skip to content

Commit

Permalink
feat: handle soft asserts, fix video attachment on pass, address #108,
Browse files Browse the repository at this point in the history
  • Loading branch information
Shelex committed Dec 8, 2021
1 parent 9c3fd40 commit 57d5b23
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
6 changes: 4 additions & 2 deletions reporter/allure-cypress/AllureInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,11 @@ Allure.prototype.stepEnd = function () {
// just find the last user created step and finish it
const step = this.reporter.popStep();
if (step) {
const status = getStatus(this);
if (step.status !== Status.FAILED) {
const status = getStatus(this);
step.stepResult.status = status;
}
step.stepResult.stage = Stage.FINISHED;
step.stepResult.status = status;
step.endStep();
}
};
Expand Down
27 changes: 19 additions & 8 deletions reporter/allure-cypress/AllureReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,17 +318,28 @@ module.exports = class AllureReporter {
}

finishRemainingSteps(status = Status.PASSED) {
const alreadyHasFailedStep =
this.currentTest &&
this.currentTest.info &&
this.currentTest.info.steps.some(
(step) => step.status === Status.FAILED
);

this.steps.forEach((step) => {
step.info.stage = Stage.FINISHED;
if (step.info.steps.length) {
step.info.status = step.info.steps.some(
(step) => step.status === Status.FAILED
)
? Status.FAILED
: Status.PASSED;
} else {
step.info.status = status;

if (!alreadyHasFailedStep) {
if (step.info.steps.length) {
step.info.status = step.info.steps.some(
(step) => step.status === Status.FAILED
)
? Status.FAILED
: Status.PASSED;
} else {
step.info.status = status;
}
}

step.endStep();
});
this.steps = [];
Expand Down
13 changes: 13 additions & 0 deletions reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,19 @@ class CypressAllureReporter {
this.reporter.cy.finished(command.attributes);
}
});

Cypress.on('log:added', (log) => {
if (log.state === 'failed') {
logger.cy('found failed log:added %O', log);

if (
this.reporter.currentExecutable &&
this.reporter.currentExecutable.info
) {
this.reporter.currentExecutable.info.status = 'failed';
}
}
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function allureWriter(on, config) {
try {
results.error
? handleCrash(results)
: attachScreenshotsAndVideo(allureMapping, results);
: attachScreenshotsAndVideo(allureMapping, results, config);
} catch (e) {
logger.writer(
'failed to add attachments in "after:spec" due to: %O',
Expand Down
10 changes: 8 additions & 2 deletions writer/attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const logger = require('../reporter/debug');
const videoContentType = 'video/mp4';
const imageContentType = 'image/png';

const attachScreenshotsAndVideo = (allureMapping, results) => {
const attachScreenshotsAndVideo = (allureMapping, results, config) => {
if (!allureMapping) {
logger.writer('not found mapping of mocha test id to allure test ids');
return;
Expand All @@ -16,6 +16,8 @@ const attachScreenshotsAndVideo = (allureMapping, results) => {
results.video &&
`${uuid.v4()}-attachment${path.extname(results.video)}`;

const shouldAddVideoOnPass = config.env.allureAddVideoOnPass !== false;

const needVideo = results.tests.filter((test) => {
const allureId = allureMapping[test.testId];
if (!allureId) {
Expand Down Expand Up @@ -72,7 +74,11 @@ const attachScreenshotsAndVideo = (allureMapping, results) => {
});
});

if (results.video) {
if (
results.video &&
// attach video for not passed tests or for every in case "allureAddVideoOnPass" enabled
(allureTest.status !== 'passed' || shouldAddVideoOnPass)
) {
logger.writer('going to attach video for "%s"', allureId);
const existingVideoIndex = allureTest.attachments.findIndex(
(attach) => attach.type === videoContentType
Expand Down

0 comments on commit 57d5b23

Please sign in to comment.