From 5c4ebdce54c5f3c52d8f77d4b97dd02f597c0501 Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 13 Dec 2021 19:06:13 -0800 Subject: [PATCH] fix(line reporter): clarify about retries when going over total counter (#10901) --- .../playwright-test/src/reporters/line.ts | 20 +++++++++++++------ tests/playwright-test/reporter-line.spec.ts | 4 ++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/playwright-test/src/reporters/line.ts b/packages/playwright-test/src/reporters/line.ts index 652ee2d6bb..e9168ba743 100644 --- a/packages/playwright-test/src/reporters/line.ts +++ b/packages/playwright-test/src/reporters/line.ts @@ -46,7 +46,8 @@ class LineReporter extends BaseReporter { private _dumpToStdio(test: TestCase | undefined, chunk: string | Buffer, stream: NodeJS.WriteStream) { if (this.config.quiet) return; - stream.write(`\u001B[1A\u001B[2K`); + if (!process.env.PWTEST_SKIP_TEST_OUTPUT) + stream.write(`\u001B[1A\u001B[2K`); if (test && this._lastTest !== test) { // Write new header for the output. stream.write(colors.gray(formatTestTitle(this.config, test) + `\n`)); @@ -59,12 +60,18 @@ class LineReporter extends BaseReporter { override onTestEnd(test: TestCase, result: TestResult) { super.onTestEnd(test, result); - const width = process.stdout.columns! - 1; - const title = `[${++this._current}/${this.totalTestCount}] ${formatTestTitle(this.config, test)}`.substring(0, width); - process.stdout.write(`\u001B[1A\u001B[2K${title}\n`); + const width = process.env.PWTEST_SKIP_TEST_OUTPUT ? 79 : process.stdout.columns! - 1; + ++this._current; + const retriesSuffix = this.totalTestCount < this._current ? ` (retries)` : ``; + const title = `[${this._current}/${this.totalTestCount}]${retriesSuffix} ${formatTestTitle(this.config, test)}`.substring(0, width); + if (process.env.PWTEST_SKIP_TEST_OUTPUT) + process.stdout.write(`${title}\n`); + else + process.stdout.write(`\u001B[1A\u001B[2K${title}\n`); if (!this.willRetry(test) && (test.outcome() === 'flaky' || test.outcome() === 'unexpected')) { - process.stdout.write(`\u001B[1A\u001B[2K`); + if (!process.env.PWTEST_SKIP_TEST_OUTPUT) + process.stdout.write(`\u001B[1A\u001B[2K`); console.log(formatFailure(this.config, test, { index: ++this._failures }).message); @@ -73,7 +80,8 @@ class LineReporter extends BaseReporter { } override async onEnd(result: FullResult) { - process.stdout.write(`\u001B[1A\u001B[2K`); + if (!process.env.PWTEST_SKIP_TEST_OUTPUT) + process.stdout.write(`\u001B[1A\u001B[2K`); await super.onEnd(result); this.epilogue(false); } diff --git a/tests/playwright-test/reporter-line.spec.ts b/tests/playwright-test/reporter-line.spec.ts index 56bbaefa57..bae65be1b9 100644 --- a/tests/playwright-test/reporter-line.spec.ts +++ b/tests/playwright-test/reporter-line.spec.ts @@ -26,6 +26,10 @@ test('render unexpected after retry', async ({ runInlineTest }) => { `, }, { retries: 3, reporter: 'line' }); const text = stripAscii(result.output); + expect(text).toContain('[1/1] a.test.js:6:7 › one'); + expect(text).toContain('[2/1] (retries) a.test.js:6:7 › one'); + expect(text).toContain('[3/1] (retries) a.test.js:6:7 › one'); + expect(text).toContain('[4/1] (retries) a.test.js:6:7 › one'); expect(text).toContain('1 failed'); expect(text).toContain('1) a.test'); expect(text).not.toContain('2) a.test');