@@ -22,9 +22,11 @@ class JestActionsReporter {
22
22
}
23
23
24
24
const path = relative ( repoRoot , testFilePath )
25
- const { line, column } = location
26
25
27
26
for ( const msg of failureMessages ) {
27
+ const { line, column } =
28
+ tryGetFailureLocation ( msg , testFilePath ) || location
29
+
28
30
const escapedMessage = `${ msg } ` . replace ( / \r ? \n / g, '%0A' )
29
31
process . stdout . write (
30
32
`::error file=${ path } ,line=${ line } ,col=${ column } ::${ escapedMessage } \n`
@@ -35,4 +37,31 @@ class JestActionsReporter {
35
37
}
36
38
}
37
39
40
+ function tryGetFailureLocation ( message , testPath ) {
41
+ for ( const line of message . split ( / \r ? \n / g) ) {
42
+ if ( ! / ^ \s + a t \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
+
38
67
module . exports = JestActionsReporter
0 commit comments