render tags unconditionally in base

This commit is contained in:
Mark Stewart 2024-10-07 22:29:02 +01:00
parent db925359d9
commit 8f89a2b5a5
No known key found for this signature in database
GPG key ID: 8F4C93FFAE542241
5 changed files with 23 additions and 26 deletions

View file

@ -102,7 +102,6 @@ List report supports the following configuration options and environment variabl
| Environment Variable Name | Reporter Config Option| Description | Default | Environment Variable Name | Reporter Config Option| Description | Default
|---|---|---|---| |---|---|---|---|
| `PLAYWRIGHT_LIST_PRINT_STEPS` | `printSteps` | Whether to print each step on its own line. | `false` | `PLAYWRIGHT_LIST_PRINT_STEPS` | `printSteps` | Whether to print each step on its own line. | `false`
| `PLAYWRIGHT_LIST_APPEND_TAGS` | `appendTags` | Whether to append tags to the end of the test name. | `false`
| `PLAYWRIGHT_FORCE_TTY` | | Whether to produce output suitable for a live terminal. If a number is specified, it will also be used as the terminal width. | `true` when terminal is in TTY mode, `false` otherwise. | `PLAYWRIGHT_FORCE_TTY` | | Whether to produce output suitable for a live terminal. If a number is specified, it will also be used as the terminal width. | `true` when terminal is in TTY mode, `false` otherwise.
| `FORCE_COLOR` | | Whether to produce colored output. | `true` when terminal is in TTY mode, `false` otherwise. | `FORCE_COLOR` | | Whether to produce colored output. | `true` when terminal is in TTY mode, `false` otherwise.

View file

@ -401,7 +401,7 @@ export function stepSuffix(step: TestStep | undefined) {
return stepTitles.map(t => t.split('\n')[0]).map(t => ' ' + t).join(''); return stepTitles.map(t => t.split('\n')[0]).map(t => ' ' + t).join('');
} }
export function formatTestTitle(config: FullConfig, test: TestCase, step?: TestStep, omitLocation: boolean = false, appendTags: boolean = false): string { export function formatTestTitle(config: FullConfig, test: TestCase, step?: TestStep, omitLocation: boolean = false): string {
// root, project, file, ...describes, test // root, project, file, ...describes, test
const [, projectName, , ...titles] = test.titlePath(); const [, projectName, , ...titles] = test.titlePath();
let location; let location;
@ -410,7 +410,7 @@ export function formatTestTitle(config: FullConfig, test: TestCase, step?: TestS
else else
location = `${relativeTestPath(config, test)}:${step?.location?.line ?? test.location.line}:${step?.location?.column ?? test.location.column}`; location = `${relativeTestPath(config, test)}:${step?.location?.line ?? test.location.line}:${step?.location?.column ?? test.location.column}`;
const projectTitle = projectName ? `[${projectName}] ` : ''; const projectTitle = projectName ? `[${projectName}] ` : '';
const tags = appendTags && test.tags.length > 0 ? ` [${test.tags.join(', ')}]` : ''; const tags = test.tags.length > 0 ? ` ${test.tags.join(' ')}` : '';
return `${projectTitle}${location} ${titles.join(' ')}${stepSuffix(step)}${tags}`; return `${projectTitle}${location} ${titles.join(' ')}${stepSuffix(step)}${tags}`;
} }

View file

@ -33,12 +33,10 @@ class ListReporter extends BaseReporter {
private _stepIndex = new Map<TestStep, string>(); private _stepIndex = new Map<TestStep, string>();
private _needNewLine = false; private _needNewLine = false;
private _printSteps: boolean; private _printSteps: boolean;
private _appendTags: boolean;
constructor(options: { printSteps?: boolean; appendTags?: boolean } = {}) { constructor(options: { printSteps?: boolean;} = {}) {
super(); super();
this._printSteps = getAsBooleanFromENV('PLAYWRIGHT_LIST_PRINT_STEPS', options.printSteps); this._printSteps = getAsBooleanFromENV('PLAYWRIGHT_LIST_PRINT_STEPS', options.printSteps);
this._appendTags = getAsBooleanFromENV('PLAYWRIGHT_LIST_APPEND_TAGS', options.appendTags);
} }
override onBegin(suite: Suite) { override onBegin(suite: Suite) {
@ -59,7 +57,7 @@ class ListReporter extends BaseReporter {
this._maybeWriteNewLine(); this._maybeWriteNewLine();
this._testRows.set(test, this._lastRow); this._testRows.set(test, this._lastRow);
const prefix = this._testPrefix(index, ''); const prefix = this._testPrefix(index, '');
const line = colors.dim(formatTestTitle(this.config, test, undefined, false, this._appendTags)) + this._retrySuffix(result); const line = colors.dim(formatTestTitle(this.config, test)) + this._retrySuffix(result);
this._appendLine(line, prefix); this._appendLine(line, prefix);
} }
@ -99,7 +97,7 @@ class ListReporter extends BaseReporter {
const line = test.title + colors.dim(stepSuffix(step)); const line = test.title + colors.dim(stepSuffix(step));
this._appendLine(line, prefix); this._appendLine(line, prefix);
} else { } else {
this._updateLine(this._testRows.get(test)!, colors.dim(formatTestTitle(this.config, test, step, false, this._appendTags)) + this._retrySuffix(result), this._testPrefix(testIndex, '')); this._updateLine(this._testRows.get(test)!, colors.dim(formatTestTitle(this.config, test, step)) + this._retrySuffix(result), this._testPrefix(testIndex, ''));
} }
} }
@ -110,12 +108,12 @@ class ListReporter extends BaseReporter {
const testIndex = this._resultIndex.get(result) || ''; const testIndex = this._resultIndex.get(result) || '';
if (!this._printSteps) { if (!this._printSteps) {
if (isTTY) if (isTTY)
this._updateLine(this._testRows.get(test)!, colors.dim(formatTestTitle(this.config, test, step.parent, false, this._appendTags)) + this._retrySuffix(result), this._testPrefix(testIndex, '')); this._updateLine(this._testRows.get(test)!, colors.dim(formatTestTitle(this.config, test, step.parent)) + this._retrySuffix(result), this._testPrefix(testIndex, ''));
return; return;
} }
const index = this.getStepIndex(testIndex, result, step); const index = this.getStepIndex(testIndex, result, step);
const title = isTTY ? test.title + colors.dim(stepSuffix(step)) : formatTestTitle(this.config, test, step, false, this._appendTags); const title = isTTY ? test.title + colors.dim(stepSuffix(step)) : formatTestTitle(this.config, test, step);
const prefix = this._testPrefix(index, ''); const prefix = this._testPrefix(index, '');
let text = ''; let text = '';
if (step.error) if (step.error)
@ -163,7 +161,7 @@ class ListReporter extends BaseReporter {
override onTestEnd(test: TestCase, result: TestResult) { override onTestEnd(test: TestCase, result: TestResult) {
super.onTestEnd(test, result); super.onTestEnd(test, result);
const title = formatTestTitle(this.config, test, undefined, false, this._appendTags); const title = formatTestTitle(this.config, test);
let prefix = ''; let prefix = '';
let text = ''; let text = '';

View file

@ -418,5 +418,19 @@ for (const useIntermediateMergeReport of [false, true] as const) {
expect(result.passed).toBe(1); expect(result.passed).toBe(1);
expect(result.output).toMatch(/\d+ passed \(\d+(\.\d)?(ms|s)\)/); expect(result.output).toMatch(/\d+ passed \(\d+(\.\d)?(ms|s)\)/);
}); });
test('should output tags', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `
const { test, expect } = require('@playwright/test');
test('passes', { tag: ['@foo', '@bar'] }, async ({}) => {
expect(0).toBe(0);
});
`,
});
const text = result.output;
expect(text).toContain('passes @foo @bar');
});
}); });
} }

View file

@ -258,20 +258,6 @@ for (const useIntermediateMergeReport of [false, true] as const) {
expect(text).toContain('1) a.test.ts:3:15 passes outer 1.0 inner 1.1 ──'); expect(text).toContain('1) a.test.ts:3:15 passes outer 1.0 inner 1.1 ──');
expect(result.exitCode).toBe(1); expect(result.exitCode).toBe(1);
}); });
test('append tags', async ({ runInlineTest }) => {
const result = await runInlineTest({
'a.test.ts': `
const { test, expect } = require('@playwright/test');
test('passes', { tag: ['@foo', '@bar'] }, async ({}) => {
expect(0).toBe(0);
});
`,
}, { reporter: 'list', workers: '1' }, { PLAYWRIGHT_LIST_APPEND_TAGS: '1' });
const text = result.output;
expect(text).toContain(`${POSITIVE_STATUS_MARK} 1 a.test.ts:3:11 passes [@foo, @bar]`);
});
}); });
} }