Skip to content
This repository has been archived by the owner on May 8, 2023. It is now read-only.

Add custom reporter to produce Problem Matcher output #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Do not rely on test location to get line number
  • Loading branch information
stefanbuck committed Apr 25, 2020
commit 56a75b417c258b93a263b9a122e33701839a91b4
9 changes: 1 addition & 8 deletions json-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,8 @@ class MyCustomReporter {
const newLine = "%0A";
Copy link
Owner Author

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

const name = results.testResults[0].testFilePath;

if (!item.location) {
throw new Error(
"You need to invoked jest with argument --testLocationInResults"
);
}

const line = item.location.line + 1;
const col = item.location.column;
const message = item.failureMessages[0].replace(/\n/g, newLine);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We might need to iterate over failureMessages, but for this MVP its should be enough

const [, line, col] = item.failureMessages[0].match(/:([0-9]+):([0-9]+)/);

console.log(`::error file=${name},line=${line},col=${col}::${message}`);
Copy link
Owner Author

Choose a reason for hiding this comment

The 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)

});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"main": "index.js",
"scripts": {
"test": "jest . --testLocationInResults"
"test": "jest ."
},
"keywords": [],
"author": "",
Expand Down
3 changes: 2 additions & 1 deletion some.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ describe("foo", function() {
});

it("fails", function() {
expect("b").toBe("a");
expect("b").toBe("b");
expect("c").toBe("d");
});
});