fix(list reporter): assign step index on step end

This commit is contained in:
Simon Knott 2024-07-16 16:28:33 +02:00
parent ef4b5a4121
commit 0e80491f06
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC
2 changed files with 20 additions and 13 deletions

View file

@ -77,15 +77,22 @@ class ListReporter extends BaseReporter {
this._dumpToStdio(test, chunk, process.stderr);
}
private getStepIndex(testIndex: string, result: TestResult, step: TestStep): string {
if (this._stepIndex.has(step))
return this._stepIndex.get(step)!;
const ordinal = ((result as any)[lastStepOrdinalSymbol] || 0) + 1;
(result as any)[lastStepOrdinalSymbol] = ordinal;
const stepIndex = `${testIndex}.${ordinal}`;
this._stepIndex.set(step, stepIndex);
return stepIndex;
}
override onStepBegin(test: TestCase, result: TestResult, step: TestStep) {
super.onStepBegin(test, result, step);
if (step.category !== 'test.step')
return;
const testIndex = this._resultIndex.get(result) || '';
const ordinal = ((result as any)[lastStepOrdinalSymbol] || 0) + 1;
(result as any)[lastStepOrdinalSymbol] = ordinal;
const stepIndex = `${testIndex}.${ordinal}`;
this._stepIndex.set(step, stepIndex);
if (!this._printSteps) {
if (isTTY)
@ -96,7 +103,7 @@ class ListReporter extends BaseReporter {
if (isTTY) {
this._maybeWriteNewLine();
this._stepRows.set(step, this._lastRow);
const prefix = this._testPrefix(stepIndex, '');
const prefix = this._testPrefix(this.getStepIndex(testIndex, result, step), '');
const line = test.title + colors.dim(stepSuffix(step));
this._appendLine(line, prefix);
}
@ -113,7 +120,7 @@ class ListReporter extends BaseReporter {
this._updateLine(this._testRows.get(test)!, colors.dim(formatTestTitle(this.config, test, step.parent)) + this._retrySuffix(result), this._testPrefix(testIndex, ''));
}
const index = this._stepIndex.get(step)!;
const index = this.getStepIndex(testIndex, result, step);
const title = isTTY ? test.title + colors.dim(stepSuffix(step)) : formatTestTitle(this.config, test, step);
const prefix = this._testPrefix(index, '');
let text = '';

View file

@ -126,7 +126,7 @@ for (const useIntermediateMergeReport of [false, true] as const) {
]);
});
test.only('render steps in non-TTY mode', async ({ runInlineTest }) => {
test('render steps in non-TTY mode', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `
import { test, expect } from '@playwright/test';
@ -145,12 +145,12 @@ for (const useIntermediateMergeReport of [false, true] as const) {
const text = result.output;
const lines = text.split('\n').filter(l => l.match(/^\d :/)).map(l => l.replace(/[.\d]+m?s/, 'Xms'));
expect(lines).toEqual([
'0 : 1.1 a.test.ts:3:15 passes outer 1.0 inner 1.1 (Xms)',
'1 : 1.2 a.test.ts:3:15 passes outer 1.0 inner 1.2 (Xms)',
'2 : 1.3 a.test.ts:3:15 passes outer 1.0 (Xms)',
'3 : 1.4 a.test.ts:3:15 passes outer 2.0 inner 2.1 (Xms)',
'4 : 1.5 a.test.ts:3:15 passes outer 2.0 inner 2.2 (Xms)',
'5 : 1.6 a.test.ts:3:15 passes outer 2.0 (Xms)',
'0 : 1.1 a.test.ts:5:26 passes outer 1.0 inner 1.1 (Xms)',
'1 : 1.2 a.test.ts:6:26 passes outer 1.0 inner 1.2 (Xms)',
'2 : 1.3 a.test.ts:4:24 passes outer 1.0 (Xms)',
'3 : 1.4 a.test.ts:9:26 passes outer 2.0 inner 2.1 (Xms)',
'4 : 1.5 a.test.ts:10:26 passes outer 2.0 inner 2.2 (Xms)',
'5 : 1.6 a.test.ts:8:24 passes outer 2.0 (Xms)',
'6 : ✓ 1 a.test.ts:3:15 passes (Xms)',
]);
});