Skip to content

Commit 0770208

Browse files
authored
fix: Update regex for removing ANSI colors output (#271)
* fix: Disable color output * fix: Update regex for removing ANSI colors output * revert FORCE_COLOR update * strip stderr as well * also strip process.stdout * fix typo * test output * test output file * what if I disable stdout/stderr? * test different log file name * put console log under assets folder * remove debug code * fix filepath * let spawn error * revert debug * bump package * remove console.log directly
1 parent c7eb370 commit 0770208

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

package-lock.json

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"homepage": "https://github.com/saucelabs/sauce-playwright-runner",
3333
"dependencies": {
3434
"@playwright/test": "1.45.2",
35-
"@saucelabs/playwright-reporter": "1.2.1",
35+
"@saucelabs/playwright-reporter": "1.2.2",
3636
"@saucelabs/testcomposer": "3.0.0",
3737
"dotenv": "16.4.5",
3838
"lodash": "4.17.21",

src/playwright-recorder.ts

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
import * as fs from 'node:fs';
21
import * as path from 'node:path';
32
import { Transform } from 'node:stream';
43
import * as childProcess from 'node:child_process';
54
import * as process from 'node:process';
65

7-
const escapeSequenceRegex = new RegExp('[\\u001b]\\[2K|[\\u001b]\\[0G', 'g');
6+
const escapeSequenceRegex = new RegExp(
7+
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))',
8+
'g',
9+
);
810

911
export function playwrightRecorder() {
10-
// console.log is saved out of reportsDir since it is cleared on startup.
11-
const ws = fs.createWriteStream(path.join(process.cwd(), 'console.log'), {
12-
flags: 'w+',
13-
mode: 0o644,
14-
});
1512
const stripAsciiTransform = new Transform({
1613
transform(chunk, _, callback) {
1714
// list reporter uses escape codes to rewrite lines, strip them to make console output more readable
@@ -25,13 +22,10 @@ export function playwrightRecorder() {
2522
...process.argv.slice(2),
2623
]);
2724

28-
child.stdout.pipe(process.stdout);
25+
child.stdout.pipe(stripAsciiTransform).pipe(process.stdout);
2926
child.stderr.pipe(process.stderr);
30-
child.stdout.pipe(stripAsciiTransform).pipe(ws);
31-
child.stderr.pipe(ws);
3227

3328
child.on('exit', (exitCode) => {
34-
ws.end();
3529
process.exit(exitCode ?? 1);
3630
});
3731
}

0 commit comments

Comments
 (0)