From 2a805c1f1c4a9f7c1c2ff34d9af12834718d4b9c Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Tue, 5 Jul 2022 09:07:55 -0700 Subject: [PATCH] fix(line reporter): print currently running test (#15339) --- .../playwright-test/src/reporters/line.ts | 38 +++++++++++++------ tests/playwright-test/reporter-json.spec.ts | 14 +++---- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/packages/playwright-test/src/reporters/line.ts b/packages/playwright-test/src/reporters/line.ts index 017cd89e9e..373251f062 100644 --- a/packages/playwright-test/src/reporters/line.ts +++ b/packages/playwright-test/src/reporters/line.ts @@ -16,7 +16,7 @@ import { colors } from 'playwright-core/lib/utilsBundle'; import { BaseReporter, formatFailure, formatTestTitle } from './base'; -import type { FullConfig, TestCase, Suite, TestResult, FullResult } from '../../types/testReporter'; +import type { FullConfig, TestCase, Suite, TestResult, FullResult, TestStep } from '../../types/testReporter'; class LineReporter extends BaseReporter { private _current = 0; @@ -62,18 +62,23 @@ class LineReporter extends BaseReporter { console.log(); } + onTestBegin(test: TestCase, result: TestResult) { + ++this._current; + this._updateLine(test, result, undefined); + } + + onStepBegin(test: TestCase, result: TestResult, step: TestStep) { + if (step.category === 'test.step') + this._updateLine(test, result, step); + } + + onStepEnd(test: TestCase, result: TestResult, step: TestStep) { + if (step.category === 'test.step') + this._updateLine(test, result, step.parent); + } + override onTestEnd(test: TestCase, result: TestResult) { super.onTestEnd(test, result); - ++this._current; - const retriesPrefix = this.totalTestCount < this._current ? ` (retries)` : ``; - const prefix = `[${this._current}/${this.totalTestCount}]${retriesPrefix} `; - const currentRetrySuffix = result.retry ? colors.yellow(` (retry #${result.retry})`) : ''; - const title = formatTestTitle(this.config, test) + currentRetrySuffix; - if (process.env.PW_TEST_DEBUG_REPORTERS) - process.stdout.write(`${prefix + title}\n`); - else - process.stdout.write(`\u001B[1A\u001B[2K${prefix + this.fitToScreen(title, prefix)}\n`); - if (!this.willRetry(test) && (test.outcome() === 'flaky' || test.outcome() === 'unexpected')) { if (!process.env.PW_TEST_DEBUG_REPORTERS) process.stdout.write(`\u001B[1A\u001B[2K`); @@ -84,6 +89,17 @@ class LineReporter extends BaseReporter { } } + private _updateLine(test: TestCase, result: TestResult, step?: TestStep) { + const retriesPrefix = this.totalTestCount < this._current ? ` (retries)` : ``; + const prefix = `[${this._current}/${this.totalTestCount}]${retriesPrefix} `; + const currentRetrySuffix = result.retry ? colors.yellow(` (retry #${result.retry})`) : ''; + const title = formatTestTitle(this.config, test, step) + currentRetrySuffix; + if (process.env.PW_TEST_DEBUG_REPORTERS) + process.stdout.write(`${prefix + title}\n`); + else + process.stdout.write(`\u001B[1A\u001B[2K${prefix + this.fitToScreen(title, prefix)}\n`); + } + override async onEnd(result: FullResult) { if (!process.env.PW_TEST_DEBUG_REPORTERS) process.stdout.write(`\u001B[1A\u001B[2K`); diff --git a/tests/playwright-test/reporter-json.spec.ts b/tests/playwright-test/reporter-json.spec.ts index 98a49274ca..2702c008c0 100644 --- a/tests/playwright-test/reporter-json.spec.ts +++ b/tests/playwright-test/reporter-json.spec.ts @@ -133,11 +133,11 @@ test('should show steps', async ({ runInlineTest }) => { expect(result.exitCode).toBe(1); expect(result.report.suites.length).toBe(1); expect(result.report.suites[0].specs.length).toBe(1); - expect(result.report.suites[0].specs[0].tests[0].results[0].steps[0].title).toBe('math works in a step'); - expect(result.report.suites[0].specs[0].tests[0].results[0].steps[0].steps[0].title).toBe('nested step'); - expect(result.report.suites[0].specs[0].tests[0].results[0].steps[0].steps[0].steps[0].title).toBe('deeply nested step'); - expect(result.report.suites[0].specs[0].tests[0].results[0].steps[0].steps[0].steps[0].steps).toBeUndefined(); - expect(result.report.suites[0].specs[0].tests[0].results[0].steps[1].error).not.toBeUndefined(); + expect(result.report.suites[0].specs[0].tests[0].results[0].steps![0].title).toBe('math works in a step'); + expect(result.report.suites[0].specs[0].tests[0].results[0].steps![0].steps![0].title).toBe('nested step'); + expect(result.report.suites[0].specs[0].tests[0].results[0].steps![0].steps![0].steps![0].title).toBe('deeply nested step'); + expect(result.report.suites[0].specs[0].tests[0].results[0].steps![0].steps![0].steps![0].steps).toBeUndefined(); + expect(result.report.suites[0].specs[0].tests[0].results[0].steps![1].error).not.toBeUndefined(); }); test('should display tags separately from title', async ({ runInlineTest }) => { @@ -198,8 +198,8 @@ test('should have error position in results', async ({ }); expect(result.exitCode).toBe(1); expect(result.report.suites[0].specs[0].file).toBe('a.test.js'); - expect(result.report.suites[0].specs[0].tests[0].results[0].errorLocation.line).toBe(7); - expect(result.report.suites[0].specs[0].tests[0].results[0].errorLocation.column).toBe(23); + expect(result.report.suites[0].specs[0].tests[0].results[0].errorLocation!.line).toBe(7); + expect(result.report.suites[0].specs[0].tests[0].results[0].errorLocation!.column).toBe(23); }); test('should add dot in addition to file json with CI', async ({ runInlineTest }, testInfo) => {