-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.log
s in the roca
project's JS test suite):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aw bummer it reports as console.print
instead of just print
? So close!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
jest
packages andtap-parser
to 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: