Skip to content

Commit

Permalink
strip Ansi Escapes
Browse files Browse the repository at this point in the history
  • Loading branch information
mxkae committed Feb 6, 2025
1 parent b6706e2 commit 926fdb0
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions e2e/config/reporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type {
import fs from 'fs'
import path from 'path'

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

class MyReporter implements Reporter {
outputFolder: string;
testResults: Array<string>;
Expand All @@ -16,12 +18,8 @@ class MyReporter implements Reporter {
this.testResults = []
}

removeColorCodes( input : string ) {
return input.replace( /\[[0-9;]*m/g, '' )
}

escapeSpecialCharacters( input: string ) {
return input.replace( /([\'\"\&\{\}])/g, '\\$1' )
stripAnsiEscapes( str: string ): string {
return str.replace( ansiRegex, '' )
}

cleanupFolder() {
Expand Down Expand Up @@ -52,13 +50,13 @@ class MyReporter implements Reporter {
`
result.errors.forEach( error => {
if ( error.message ) {
testResult += `${ this.removeColorCodes( error.message ) }
testResult += `${ error.message }
`
}

if ( error.snippet ) {
testResult += `${ this.removeColorCodes( error.snippet ) }
testResult += `${ error.snippet }
`
}
Expand Down Expand Up @@ -87,7 +85,7 @@ class MyReporter implements Reporter {
${ this.testResults.join( '' ) }`

reportContent = this.escapeSpecialCharacters( reportContent )
reportContent = this.stripAnsiEscapes( reportContent )
}

fs.writeFileSync( reportPath, reportContent )
Expand Down

0 comments on commit 926fdb0

Please sign in to comment.