Extract stats counting
parent
ded9237acc
commit
48bac473fc
|
@ -5,13 +5,23 @@ const metaltest = (title) => {
|
|||
const after = []
|
||||
const end = []
|
||||
|
||||
|
||||
let success = 0
|
||||
let fail = 0
|
||||
const testSuccess = []
|
||||
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 }
|
||||
}
|
||||
|
||||
|
@ -40,14 +50,11 @@ const metaltest = (title) => {
|
|||
try {
|
||||
for (const fn of before) await fn()
|
||||
await test.fn()
|
||||
|
||||
success++
|
||||
testSuccess.push(test)
|
||||
stats('success', test)
|
||||
notify(reporters, 'success', test)
|
||||
}
|
||||
catch (error) {
|
||||
fail++
|
||||
testFail.push(Object.assign({}, test, { error }))
|
||||
stats('fail', test, error)
|
||||
notify(reporters, 'fail', test, error)
|
||||
}
|
||||
}
|
||||
|
@ -56,20 +63,19 @@ const metaltest = (title) => {
|
|||
try {
|
||||
await test.fn(stats())
|
||||
|
||||
success++
|
||||
testSuccess.push(test)
|
||||
stats('success', test)
|
||||
notify(reporters, 'success', test)
|
||||
} catch (error) {
|
||||
fail++
|
||||
testFail.push(Object.assign({}, test, { error }))
|
||||
stats('fail', test, error)
|
||||
notify(reporters, 'fail', test, error)
|
||||
}
|
||||
}
|
||||
|
||||
for (const fn of after) await fn()
|
||||
|
||||
notify(reporters, 'end', stats())
|
||||
return stats
|
||||
const r = stats()
|
||||
notify(reporters, 'end', r)
|
||||
return r
|
||||
}
|
||||
|
||||
return runner
|
||||
|
|
Loading…
Reference in New Issue