@@ -6,6 +6,8 @@ import type {
6
6
import fs from 'fs'
7
7
import path from 'path'
8
8
9
+ const ansiRegex = new RegExp ( '([\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~])))' , 'g' )
10
+
9
11
class MyReporter implements Reporter {
10
12
outputFolder : string ;
11
13
testResults : Array < string > ;
@@ -16,12 +18,8 @@ class MyReporter implements Reporter {
16
18
this . testResults = [ ]
17
19
}
18
20
19
- removeColorCodes ( input : string ) {
20
- return input . replace ( / \[ [ 0 - 9 ; ] * m / g, '' )
21
- }
22
-
23
- escapeSpecialCharacters ( input : string ) {
24
- return input . replace ( / ( [ \' \" \& \{ \} ] ) / g, '\\$1' )
21
+ stripAnsiEscapes ( str : string ) : string {
22
+ return str . replace ( ansiRegex , '' )
25
23
}
26
24
27
25
cleanupFolder ( ) {
@@ -52,13 +50,13 @@ class MyReporter implements Reporter {
52
50
`
53
51
result . errors . forEach ( error => {
54
52
if ( error . message ) {
55
- testResult += `${ this . removeColorCodes ( error . message ) }
53
+ testResult += `${ error . message }
56
54
57
55
`
58
56
}
59
57
60
58
if ( error . snippet ) {
61
- testResult += `${ this . removeColorCodes ( error . snippet ) }
59
+ testResult += `${ error . snippet }
62
60
63
61
`
64
62
}
@@ -87,7 +85,7 @@ class MyReporter implements Reporter {
87
85
88
86
${ this . testResults . join ( '' ) } `
89
87
90
- reportContent = this . escapeSpecialCharacters ( reportContent )
88
+ reportContent = this . stripAnsiEscapes ( reportContent )
91
89
}
92
90
93
91
fs . writeFileSync ( reportPath , reportContent )
0 commit comments