1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-02-20 23:22:56 +01:00
slate/support/benchmark-reporter.js

33 lines
623 B
JavaScript
Raw Normal View History

const { stdout } = process
module.exports = function (runner, utils) {
let hasSuite = false
let hasBench = false
runner.on('start', () => {
stdout.write('[')
})
runner.on('end', () => {
stdout.write(']')
})
runner.on('suite start', (suite) => {
if (hasSuite) stdout.write(',')
stdout.write(`{"name":"${suite.title}","benchmarks":[`)
hasSuite = true
})
runner.on('suite end', (suite) => {
hasBench = false
stdout.write(']}')
})
runner.on('bench end', (bench) => {
if (hasBench) stdout.write(',')
stdout.write(JSON.stringify(bench))
hasBench = true
})
}