mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(line reporter): print currently running test (#15339)
This commit is contained in:
parent
4eccb89a79
commit
2a805c1f1c
@ -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`);
|
||||
|
||||
@ -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) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user