-
Notifications
You must be signed in to change notification settings - Fork 0
Add custom reporter to produce Problem Matcher output #2
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
"reporters": ["<rootDir>/json-reporter.js"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
class MyCustomReporter { | ||
constructor(globalConfig, options) { | ||
this._globalConfig = globalConfig; | ||
this._options = options; | ||
} | ||
|
||
onRunComplete(contexts, results) { | ||
results.testResults[0].testResults.forEach((item) => { | ||
if (item.status !== "failed") { | ||
return; | ||
} | ||
const newLine = "%0A"; | ||
const name = results.testResults[0].testFilePath; | ||
|
||
if (!item.location) { | ||
throw new Error( | ||
"You need to invoked jest with argument --testLocationInResults" | ||
stefanbuck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
} | ||
|
||
const line = item.location.line + 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I misread the documentation
Anyway, thanks for the hint about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated the implementation according to your comment. Should I try to get a Jest PR up? If you could point me to a location / package where I should make changes, that would be amazing. From a quick look it feels like it should be part of https://github.com/facebook/jest/tree/master/packages/jest-reporters/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Part of reporters, yeah. Auto-adding it would go somewhere here: https://github.com/facebook/jest/blob/faa52673f4d02ee1d273103ada9382a0805b54a4/packages/jest-core/src/TestScheduler.ts#L267-L298 We should probably wait a bit with that until we're happy, though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm already super happy with the result 😉 I want to get this feature in so I can deprecate a Danger.js plugin I wrote to present failing tests on a Pull Request. Also I think the Jest community will love this integration which works out of the box with every GitHub Action setup. The image below shows a comment on a Pull Request generated by a custom Danger.js](https://github.com/danger/danger-js) plugin |
||
const col = item.location.column; | ||
const message = item.failureMessages[0].replace(/\n/g, newLine); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We might need to iterate over |
||
|
||
console.log(`::error file=${name},line=${line},col=${col}::${message}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The GitHub runner has some build in matchers and therefore all we have to do is producing output in this format actions/toolkit#260 (comment) |
||
}); | ||
} | ||
} | ||
|
||
module.exports = MyCustomReporter; |
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.
We have to url encode new lines in order to produce a matcher message that can spawn over multiple lines