Skip to content

Commit

Permalink
feat(stats): calculate correct total duration
Browse files Browse the repository at this point in the history
* Fix duration calculation

* Update index.js

* Update snapshot

* Update test json files to have a more relevant snapshot
  • Loading branch information
basile-parent authored Mar 13, 2023
1 parent 0dab16f commit 2665292
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 18 deletions.
15 changes: 7 additions & 8 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,29 @@ const collectSourceFiles = flatMap(pattern => {
return files
})

function generateStats(suites) {
function generateStats(suites, reports) {
const tests = getAllTests(suites)
const passes = tests.filter(test => test.state === 'passed')
const pending = tests.filter(test => test.state === 'pending')
const failures = tests.filter(test => test.state === 'failed')
const skipped = tests.filter(test => test.state === 'skipped')

const timeStats = getStateTimeSpan(reports)

return {
suites: suites.length,
tests: tests.length,
passes: passes.length,
pending: pending.length,
failures: failures.length,
start: new Date().toISOString(),
end: new Date().toISOString(),
duration: tests.map(test => test.duration).reduce((a, b) => a + b, 0),
testsRegistered: tests.length,
passPercent: (passes.length * 100) / tests.length,
pendingPercent: (pending.length * 100) / tests.length,
other: 0,
hasOther: false,
skipped: skipped.length,
hasSkipped: !!skipped.length,
...timeStats
}
}

Expand Down Expand Up @@ -74,6 +75,7 @@ const getStateTimeSpan = reports => {
return {
start: maxSpan.start.toISOString(),
end: maxSpan.end.toISOString(),
duration: maxSpan.end.getTime() - maxSpan.start.getTime()
}
}

Expand All @@ -84,10 +86,7 @@ exports.merge = async function merge(options) {
const suites = collectReportSuites(reports)

return {
stats: {
...generateStats(suites),
...getStateTimeSpan(reports),
},
stats: generateStats(suites, reports),
results: suites,
meta: reports[0].meta,
}
Expand Down
4 changes: 2 additions & 2 deletions tests/__snapshots__/merge.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

exports[`merge merges configs 1`] = `
Object {
"duration": 800,
"end": "2020-12-21T17:42:36.693Z",
"duration": 156052,
"end": "2018-12-21T17:44:25.123Z",
"failures": 3,
"hasOther": false,
"hasSkipped": true,
Expand Down
4 changes: 2 additions & 2 deletions tests/mochawesome-report/mochawesome_001.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"passes": 0,
"pending": 0,
"failures": 1,
"start": "2018-12-21T17:41:49.071Z",
"end": "2018-12-21T17:42:36.693Z",
"start": "2018-12-21T17:42:36.693Z",
"end": "2018-12-21T17:43:51.693Z",
"duration": 100,
"testsRegistered": 1,
"passPercent": 0,
Expand Down
4 changes: 2 additions & 2 deletions tests/mochawesome-report/mochawesome_002.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"passes": 1,
"pending": 0,
"failures": 2,
"start": "2018-12-21T17:41:49.071Z",
"end": "2018-12-21T17:42:36.693Z",
"start": "2018-12-21T17:43:51.693Z",
"end": "2018-12-21T17:44:02.543Z",
"duration": 300,
"testsRegistered": 3,
"passPercent": 33.3,
Expand Down
4 changes: 2 additions & 2 deletions tests/mochawesome-report/mochawesome_003.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"passes": 0,
"pending": 0,
"failures": 0,
"start": "2019-06-12T02:22:23.782Z",
"end": "2019-06-12T02:22:23.789Z",
"start": "2018-12-21T17:44:02.543Z",
"end": "2018-12-21T17:44:07.354Z",
"duration": 7,
"testsRegistered": 0,
"passPercent": null,
Expand Down
4 changes: 2 additions & 2 deletions tests/mochawesome-report/mochawesome_004.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"passes": 0,
"pending": 1,
"failures": 0,
"start": "2020-12-21T17:41:49.071Z",
"end": "2020-12-21T17:42:36.693Z",
"start": "2018-12-21T17:44:07.354Z",
"end": "2018-12-21T17:44:25.123Z",
"duration": 100,
"testsRegistered": 2,
"passPercent": 0,
Expand Down

0 comments on commit 2665292

Please sign in to comment.