Extract stats counting

master
Frédéric Matte 2022-12-06 20:18:42 -05:00
parent ded9237acc
commit 48bac473fc
1 changed files with 19 additions and 13 deletions

View File

@ -5,13 +5,23 @@ const metaltest = (title) => {
const after = [] const after = []
const end = [] const end = []
let success = 0 let success = 0
let fail = 0 let fail = 0
const testSuccess = [] const testSuccess = []
const testFail = [] const testFail = []
const stats = () => { const stats = (type, test, error) => {
switch (type) {
case 'success':
success++
testSuccess.push(test)
break
case 'fail':
fail++
testFail.push(Object.assign({}, test, { error }))
break
}
return { title, success, fail, total: success + fail, testSuccess, testFail } return { title, success, fail, total: success + fail, testSuccess, testFail }
} }
@ -40,14 +50,11 @@ const metaltest = (title) => {
try { try {
for (const fn of before) await fn() for (const fn of before) await fn()
await test.fn() await test.fn()
stats('success', test)
success++
testSuccess.push(test)
notify(reporters, 'success', test) notify(reporters, 'success', test)
} }
catch (error) { catch (error) {
fail++ stats('fail', test, error)
testFail.push(Object.assign({}, test, { error }))
notify(reporters, 'fail', test, error) notify(reporters, 'fail', test, error)
} }
} }
@ -56,20 +63,19 @@ const metaltest = (title) => {
try { try {
await test.fn(stats()) await test.fn(stats())
success++ stats('success', test)
testSuccess.push(test)
notify(reporters, 'success', test) notify(reporters, 'success', test)
} catch (error) { } catch (error) {
fail++ stats('fail', test, error)
testFail.push(Object.assign({}, test, { error }))
notify(reporters, 'fail', test, error) notify(reporters, 'fail', test, error)
} }
} }
for (const fn of after) await fn() for (const fn of after) await fn()
notify(reporters, 'end', stats()) const r = stats()
return stats notify(reporters, 'end', r)
return r
} }
return runner return runner