Skip to content

Commit fec0c05

Browse files
committed
create support file on init command
1 parent 5a9ad6d commit fec0c05

File tree

5 files changed

+1464
-25
lines changed

5 files changed

+1464
-25
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const addContext = require('mochawesome/addContext')
2+
3+
// NOTE: import this file in cypress/support/e2e.js
4+
Cypress.on('test:after:run', (test, runnable) => {
5+
if (test.state === 'failed') {
6+
let item = runnable
7+
const nameParts = [runnable.title]
8+
9+
// Iterate through all parents and grab the titles
10+
while (item.parent) {
11+
nameParts.unshift(item.parent.title)
12+
item = item.parent
13+
}
14+
15+
if(runnable.hookName) {
16+
nameParts.push(`${runnable.hookName} hook`)
17+
}
18+
const fullTestName = nameParts
19+
.filter(Boolean)
20+
.join(' -- ') // this is how cypress joins the test title fragments
21+
22+
const imageUrl = `${fullTestName} (failed).png`
23+
24+
addContext({ test }, imageUrl)
25+
26+
27+
}
28+
})

commands/init.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,22 @@ function create_base_reporter_config_file(args) {
5151
}
5252
};
5353

54+
function create_custom_support_file(args){
55+
const pathToFile = path.join(__dirname, "default_custom_support_file.js");
56+
// const pathToNewDestination = path.join(__dirname, constants.LT_BASE_CUSTOM_SUPPORT_FILE_NAME)
57+
const pathToNewDestination = constants.LT_BASE_CUSTOM_SUPPORT_FILE_NAME;
58+
fs.copyFile(pathToFile, pathToNewDestination, (err) => {
59+
if (err) {
60+
console.log("Error while copying custom support file", err);
61+
}
62+
else {
63+
console.log("Successfully saved custom support file at - ", pathToNewDestination);
64+
}
65+
});
66+
}
67+
5468
module.exports = function (args) {
55-
5669
create_ltconfig_file(args);
5770
create_base_reporter_config_file(args);
58-
71+
create_custom_support_file(args);
5972
};

commands/utils/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = {
66
CLI: "/cy/versions",
77
LT_CONFIG_NAME: "lambdatest-config.json",
88
LT_BASE_REPORTER_CONFIG_FILE_NAME: "base_reporter_config.json",
9+
LT_BASE_CUSTOM_SUPPORT_FILE_NAME: "custom_support_file.js",
910
CYPRESS_CONFIG_NAME: "cypress.json",
1011
DEFAULT_TEST_PATH: ".",
1112
LAMBDA_CONFIG: "./lambdatest-config.json",

0 commit comments

Comments
 (0)