Skip to content

Commit 573ae7b

Browse files
committed
Try getting the actual failure position
1 parent 29c3dcd commit 573ae7b

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

script/jest-actions-reporter.js

+30-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ class JestActionsReporter {
2222
}
2323

2424
const path = relative(repoRoot, testFilePath)
25-
const { line, column } = location
2625

2726
for (const msg of failureMessages) {
27+
const { line, column } =
28+
tryGetFailureLocation(msg, testFilePath) || location
29+
2830
const escapedMessage = `${msg}`.replace(/\r?\n/g, '%0A')
2931
process.stdout.write(
3032
`::error file=${path},line=${line},col=${column}::${escapedMessage}\n`
@@ -35,4 +37,31 @@ class JestActionsReporter {
3537
}
3638
}
3739

40+
function tryGetFailureLocation(message, testPath) {
41+
for (const line of message.split(/\r?\n/g)) {
42+
if (!/^\s+at\s/.test(line)) {
43+
continue
44+
}
45+
46+
const ix = line.indexOf(testPath)
47+
48+
if (ix < 0) {
49+
continue
50+
}
51+
52+
const locationRe = /:(\d+):(\d+)/
53+
const remainder = line.substr(ix + testPath.length)
54+
const match = locationRe.exec(remainder)
55+
56+
if (match) {
57+
return {
58+
line: parseInt(match[1], 10),
59+
column: parseInt(match[2], 10),
60+
}
61+
}
62+
}
63+
64+
return undefined
65+
}
66+
3867
module.exports = JestActionsReporter

0 commit comments

Comments
 (0)