Skip to content
This repository has been archived by the owner on Mar 13, 2024. It is now read-only.

Mochawesome reporting #3130

Merged
merged 5 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Mochawesome reporting
  • Loading branch information
thekiiingbob committed Jul 15, 2019
commit 1274a227953702064459725e44ac5384449ce50d
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ mattermost-webapp.iml

# disable folders generated by Cypress
e2e/node_modules
e2e/cypress/screenshots
e2e/screenshots
e2e/cypress/videos
e2e/results
e2e/mochawesome-report
e2e/mochawesome-merged.json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's clean this up with the only folders to ignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@saturninoabril Pushed up changes to remove those unneeded ignores. Added .eslintignore file to handle ignoring e2e/results in linting.

7 changes: 1 addition & 6 deletions e2e/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,5 @@
"viewportWidth": 1300,
"defaultCommandTimeout": 20000,
"taskTimeout": 20000,
"video": false,
"reporter": "junit",
"reporterOptions": {
"mochaFile": "results/results-[hash].xml",
"toConsole": false
}
"video": false
}
63 changes: 63 additions & 0 deletions e2e/cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,74 @@
// Read more at: https://on.cypress.io/configuration
// ***********************************************************

/* eslint-disable no-loop-func */

import './ui_commands';
import './api_commands';
import './task_commands';
import '@testing-library/cypress/add-commands';
import 'cypress-file-upload';
import addContext from 'mochawesome/addContext';

Cypress.on('test:after:run', (test, runnable) => {
// Only if the test is failed to we want ot add
saturninoabril marked this conversation as resolved.
Show resolved Hide resolved
// the additional context of the screenshot.
if (test.state === 'failed') {
let filename = Cypress.spec.name + '/';
let parentNames = '';

// Define our starting parent
let parent = runnable.parent;

// If the test failed due to a hook, we have to handle
// getting our starting parent to form the correct filename.
if (test.failedFromHookId) {
// Failed from hook Id is always something like 'h2'
// We just need tho trailing number to match with parent id
saturninoabril marked this conversation as resolved.
Show resolved Hide resolved
const hookId = test.failedFromHookId.split('')[1];

// If the current parentId does not match our hook id
// start digging upwards until we get the parent that
// has the same hook id, or until we get to a tile of ''
// (which means we are at the top level)
if (parent.id !== `r${hookId}`) {
while (parent.parent.id !== `r${hookId}`) {
if (parent.title === '') {
// If we have a title of '' we have reached the top parent
break;
} else {
parent = parent.parent;
}
}
}
}

// Now we can go from parent to parent to generate the screenshot filename
while (parent) {
// Only append parents that have actual content for their titles
if (parent.title !== '') {
parentNames = parent.title + ' -- ' + parentNames;
}

parent = parent.parent;
}

// If the test has a hook name, that means it failed due to a hook
// and consequently Cypress appends some text to the file name
const hookName = test.hookName ? ' -- ' + test.hookName + ' hook' : '';

filename += parentNames + test.title + hookName + ' (failed).png';

// Clean up filename of characters that Cypress strips out
filename = filename.replace(/[;:"<>/]/g, '');

// Add context to the mochawesome report which includes the screenshot
addContext({test}, {
title: 'Failing Screenshot: >> screenshots/' + filename,
value: 'screenshots/' + filename,
});
}
});

// Add login cookies to whitelist to preserve it
beforeEach(() => {
Expand Down
Loading