feat(reporter): implement Jest reporter#80
Conversation
| // Flatten console output because tap-parser splits output by newline in the "extra" event. | ||
| // We don't know which lines are supposed to go together, so just print them all together. | ||
| if (this.currentResults.console) { | ||
| this.currentResults.console = [ |
There was a problem hiding this comment.
This was the best solution I could think of. It's a little wonky, but it's not too far off from how Jest prints console.log statements in JS tests. The main problem is we don't have any stack trace for the logs.
Jest reporter for roca (what this PR implements):

Actual jest reporter for JS (I put some console.logs in the roca project's JS test suite):

There was a problem hiding this comment.
I think this is fine as long as we get stack traces for errors which seems like we do already 😄
There was a problem hiding this comment.
Agreed! Since we treat brs (specifically its print statements) as an opaque box from the roca perspective, I'm fine with losing that for now. It might be possible to add an eventEmitter that handles writes to stdout instead of calling interpreter.stdout.write() directly from within brs's implementation of print, but that's not necessary here at all. It'd be neat to consider for the future though — especially in combination with a --quiet in brs to suppress writes to stdout?
There was a problem hiding this comment.
It'd be neat to consider for the future though — especially in combination with a --quiet in brs to suppress writes to stdout?
I agree, that'd be great!
| // Flatten console output because tap-parser splits output by newline in the "extra" event. | ||
| // We don't know which lines are supposed to go together, so just print them all together. | ||
| if (this.currentResults.console) { | ||
| this.currentResults.console = [ |
There was a problem hiding this comment.
I think this is fine as long as we get stack traces for errors which seems like we do already 😄
alimnios72
left a comment
There was a problem hiding this comment.
Thanks for the changes
sjbarag
left a comment
There was a problem hiding this comment.
For safety's sake it might be worth keeping --reporter spec as the default for a release or two while we opt-into --reporter jest to shake out any hidden bugs, but if you're comfortable with it I'm down to give this a try!
Excellent work @lkipke — I'm excited to get this out to the world!
| .map((entry) => entry.message) | ||
| .join(""), | ||
| origin: "", // TODO: figure out how to get the stack trace | ||
| type: "print" as any, // a little hack because brightscript uses `print` instead of `console.log` |
There was a problem hiding this comment.
Aw bummer it reports as console.print instead of just print? So close!
There was a problem hiding this comment.
I know, so close 😢 And we have no control over the outputted string here, either, so we can't use replace or anything, sadly.
Summary
This leverages the
jestpackages andtap-parserto create a Jest-style reporter.Screenshots
Default reporter
Verbose reporter
Failing due to assert
Failing due to runtime exception
In test case
In source code
Print statements
Code: