Have a test to verify the stats
parent
8b1a637b3c
commit
0b7776957d
|
@ -3,6 +3,8 @@ const metaltest = (title) => {
|
|||
const only = []
|
||||
const before = []
|
||||
const after = []
|
||||
const end = []
|
||||
|
||||
|
||||
let success = 0
|
||||
let fail = 0
|
||||
|
@ -16,6 +18,7 @@ const metaltest = (title) => {
|
|||
runner.only = (name, fn) => { only.push({ name, fn }) }
|
||||
runner.before = (fn) => { before.push(fn) }
|
||||
runner.after = (fn) => { after.push(fn) }
|
||||
runner.end = (name, fn) => { end.push({ name, fn }) }
|
||||
|
||||
const notify = async (reporters, event, ...args) => {
|
||||
for (const reporter of reporters) {
|
||||
|
@ -45,9 +48,24 @@ const metaltest = (title) => {
|
|||
}
|
||||
}
|
||||
|
||||
const stats = { title, success, fail, total: success + fail, testSuccess, testFail }
|
||||
|
||||
for (const test of end) {
|
||||
try {
|
||||
await test.fn(stats)
|
||||
|
||||
success++
|
||||
testSuccess.push(test)
|
||||
notify(reporters, 'success', test)
|
||||
} catch (error) {
|
||||
fail++
|
||||
testFail.push(Object.assign({}, test, { error }))
|
||||
notify(reporters, 'fail', test, error)
|
||||
}
|
||||
}
|
||||
|
||||
for (const fn of after) await fn()
|
||||
|
||||
const stats = { title, success, fail, total: success + fail, testSuccess, testFail }
|
||||
notify(reporters, 'end', stats)
|
||||
return stats
|
||||
}
|
||||
|
|
|
@ -13,11 +13,14 @@ test('throw', () => {
|
|||
}, { name: 'Error', message: 'message' })
|
||||
})
|
||||
|
||||
import { runifmain, summaryreporter } from '../index.js'
|
||||
await runifmain(import.meta, async () => {
|
||||
const stats = await test.run(summaryreporter())
|
||||
test.end('verify', async (stats) => {
|
||||
assert.equal(stats.success, 4)
|
||||
assert.equal(stats.fail, 0)
|
||||
assert.equal(stats.total, 4)
|
||||
assert.equal(stats.title, 'Metaltest')
|
||||
assert.equal(stats.testSuccess.length, 4)
|
||||
assert.equal(stats.testFail.length, 0)
|
||||
})
|
||||
|
||||
import { runifmain, summaryreporter, errorreporter } from '../index.js'
|
||||
await runifmain(import.meta, () => test.run(summaryreporter(), errorreporter()))
|
||||
|
|
Loading…
Reference in New Issue