-
Notifications
You must be signed in to change notification settings - Fork 0
/
cypress-run.js
64 lines (57 loc) · 1.91 KB
/
cypress-run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const cypress = require('cypress');
// we cannot set environment CYPRESS_INTERNAL_ENV directly :-(
process.env['CYPRESS_INTERNAL_ENV'] = 'development';
process.env['API_RETRY_INTERVALS'] = '1000,1000,1000';
const runOptions = {
// tag: process.argv[2], // abusing "tag" to hand over the response status code that the dummy dashboard server should return
spec: process.argv[3],
// record: true,
// parallel: true,
// watchForFileChanges: false,
// key: 'dummyKey',
// ciBuildId: '123',
};
console.log(`runOptions: ${JSON.stringify(runOptions)}`);
cypress
.run(runOptions)
.then((result) => {
if (result.failures) {
// console.error(JSON.stringify(result));
printRedFailure(result);
process.exit(1);
}
if (result.totalFailed > 0) {
printRedFailure(JSON.stringify(result, null, 2));
process.exit(1);
} else {
console.log('All tests passed');
printGreenSuccess(result);
// console.log(JSON.stringify(result, null, 2));
}
})
.catch((err) => {
console.error(err);
process.exit(1);
});
// const cypressPromises = [cypress.run(runOptions)];
// Promise.all(cypressPromises)
// .then((results) => {
// console.log(JSON.stringify(results));
// // console.log(`result.totalFailed: ${results[0].totalFailed}`);
// if (results.some((result) => result.totalFailed > 0)) {
// console.log(`Tests failed - setting exit code to 1`);
// // process.exitCode = 1;
// }
// })
// .catch((err) => {
// console.log(`error occurred - setting exit code to 2`);
// console.log(err);
// // process.exitCode = 2;
// });
const OCTESC = '\033';
function printGreenSuccess(message) {
console.log(`${OCTESC}[1;32m ✔ \"${message}\"${OCTESC}[0m${OCTESC}[32m executed successfully!${OCTESC}[0m`);
}
function printRedFailure(message) {
console.log(`${OCTESC}[1;31m ✘ \"${message}\"${OCTESC}[0m${OCTESC}[31m failed!${OCTESC}[0m`);
}