2021-06-07 02:09:53 +02:00
|
|
|
|
/**
|
|
|
|
|
|
* Copyright (c) Microsoft Corporation.
|
|
|
|
|
|
*
|
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
|
*
|
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
*
|
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2022-04-19 02:50:25 +02:00
|
|
|
|
import { colors } from 'playwright-core/lib/utilsBundle';
|
2022-07-28 23:46:21 +02:00
|
|
|
|
import { BaseReporter, formatError } from './base';
|
|
|
|
|
|
import type { FullResult, TestCase, TestResult, FullConfig, Suite, TestError } from '../../types/testReporter';
|
2021-06-07 02:09:53 +02:00
|
|
|
|
|
|
|
|
|
|
class DotReporter extends BaseReporter {
|
|
|
|
|
|
private _counter = 0;
|
|
|
|
|
|
|
2021-11-03 16:25:16 +01:00
|
|
|
|
printsToStdio() {
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-03 19:17:23 +01:00
|
|
|
|
override onBegin(config: FullConfig, suite: Suite) {
|
|
|
|
|
|
super.onBegin(config, suite);
|
|
|
|
|
|
console.log(this.generateStartingMessage());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-25 16:11:18 +02:00
|
|
|
|
override onStdOut(chunk: string | Buffer, test?: TestCase, result?: TestResult) {
|
2021-08-12 01:44:19 +02:00
|
|
|
|
super.onStdOut(chunk, test, result);
|
|
|
|
|
|
if (!this.config.quiet)
|
|
|
|
|
|
process.stdout.write(chunk);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-25 16:11:18 +02:00
|
|
|
|
override onStdErr(chunk: string | Buffer, test?: TestCase, result?: TestResult) {
|
2021-08-12 01:44:19 +02:00
|
|
|
|
super.onStdErr(chunk, test, result);
|
|
|
|
|
|
if (!this.config.quiet)
|
|
|
|
|
|
process.stderr.write(chunk);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-25 16:11:18 +02:00
|
|
|
|
override onTestEnd(test: TestCase, result: TestResult) {
|
2021-06-07 02:09:53 +02:00
|
|
|
|
super.onTestEnd(test, result);
|
2021-07-30 10:34:28 +02:00
|
|
|
|
if (this._counter === 80) {
|
2021-06-07 02:09:53 +02:00
|
|
|
|
process.stdout.write('\n');
|
2021-07-30 10:34:28 +02:00
|
|
|
|
this._counter = 0;
|
2021-06-07 02:09:53 +02:00
|
|
|
|
}
|
2021-07-30 10:34:28 +02:00
|
|
|
|
++this._counter;
|
2021-06-07 02:09:53 +02:00
|
|
|
|
if (result.status === 'skipped') {
|
|
|
|
|
|
process.stdout.write(colors.yellow('°'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-08-25 21:19:50 +02:00
|
|
|
|
if (this.willRetry(test)) {
|
2021-06-07 02:09:53 +02:00
|
|
|
|
process.stdout.write(colors.gray('×'));
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2021-07-19 02:40:59 +02:00
|
|
|
|
switch (test.outcome()) {
|
2021-06-07 02:09:53 +02:00
|
|
|
|
case 'expected': process.stdout.write(colors.green('·')); break;
|
2021-07-30 10:34:28 +02:00
|
|
|
|
case 'unexpected': process.stdout.write(colors.red(result.status === 'timedOut' ? 'T' : 'F')); break;
|
2021-06-07 02:09:53 +02:00
|
|
|
|
case 'flaky': process.stdout.write(colors.yellow('±')); break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-07-28 23:46:21 +02:00
|
|
|
|
override onError(error: TestError): void {
|
|
|
|
|
|
super.onError(error);
|
|
|
|
|
|
console.log('\n' + formatError(this.config, error, colors.enabled).message);
|
|
|
|
|
|
this._counter = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-08-25 16:11:18 +02:00
|
|
|
|
override async onEnd(result: FullResult) {
|
2021-06-29 19:55:46 +02:00
|
|
|
|
await super.onEnd(result);
|
2021-06-07 02:09:53 +02:00
|
|
|
|
process.stdout.write('\n');
|
|
|
|
|
|
this.epilogue(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default DotReporter;
|