-
Notifications
You must be signed in to change notification settings - Fork 0
/
aggregate.js
151 lines (140 loc) · 5.82 KB
/
aggregate.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
148
149
150
151
const path = require('path')
const fs = require('fs')
const stats = require('./utils/stats')
const suites = require('./utils/suites')
const utils = require('./utils/utils')
module.exports.byProfile = function byProfile(relPathToReports, profile) {
const absPathToReports = path.resolve(relPathToReports)
const reports = fs.readdirSync(absPathToReports)
.filter((fileName) => {
return fileName.includes('.json') && fileName.includes(profile)
})
.map((fileName) => {
return require(absPathToReports + '/' + fileName)
})
if (reports.length === 0) {
return console.warn('No matching reports found to aggregate.')
}
const aggregateReport = reports.reduce((aggReport, report, i) => {
const newSuites = suites.mergeSuites(aggReport, report)
const newAllTests = suites.updateAllTests(aggReport, report)
const newAllPending = suites.updateAllPending(aggReport, report)
const newAllPasses = suites.updateAllPasses(aggReport, report)
const newAllFailures = suites.updateAllFailures(aggReport, report)
const newExecutedSuitesCount = stats.getExecutedSuitesCount(newSuites)
const newRegisteredTestsCount = stats.getRegisteredTestsCount(newSuites)
const newSkippedCount = stats.getSkippedCount(newAllTests.length, newRegisteredTestsCount)
const newStart = stats.getEarliestStart(aggReport, report)
const newEnd = stats.getLatestEnd(aggReport, report)
return {
stats: Object.assign(aggReport.stats, {
start: newStart,
end: newEnd,
duration: stats.getDuration(newStart, newEnd),
suites: newExecutedSuitesCount,
tests: newAllTests.length,
passes: newAllPasses.length,
pending: newAllPending.length,
failures: newAllFailures.length,
testsRegistered: newRegisteredTestsCount,
passPercent: stats.getPassPercent(newAllPasses.length, newSuites.length),
pendingPercent: stats.getPendingPercent(newAllPending.length, newSuites.length),
skipped: newSkippedCount,
hasSkipped: !!newSkippedCount,
passPercentClass: "danger",
pendingPercentClass: "danger"
// TODO these sometime
// other: 0,
// hasOther: false,
}),
suites: Object.assign(aggReport.suites, {
suites: newSuites
}),
allTests: newAllTests,
allPending: newAllPending,
allPasses: newAllPasses,
allFailures: newAllFailures,
copyrightYear: aggReport.copyrightYear,
}})
const reportPrefix = profile ? profile : 'aggregate'
utils.generateReportFiles(aggregateReport, reportPrefix, relPathToReports, absPathToReports)
}
module.exports.everything = function everything(relPathToReports, profile) {
const absPathToReports = path.resolve(relPathToReports)
const reports = fs.readdirSync(absPathToReports)
.filter((fileName) => {
return fileName.includes('-report.json')
})
.map((fileName) => {
return Object.assign({}, require(absPathToReports + '/' + fileName), {
profile: fileName.split('-report.json')[0],
})
})
// prepend the profile name to each suite and test title
reports.forEach((report) => {
report.suites.suites.forEach((suite) => {
suite.title = '[' + report.profile + '] ' + suite.title
suite.tests.forEach((test) => {
test.title = '[' + report.profile + '] ' + test.title
})
})
report.allTests.forEach((test) => {
test.title = '[' + report.profile + '] ' + test.title
})
report.allPasses.forEach((test) => {
test.title = '[' + report.profile + '] ' + test.title
})
report.allFailures.forEach((test) => {
test.title = '[' + report.profile + '] ' + test.title
})
report.allPending.forEach((test) => {
test.title = '[' + report.profile + '] ' + test.title
})
})
if (reports.length === 0) {
return console.warn('No matching reports found to aggregate.')
}
const aggregateReport = reports.reduce((aggReport, report, i) => {
const newSuites = aggReport.suites.suites.concat(report.suites.suites)
const newAllTests = suites.updateAllTests(aggReport, report)
const newAllPending = suites.updateAllPending(aggReport, report)
const newAllPasses = suites.updateAllPasses(aggReport, report)
const newAllFailures = suites.updateAllFailures(aggReport, report)
const newExecutedSuitesCount = stats.getExecutedSuitesCount(newSuites)
const newRegisteredTestsCount = stats.getRegisteredTestsCount(newSuites)
const newSkippedCount = stats.getSkippedCount(newAllTests.length, newRegisteredTestsCount)
const newStart = stats.getEarliestStart(aggReport, report)
const newEnd = stats.getLatestEnd(aggReport, report)
return {
stats: Object.assign(aggReport.stats, {
start: newStart,
end: newEnd,
duration: stats.getDuration(newStart, newEnd),
suites: newExecutedSuitesCount,
tests: newAllTests.length,
passes: newAllPasses.length,
pending: newAllPending.length,
failures: newAllFailures.length,
testsRegistered: newRegisteredTestsCount,
passPercent: stats.getPassPercent(newAllPasses.length, newSuites.length),
pendingPercent: stats.getPendingPercent(newAllPending.length, newSuites.length),
skipped: newSkippedCount,
hasSkipped: !!newSkippedCount,
passPercentClass: "danger",
pendingPercentClass: "danger"
// TODO these sometime
// other: 0,
// hasOther: false,
}),
suites: Object.assign(aggReport.suites, {
suites: newSuites
}),
allTests: newAllTests,
allPending: newAllPending,
allPasses: newAllPasses,
allFailures: newAllFailures,
copyrightYear: aggReport.copyrightYear,
}})
const reportPrefix = profile ? profile : 'aggregate'
utils.generateReportFiles(aggregateReport, reportPrefix, relPathToReports, absPathToReports)
}