mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(reporters): carefully handle empty lines (#28591)
In some circumstances, like "No tests found" error, reporters produce a lot of unnecessary empty lines: ``` $ npx playwright test Error: No tests found $ <next command> ``` Also, `line` reporter removes the `npx playwright test` command entirely when `onError` happens before `onBegin`.
This commit is contained in:
parent
d20a20b9b6
commit
10dda30c7f
@ -470,7 +470,7 @@ export function formatError(error: TestError, highlightCode: boolean): ErrorDeta
|
|||||||
tokens.push(snippet);
|
tokens.push(snippet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parsedStack) {
|
if (parsedStack && parsedStack.stackLines.length) {
|
||||||
tokens.push('');
|
tokens.push('');
|
||||||
tokens.push(colors.dim(parsedStack.stackLines.join('\n')));
|
tokens.push(colors.dim(parsedStack.stackLines.join('\n')));
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ class LineReporter extends BaseReporter {
|
|||||||
private _current = 0;
|
private _current = 0;
|
||||||
private _failures = 0;
|
private _failures = 0;
|
||||||
private _lastTest: TestCase | undefined;
|
private _lastTest: TestCase | undefined;
|
||||||
|
private _didBegin = false;
|
||||||
|
|
||||||
override printsToStdio() {
|
override printsToStdio() {
|
||||||
return true;
|
return true;
|
||||||
@ -28,8 +29,12 @@ class LineReporter extends BaseReporter {
|
|||||||
|
|
||||||
override onBegin(suite: Suite) {
|
override onBegin(suite: Suite) {
|
||||||
super.onBegin(suite);
|
super.onBegin(suite);
|
||||||
console.log(this.generateStartingMessage());
|
const startingMessage = this.generateStartingMessage();
|
||||||
console.log();
|
if (startingMessage) {
|
||||||
|
console.log(startingMessage);
|
||||||
|
console.log();
|
||||||
|
}
|
||||||
|
this._didBegin = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
override onStdOut(chunk: string | Buffer, test?: TestCase, result?: TestResult) {
|
override onStdOut(chunk: string | Buffer, test?: TestCase, result?: TestResult) {
|
||||||
@ -105,15 +110,15 @@ class LineReporter extends BaseReporter {
|
|||||||
override onError(error: TestError): void {
|
override onError(error: TestError): void {
|
||||||
super.onError(error);
|
super.onError(error);
|
||||||
|
|
||||||
const message = formatError(error, colors.enabled).message + '\n\n';
|
const message = formatError(error, colors.enabled).message + '\n';
|
||||||
if (!process.env.PW_TEST_DEBUG_REPORTERS)
|
if (!process.env.PW_TEST_DEBUG_REPORTERS && this._didBegin)
|
||||||
process.stdout.write(`\u001B[1A\u001B[2K`);
|
process.stdout.write(`\u001B[1A\u001B[2K`);
|
||||||
process.stdout.write(message);
|
process.stdout.write(message);
|
||||||
console.log();
|
console.log();
|
||||||
}
|
}
|
||||||
|
|
||||||
override async onEnd(result: FullResult) {
|
override async onEnd(result: FullResult) {
|
||||||
if (!process.env.PW_TEST_DEBUG_REPORTERS)
|
if (!process.env.PW_TEST_DEBUG_REPORTERS && this._didBegin)
|
||||||
process.stdout.write(`\u001B[1A\u001B[2K`);
|
process.stdout.write(`\u001B[1A\u001B[2K`);
|
||||||
await super.onEnd(result);
|
await super.onEnd(result);
|
||||||
this.epilogue(false);
|
this.epilogue(false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user