@@ -6,6 +6,8 @@ import type {
66import fs from 'fs'
77import path from 'path'
88
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+
911class MyReporter implements Reporter {
1012 outputFolder : string ;
1113 testResults : Array < string > ;
@@ -16,12 +18,8 @@ class MyReporter implements Reporter {
1618 this . testResults = [ ]
1719 }
1820
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 , '' )
2523 }
2624
2725 cleanupFolder ( ) {
@@ -52,13 +50,13 @@ class MyReporter implements Reporter {
5250`
5351 result . errors . forEach ( error => {
5452 if ( error . message ) {
55- testResult += `${ this . removeColorCodes ( error . message ) }
53+ testResult += `${ error . message }
5654
5755`
5856 }
5957
6058 if ( error . snippet ) {
61- testResult += `${ this . removeColorCodes ( error . snippet ) }
59+ testResult += `${ error . snippet }
6260
6361`
6462 }
@@ -87,7 +85,7 @@ class MyReporter implements Reporter {
8785
8886${ this . testResults . join ( '' ) } `
8987
90- reportContent = this . escapeSpecialCharacters ( reportContent )
88+ reportContent = this . stripAnsiEscapes ( reportContent )
9189 }
9290
9391 fs . writeFileSync ( reportPath , reportContent )
0 commit comments