-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun-tests.js
147 lines (132 loc) · 4.03 KB
/
run-tests.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
const cypress = require('cypress');
const glob = require('glob');
const Promise = require('bluebird');
const fs = require('fs');
require('console.table');
const runOneSpec = (spec, config) => {
return cypress
.run({
config: {
video: false,
e2e: {
specPattern: spec,
},
},
...config,
})
.then((result) => {
if (result.failures) {
console.error('Could not execute tests');
console.error(result.message);
process.exit(1); // abort testrun fast
}
return result;
})
.catch((err) => {
console.error(err.message);
// process.exit(1);
});
};
glob('**/*in*spec.js', (err, specs) => {
if (err) {
console.error(err);
process.exit(2);
}
console.table('Running last modified spec first', specs);
var configs = [
// {
// env: {
// NO_COMMAND_LOG: 1,
// },
// },
{
env: {
NO_COMMAND_LOG: 0,
},
},
];
configs.forEach((config) => {
Promise.mapSeries(specs, (specs) => runOneSpec(specs, config)).then((runResults) => writeReport(runResults, config));
});
});
function writeReport(runResults, config) {
// information about each test run is available
// see the full NPM API declaration in
// https://github.com/cypress-io/cypress/tree/develop/cli/types
const summary = runResults.map((run) => {
var firstRun = run.runs ? run.runs[0] : {};
var runReport = {
spec: firstRun.spec.name,
totalDuration: run.totalDuration,
reporterDuration: firstRun.reporterStats.duration,
runStatsDuration: firstRun.stats.duration,
browserName: run.browserName,
browserVersion: run.browserVersion,
osName: run.osName,
// osVersion: run.osVersion,
cypressVersion: run.cypressVersion,
video: run.config.video,
report: run.config.report,
resolvedNodeVersion: run.config.resolvedNodeVersion,
noCommandLog: run.config.env.NO_COMMAND_LOG,
// config: JSON.stringify(config, null, 2),
};
//console.log(runReport);
return runReport;
});
var overallDuration = summary.reduce((total, curr) => total + curr.totalDuration, 0);
const shortSummary = {
cypressVersion: summary[0].cypressVersion,
browserName: summary[0].browserName,
browserVersion: summary[0].browserVersion,
osName: summary[0].osName,
resolvedNodeVersion: summary[0].resolvedNodeVersion,
overallDuration,
video: summary[0].video,
noCommandLog: summary[0].noCommandLog,
};
console.log('Short summary', shortSummary);
var fileName = `run-stats.csv`;
if (!fs.existsSync(fileName)) {
fs.writeFileSync(fileName, csvHeader(shortSummary));
}
fs.appendFileSync(fileName, csvContent(shortSummary));
// fs.appendFileSync(`run-stats.csv`, csvHeader(summary));
// fs.writeFileSync(
// `logs/cypress(${cypressVersion})-video(${video})-commandlog(${commandLog})-duration(${overallDuration})-${new Date().getTime()}.log`,
// JSON.stringify(summary, null, 2)
// );
}
function csvHeader(obj) {
// Use first element to choose the keys and the order
var keys = Object.keys(obj);
// Build header
var result = keys.join(',') + '\r\n';
return result;
}
function csvContent(obj) {
// Use first element to choose the keys and the order
var keys = Object.keys(obj);
var result = '';
// Add the rows
result += keys.map((k) => `${obj[k]}`).join(',') + '\r\n';
return result;
}
// function csvHeader(array) {
// // Use first element to choose the keys and the order
// var keys = Object.keys(array[0]);
// // Build header
// var result = keys.join(',') + '\r\n';
// return result;
// }
// function csvContent(array) {
// // Use first element to choose the keys and the order
// var keys = Object.keys(array[0]);
// var result = '';
// // Add the rows
// array.forEach(function (obj) {
// result += keys.map((k) => `${obj[k]}`).join(',') + '\r\n';
// // result += keys.map((k) => `"${(obj[k] + '').replace(/"/g, '""')}"`).join(',') + '\r\n';
// });
// return result;
// }