This repository has been archived by the owner on May 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Add custom reporter to produce Problem Matcher output #2
Open
stefanbuck
wants to merge
5
commits into
master
Choose a base branch
from
add-custom-reporter
base: master
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8245003
Add custom reporter to produce Problem Matcher ouput
stefanbuck 6cb8f1e
update test
stefanbuck 56a75b4
Do not rely on test location to get line number
stefanbuck 42c3323
Loop all the arrays
stefanbuck 82d50fd
more tests
stefanbuck File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
"reporters": ["<rootDir>/json-reporter.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
class MyCustomReporter { | ||
constructor(globalConfig, options) { | ||
this._globalConfig = globalConfig; | ||
this._options = options; | ||
} | ||
|
||
onRunComplete(contexts, results) { | ||
results.testResults.forEach((testResultItem) => { | ||
const testFilePath = testResultItem.testFilePath; | ||
|
||
testResultItem.testResults.forEach((result) => { | ||
if (result.status !== "failed") { | ||
return; | ||
} | ||
|
||
result.failureMessages.forEach(failureMessages => { | ||
const newLine = "%0A"; | ||
const message = failureMessages.replace(/\n/g, newLine); | ||
const captureGroup = message.match(/:([0-9]+):([0-9]+)/); | ||
|
||
if (!captureGroup) { | ||
console.log('Unable to extract line number from call stack') | ||
return; | ||
} | ||
|
||
const [, line, col] = captureGroup; | ||
console.log(`::error file=${testFilePath},line=${line},col=${col}::${message}`); | ||
}) | ||
|
||
}); | ||
}) | ||
} | ||
} | ||
|
||
module.exports = MyCustomReporter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 is the magic which turns a console.log into a GitHub annotation.