Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(reporters): move `Running X tests using Y workers` to reporters (#10014)
Dmitry Gozman3120f816298e
diff --git a/packages/playwright-test/src/reporters/base.ts b/packages/playwright-test/src/reporters/base.tsindex 21c1553432..76a8fd786d 100644--- a/packages/playwright-test/src/reporters/base.ts+++ b/packages/playwright-test/src/reporters/base.ts@@ -58,6 +58,7 @@ export class BaseReporter implements Reporter {duration = 0;config!: FullConfig;suite!: Suite;+ totalTestCount = 0;result!: FullResult;fileDurations = new Map<string, number>();monotonicStartTime: number = 0;@@ -72,6 +73,7 @@ export class BaseReporter implements Reporter {this.monotonicStartTime = monotonicTime();this.config = config;this.suite = suite;+ this.totalTestCount = suite.allTests().length;}onStdOut(chunk: string | Buffer, test?: TestCase, result?: TestResult) {@@ -106,6 +108,12 @@ export class BaseReporter implements Reporter {this.result = result;}+ protected generateStartingMessage() {+ const jobs = Math.min(this.config.workers, (this.config as any).__testGroupsCount);+ const shardDetails = this.config.shard ? `, shard ${this.config.shard.current} of ${this.config.shard.total}` : '';+ return `\nRunning ${this.totalTestCount} test${this.totalTestCount > 1 ? 's' : ''} using ${jobs} worker${jobs > 1 ? 's' : ''}${shardDetails}`;+ }+protected getSlowTests(): [string, number][] {if (!this.config.reportSlowTests)return [];diff --git a/packages/playwright-test/src/reporters/dot.ts b/packages/playwright-test/src/reporters/dot.tsindex 66e007858f..b29f113151 100644--- a/packages/playwright-test/src/reporters/dot.ts+++ b/packages/playwright-test/src/reporters/dot.ts@@ -16,7 +16,7 @@import colors from 'colors/safe';import { BaseReporter } from './base';-import { FullResult, TestCase, TestResult } from '../../types/testReporter';+import { FullResult, TestCase, TestResult, FullConfig, Suite } from '../../types/testReporter';class DotReporter extends BaseReporter {private _counter = 0;@@ -25,6 +25,11 @@ class DotReporter extends BaseReporter {return true;}+ override onBegin(config: FullConfig, suite: Suite) {+ super.onBegin(config, suite);+ console.log(this.generateStartingMessage());+ }+override onStdOut(chunk: string | Buffer, test?: TestCase, result?: TestResult) {super.onStdOut(chunk, test, result);if (!this.config.quiet)diff --git a/packages/playwright-test/src/reporters/line.ts b/packages/playwright-test/src/reporters/line.tsindex 4629b462dc..652ee2d6bb 100644--- a/packages/playwright-test/src/reporters/line.ts+++ b/packages/playwright-test/src/reporters/line.ts@@ -19,7 +19,6 @@ import { BaseReporter, formatFailure, formatTestTitle } from './base';import { FullConfig, TestCase, Suite, TestResult, FullResult } from '../../types/testReporter';class LineReporter extends BaseReporter {- private _total = 0;private _current = 0;private _failures = 0;private _lastTest: TestCase | undefined;@@ -30,7 +29,7 @@ class LineReporter extends BaseReporter {override onBegin(config: FullConfig, suite: Suite) {super.onBegin(config, suite);- this._total = suite.allTests().length;+ console.log(this.generateStartingMessage());console.log();}@@ -61,7 +60,7 @@ class LineReporter extends BaseReporter {override onTestEnd(test: TestCase, result: TestResult) {super.onTestEnd(test, result);const width = process.stdout.columns! - 1;- const title = `[${++this._current}/${this._total}] ${formatTestTitle(this.config, test)}`.substring(0, width);+ const title = `[${++this._current}/${this.totalTestCount}] ${formatTestTitle(this.config, test)}`.substring(0, width);process.stdout.write(`\u001B[1A\u001B[2K${title}\n`);if (!this.willRetry(test) && (test.outcome() === 'flaky' || test.outcome() === 'unexpected')) {diff --git a/packages/playwright-test/src/reporters/list.ts b/packages/playwright-test/src/reporters/list.tsindex 16f352378f..aad8563a3f 100644--- a/packages/playwright-test/src/reporters/list.ts+++ b/packages/playwright-test/src/reporters/list.ts@@ -44,6 +44,7 @@ class ListReporter extends BaseReporter {override onBegin(config: FullConfig, suite: Suite) {super.onBegin(config, suite);+ console.log(this.generateStartingMessage());console.log();}diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.tsindex b2aab29990..9bb8ccdf8b 100644--- a/packages/playwright-test/src/runner.ts+++ b/packages/playwright-test/src/runner.ts@@ -296,13 +296,7 @@ export class Runner {filterSuite(rootSuite, () => false, test => shardTests.has(test));total = rootSuite.allTests().length;}-- if (process.stdout.isTTY) {- console.log();- const jobs = Math.min(config.workers, testGroups.length);- const shardDetails = shard ? `, shard ${shard.current} of ${shard.total}` : '';- console.log(`Running ${total} test${total > 1 ? 's' : ''} using ${jobs} worker${jobs > 1 ? 's' : ''}${shardDetails}`);- }+ (config as any).__testGroupsCount = testGroups.length;let sigint = false;let sigintCallback: () => void;diff --git a/tests/playwright-test/retry.spec.ts b/tests/playwright-test/retry.spec.tsindex 7ff92ae9e8..af989a1f0e 100644--- a/tests/playwright-test/retry.spec.ts+++ b/tests/playwright-test/retry.spec.ts@@ -72,7 +72,7 @@ test('should retry timeout', async ({ runInlineTest }) => {expect(exitCode).toBe(1);expect(passed).toBe(0);expect(failed).toBe(1);- expect(stripAscii(output).split('\n')[0]).toBe('××T');+ expect(stripAscii(output).split('\n')[2]).toBe('××T');});test('should fail on unexpected pass with retries', async ({ runInlineTest }) => {@@ -103,7 +103,7 @@ test('should retry unexpected pass', async ({ runInlineTest }) => {expect(exitCode).toBe(1);expect(passed).toBe(0);expect(failed).toBe(1);- expect(stripAscii(output).split('\n')[0]).toBe('××F');+ expect(stripAscii(output).split('\n')[2]).toBe('××F');});test('should not retry expected failure', async ({ runInlineTest }) => {@@ -123,7 +123,7 @@ test('should not retry expected failure', async ({ runInlineTest }) => {expect(exitCode).toBe(0);expect(passed).toBe(2);expect(failed).toBe(0);- expect(stripAscii(output).split('\n')[0]).toBe('··');+ expect(stripAscii(output).split('\n')[2]).toBe('··');});test('should retry unhandled rejection', async ({ runInlineTest }) => {@@ -141,7 +141,7 @@ test('should retry unhandled rejection', async ({ runInlineTest }) => {expect(result.exitCode).toBe(1);expect(result.passed).toBe(0);expect(result.failed).toBe(1);- expect(stripAscii(result.output).split('\n')[0]).toBe('××F');+ expect(stripAscii(result.output).split('\n')[2]).toBe('××F');expect(result.output).toContain('Unhandled rejection');});@@ -162,7 +162,7 @@ test('should retry beforeAll failure', async ({ runInlineTest }) => {expect(result.passed).toBe(0);expect(result.failed).toBe(1);expect(result.skipped).toBe(1);- expect(stripAscii(result.output).split('\n')[0]).toBe('×°×°F°');+ expect(stripAscii(result.output).split('\n')[2]).toBe('×°×°F°');expect(result.output).toContain('BeforeAll is bugged!');});@@ -184,6 +184,6 @@ test('should retry worker fixture setup failure', async ({ runInlineTest }) => {expect(result.exitCode).toBe(1);expect(result.passed).toBe(0);expect(result.failed).toBe(1);- expect(stripAscii(result.output).split('\n')[0]).toBe('××F');+ expect(stripAscii(result.output).split('\n')[2]).toBe('××F');expect(result.output).toContain('worker setup is bugged!');});