Skip to content

Commit 7de9629

Browse files
authored
fix: Remove ANSI color from error output (#50)
* fix: Remove ANSI color from error output * rename
1 parent ba33c43 commit 7de9629

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/reporter.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,15 @@ export default class SauceReporter implements Reporter {
356356
return consoleLog;
357357
}
358358

359+
removeAnsiColors(str: string): string {
360+
const ansiRegex = new RegExp(
361+
// eslint-disable-next-line no-control-regex
362+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
363+
'g',
364+
);
365+
return str.replace(ansiRegex, '');
366+
}
367+
359368
constructSauceSuite(rootSuite: PlaywrightSuite) {
360369
const suite = new SauceSuite(rootSuite.title);
361370
const assets: Asset[] = [];
@@ -393,7 +402,7 @@ export default class SauceReporter implements Reporter {
393402
: Status.Failed,
394403
duration: lastResult.duration,
395404
output: lastResult.error
396-
? this.errorToMessage(lastResult.error)
405+
? this.removeAnsiColors(this.errorToMessage(lastResult.error))
397406
: undefined,
398407
startTime: lastResult.startTime,
399408
code: new TestCode(lines),

0 commit comments

Comments
 (0)