How to call Ava runner/reporter to get test stats. #2787
-
I am trying to use AVA in our test suite for e2e testing. Can somebody share an example on how to get test stats in js code like this? Here is the pseudo code of what i am trying to achieve:
I am looking for following stats: totalTestCount, passedTestCount, skippedTestCount, failedTestCount, testDuration |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Other than through what's emitted by the TAP reporter, this isn't available in any structured way. Long term we'd want this to be available through reporters, so you'd run AVA in a child process and handle the output. |
Beta Was this translation helpful? Give feedback.
-
A very simple concrete example in case one else lands on this page: import { spawn } from 'child_process'
import reporter from 'tap-json'
function runTest (file) {
const ava = spawn('npx', [
'ava',
file
])
ava.stdout
.pipe(reporter())
.on('data', (report) => {
console.log(report)
/* Output */
/* {
stats: { asserts: 1, passes: 1, failures: 0 },
asserts: [
{
number: 1,
comment: null,
name: 'Module: adds plugin',
ok: true,
extra: {}
}
]
} */
})
}
runTest('test/module.js') Seems like TAP is the way to go because of all the reporters it already supports. |
Beta Was this translation helpful? Give feedback.
A very simple concrete example in case one else lands on this page:
Seems like TAP is the way to go because of all the reporters it alr…