Skip to content

Commit 341e60d

Browse files
author
Pavel Feldman
committed
chore: split output clients by capabilities and base dir
1 parent 1c8e6f0 commit 341e60d

File tree

13 files changed

+220
-133
lines changed

13 files changed

+220
-133
lines changed

packages/playwright/src/reporters/base.ts

Lines changed: 146 additions & 63 deletions
Large diffs are not rendered by default.

packages/playwright/src/reporters/dot.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { colors, BaseReporter, formatError } from './base';
17+
import { TerminalReporter } from './base';
1818
import type { FullResult, TestCase, TestResult, Suite, TestError } from '../../types/testReporter';
1919

20-
class DotReporter extends BaseReporter {
20+
class DotReporter extends TerminalReporter {
2121
private _counter = 0;
2222

2323
override onBegin(suite: Suite) {
@@ -45,23 +45,23 @@ class DotReporter extends BaseReporter {
4545
}
4646
++this._counter;
4747
if (result.status === 'skipped') {
48-
process.stdout.write(colors.yellow('°'));
48+
process.stdout.write(this.screen.colors.yellow('°'));
4949
return;
5050
}
5151
if (this.willRetry(test)) {
52-
process.stdout.write(colors.gray('×'));
52+
process.stdout.write(this.screen.colors.gray('×'));
5353
return;
5454
}
5555
switch (test.outcome()) {
56-
case 'expected': process.stdout.write(colors.green('·')); break;
57-
case 'unexpected': process.stdout.write(colors.red(result.status === 'timedOut' ? 'T' : 'F')); break;
58-
case 'flaky': process.stdout.write(colors.yellow('±')); break;
56+
case 'expected': process.stdout.write(this.screen.colors.green('·')); break;
57+
case 'unexpected': process.stdout.write(this.screen.colors.red(result.status === 'timedOut' ? 'T' : 'F')); break;
58+
case 'flaky': process.stdout.write(this.screen.colors.yellow('±')); break;
5959
}
6060
}
6161

6262
override onError(error: TestError): void {
6363
super.onError(error);
64-
console.log('\n' + formatError(error, colors.enabled).message);
64+
console.log('\n' + this.formatError(error).message);
6565
this._counter = 0;
6666
}
6767

packages/playwright/src/reporters/github.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { ms as milliseconds } from 'playwright-core/lib/utilsBundle';
1818
import path from 'path';
19-
import { BaseReporter, colors, formatError, formatResultFailure, formatRetry, formatTestHeader, formatTestTitle, stripAnsiEscapes } from './base';
19+
import { TerminalReporter, formatResultFailure, formatRetry, noColors, stripAnsiEscapes } from './base';
2020
import type { TestCase, FullResult, TestError } from '../../types/testReporter';
2121

2222
type GitHubLogType = 'debug' | 'notice' | 'warning' | 'error';
@@ -56,9 +56,14 @@ class GitHubLogger {
5656
}
5757
}
5858

59-
export class GitHubReporter extends BaseReporter {
59+
export class GitHubReporter extends TerminalReporter {
6060
githubLogger = new GitHubLogger();
6161

62+
constructor(options: { omitFailures?: boolean } = {}) {
63+
super(options);
64+
this.screen.colors = noColors;
65+
}
66+
6267
printsToStdio() {
6368
return false;
6469
}
@@ -69,7 +74,7 @@ export class GitHubReporter extends BaseReporter {
6974
}
7075

7176
override onError(error: TestError) {
72-
const errorMessage = formatError(error, false).message;
77+
const errorMessage = this.formatError(error).message;
7378
this.githubLogger.error(errorMessage);
7479
}
7580

@@ -100,10 +105,10 @@ export class GitHubReporter extends BaseReporter {
100105

101106
private _printFailureAnnotations(failures: TestCase[]) {
102107
failures.forEach((test, index) => {
103-
const title = formatTestTitle(this.config, test);
104-
const header = formatTestHeader(this.config, test, { indent: ' ', index: index + 1, mode: 'error' });
108+
const title = this.formatTestTitle(test);
109+
const header = this.formatTestHeader(test, { indent: ' ', index: index + 1, mode: 'error' });
105110
for (const result of test.results) {
106-
const errors = formatResultFailure(test, result, ' ', colors.enabled);
111+
const errors = formatResultFailure(this.screen, test, result, ' ');
107112
for (const error of errors) {
108113
const options: GitHubLogOptions = {
109114
file: workspaceRelativePath(error.location?.file || test.location.file),
@@ -113,7 +118,7 @@ export class GitHubReporter extends BaseReporter {
113118
options.line = error.location.line;
114119
options.col = error.location.column;
115120
}
116-
const message = [header, ...formatRetry(result), error.message].join('\n');
121+
const message = [header, ...formatRetry(this.screen, result), error.message].join('\n');
117122
this.githubLogger.error(message, options);
118123
}
119124
}

packages/playwright/src/reporters/html.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { open } from 'playwright-core/lib/utilsBundle';
17+
import { colors, open } from 'playwright-core/lib/utilsBundle';
1818
import { MultiMap, getPackageManagerExecCommand } from 'playwright-core/lib/utils';
1919
import fs from 'fs';
2020
import path from 'path';
@@ -23,7 +23,7 @@ import { Transform } from 'stream';
2323
import { codeFrameColumns } from '../transform/babelBundle';
2424
import type * as api from '../../types/testReporter';
2525
import { HttpServer, assert, calculateSha1, copyFileAndMakeWritable, gracefullyProcessExitDoNotHang, removeFolders, sanitizeForFilePath, toPosixPath } from 'playwright-core/lib/utils';
26-
import { colors, formatError, formatResultFailure, stripAnsiEscapes } from './base';
26+
import { formatError, formatResultFailure, internalScreen, stripAnsiEscapes } from './base';
2727
import { resolveReporterOutputPath } from '../util';
2828
import type { Metadata } from '../../types/test';
2929
import type { ZipFile } from 'playwright-core/lib/zipBundle';
@@ -297,7 +297,7 @@ class HtmlBuilder {
297297
files: [...data.values()].map(e => e.testFileSummary),
298298
projectNames: projectSuites.map(r => r.project()!.name),
299299
stats: { ...[...data.values()].reduce((a, e) => addStats(a, e.testFileSummary.stats), emptyStats()) },
300-
errors: topLevelErrors.map(error => formatError(error, true).message),
300+
errors: topLevelErrors.map(error => formatError(internalScreen, error).message),
301301
};
302302
htmlReport.files.sort((f1, f2) => {
303303
const w1 = f1.stats.unexpected * 1000 + f1.stats.flaky;
@@ -506,7 +506,7 @@ class HtmlBuilder {
506506
startTime: result.startTime.toISOString(),
507507
retry: result.retry,
508508
steps: dedupeSteps(result.steps).map(s => this._createTestStep(s)),
509-
errors: formatResultFailure(test, result, '', true).map(error => error.message),
509+
errors: formatResultFailure(internalScreen, test, result, '').map(error => error.message),
510510
status: result.status,
511511
attachments: this._serializeAttachments([
512512
...result.attachments,

packages/playwright/src/reporters/internalReporter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import fs from 'fs';
1818
import { codeFrameColumns } from '../transform/babelBundle';
1919
import type { FullConfig, TestCase, TestError, TestResult, FullResult, TestStep } from '../../types/testReporter';
2020
import { Suite } from '../common/test';
21-
import { colors, prepareErrorStack, relativeFilePath } from './base';
21+
import { internalScreen, prepareErrorStack, relativeFilePath } from './base';
2222
import type { ReporterV2 } from './reporterV2';
2323
import { monotonicTime } from 'playwright-core/lib/utils';
2424
import { Multiplexer } from './multiplexer';
@@ -125,7 +125,7 @@ function addLocationAndSnippetToError(config: FullConfig, error: TestError, file
125125
const codeFrame = codeFrameColumns(source, { start: location }, { highlightCode: true });
126126
// Convert /var/folders to /private/var/folders on Mac.
127127
if (!file || fs.realpathSync(file) !== location.file) {
128-
tokens.push(colors.gray(` at `) + `${relativeFilePath(config, location.file)}:${location.line}`);
128+
tokens.push(internalScreen.colors.gray(` at `) + `${relativeFilePath(internalScreen, config, location.file)}:${location.line}`);
129129
tokens.push('');
130130
}
131131
tokens.push(codeFrame);

packages/playwright/src/reporters/json.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import fs from 'fs';
1818
import path from 'path';
1919
import type { FullConfig, TestCase, Suite, TestResult, TestError, TestStep, FullResult, Location, JSONReport, JSONReportSuite, JSONReportSpec, JSONReportTest, JSONReportTestResult, JSONReportTestStep, JSONReportError } from '../../types/testReporter';
20-
import { formatError, prepareErrorStack, resolveOutputFile } from './base';
20+
import { formatError, nonTerminalScreen, prepareErrorStack, resolveOutputFile } from './base';
2121
import { MultiMap, toPosixPath } from 'playwright-core/lib/utils';
2222
import { getProjectId } from '../common/config';
2323
import type { ReporterV2 } from './reporterV2';
@@ -222,7 +222,7 @@ class JSONReporter implements ReporterV2 {
222222
}
223223

224224
private _serializeError(error: TestError): JSONReportError {
225-
return formatError(error, true);
225+
return formatError(nonTerminalScreen, error);
226226
}
227227

228228
private _serializeTestStep(step: TestStep): JSONReportTestStep {

packages/playwright/src/reporters/junit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import fs from 'fs';
1818
import path from 'path';
1919
import type { FullConfig, FullResult, Suite, TestCase } from '../../types/testReporter';
20-
import { formatFailure, resolveOutputFile, stripAnsiEscapes } from './base';
20+
import { formatFailure, nonTerminalScreen, resolveOutputFile, stripAnsiEscapes } from './base';
2121
import { getAsBooleanFromENV } from 'playwright-core/lib/utils';
2222
import type { ReporterV2 } from './reporterV2';
2323

@@ -188,7 +188,7 @@ class JUnitReporter implements ReporterV2 {
188188
message: `${path.basename(test.location.file)}:${test.location.line}:${test.location.column} ${test.title}`,
189189
type: 'FAILURE',
190190
},
191-
text: stripAnsiEscapes(formatFailure(this.config, test))
191+
text: stripAnsiEscapes(formatFailure(nonTerminalScreen, this.config, test))
192192
});
193193
}
194194

packages/playwright/src/reporters/line.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { colors, BaseReporter, formatError, formatFailure, formatTestTitle } from './base';
17+
import { TerminalReporter } from './base';
1818
import type { TestCase, Suite, TestResult, FullResult, TestStep, TestError } from '../../types/testReporter';
1919

20-
class LineReporter extends BaseReporter {
20+
class LineReporter extends TerminalReporter {
2121
private _current = 0;
2222
private _failures = 0;
2323
private _lastTest: TestCase | undefined;
@@ -50,7 +50,7 @@ class LineReporter extends BaseReporter {
5050
stream.write(`\u001B[1A\u001B[2K`);
5151
if (test && this._lastTest !== test) {
5252
// Write new header for the output.
53-
const title = colors.dim(formatTestTitle(this.config, test));
53+
const title = this.screen.colors.dim(this.formatTestTitle(test));
5454
stream.write(this.fitToScreen(title) + `\n`);
5555
this._lastTest = test;
5656
}
@@ -82,16 +82,16 @@ class LineReporter extends BaseReporter {
8282
if (!this.willRetry(test) && (test.outcome() === 'flaky' || test.outcome() === 'unexpected' || result.status === 'interrupted')) {
8383
if (!process.env.PW_TEST_DEBUG_REPORTERS)
8484
process.stdout.write(`\u001B[1A\u001B[2K`);
85-
console.log(formatFailure(this.config, test, ++this._failures));
85+
console.log(this.formatFailure(test, ++this._failures));
8686
console.log();
8787
}
8888
}
8989

9090
private _updateLine(test: TestCase, result: TestResult, step?: TestStep) {
9191
const retriesPrefix = this.totalTestCount < this._current ? ` (retries)` : ``;
9292
const prefix = `[${this._current}/${this.totalTestCount}]${retriesPrefix} `;
93-
const currentRetrySuffix = result.retry ? colors.yellow(` (retry #${result.retry})`) : '';
94-
const title = formatTestTitle(this.config, test, step) + currentRetrySuffix;
93+
const currentRetrySuffix = result.retry ? this.screen.colors.yellow(` (retry #${result.retry})`) : '';
94+
const title = this.formatTestTitle(test, step) + currentRetrySuffix;
9595
if (process.env.PW_TEST_DEBUG_REPORTERS)
9696
process.stdout.write(`${prefix + title}\n`);
9797
else
@@ -101,7 +101,7 @@ class LineReporter extends BaseReporter {
101101
override onError(error: TestError): void {
102102
super.onError(error);
103103

104-
const message = formatError(error, colors.enabled).message + '\n';
104+
const message = this.formatError(error).message + '\n';
105105
if (!process.env.PW_TEST_DEBUG_REPORTERS && this._didBegin)
106106
process.stdout.write(`\u001B[1A\u001B[2K`);
107107
process.stdout.write(message);

0 commit comments

Comments
 (0)