Introduce notify reporter
parent
850240e9ef
commit
f59a4923a0
|
@ -1,5 +1,3 @@
|
||||||
import { nullreporter } from '../reporter/nullreporter.js'
|
|
||||||
|
|
||||||
const metaltest = (title) => {
|
const metaltest = (title) => {
|
||||||
const suite = []
|
const suite = []
|
||||||
const only = []
|
const only = []
|
||||||
|
@ -19,11 +17,17 @@ const metaltest = (title) => {
|
||||||
runner.before = (fn) => { before.push(fn) }
|
runner.before = (fn) => { before.push(fn) }
|
||||||
runner.after = (fn) => { after.push(fn) }
|
runner.after = (fn) => { after.push(fn) }
|
||||||
|
|
||||||
runner.run = async (...reporters) => {
|
const notify = async (reporters, event, ...args) => {
|
||||||
const rs = reporters.map(r => Object.assign({}, nullreporter, r))
|
for (const reporter of reporters) {
|
||||||
|
if (!reporter[event]) continue
|
||||||
|
|
||||||
rs.forEach(r => r.start(title))
|
await reporter[event](...args)
|
||||||
rs.forEach(r => r.before())
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runner.run = async (...reporters) => {
|
||||||
|
notify(reporters, 'start', title)
|
||||||
|
notify(reporters, 'before')
|
||||||
|
|
||||||
const tests = only.length ? only : suite
|
const tests = only.length ? only : suite
|
||||||
for (const test of tests) {
|
for (const test of tests) {
|
||||||
|
@ -31,22 +35,21 @@ const metaltest = (title) => {
|
||||||
for (const fn of before) await fn()
|
for (const fn of before) await fn()
|
||||||
await test.fn()
|
await test.fn()
|
||||||
success++
|
success++
|
||||||
rs.forEach(r => r.success(test))
|
notify(reporters, 'success', test)
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
fail++
|
fail++
|
||||||
|
|
||||||
testFail.push(Object.assign({}, test, { error: e }))
|
testFail.push(Object.assign({}, test, { error: e }))
|
||||||
rs.forEach(r => r.fail(test, e))
|
notify(reporters, 'fail', test, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const fn of after) await fn()
|
for (const fn of after) await fn()
|
||||||
|
notify(reporters, 'after')
|
||||||
rs.forEach(r => r.after())
|
|
||||||
|
|
||||||
const stats = { title, success, fail, total: success + fail, testSuccess, testFail }
|
const stats = { title, success, fail, total: success + fail, testSuccess, testFail }
|
||||||
|
notify(reporters, 'end', stats)
|
||||||
rs.forEach(r => r.end(stats))
|
|
||||||
|
|
||||||
return stats
|
return stats
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
const nullreporter = {
|
|
||||||
start: (title) => { },
|
|
||||||
before: () => { },
|
|
||||||
success: (test) => { },
|
|
||||||
fail: (test, e) => { },
|
|
||||||
after: () => { },
|
|
||||||
end: (stats) => { },
|
|
||||||
}
|
|
||||||
|
|
||||||
export { nullreporter }
|
|
Loading…
Reference in New Issue