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
chore: make Reporter.onExit an internal method (#16280)
Dmitry Gozman1f40e3d22bec
diff --git a/docs/src/test-reporter-api/class-reporter.md b/docs/src/test-reporter-api/class-reporter.mdindex 5f62ac5530..ef16d278b7 100644--- a/docs/src/test-reporter-api/class-reporter.md+++ b/docs/src/test-reporter-api/class-reporter.md@@ -140,12 +140,6 @@ Called on some global error, for example unhandled exception in the worker proceThe error.-## optional async method: Reporter.onExit-* since: v1.25--Called before the test runner will terminate. Useful to perform work after all reporters have finished, for example open some UI. Fore regular reporting, you should use [`method: Reporter.onEnd`] instead.--## optional method: Reporter.onStdErr* since: v1.10diff --git a/packages/playwright-test/src/reporters/base.ts b/packages/playwright-test/src/reporters/base.tsindex 1a1771489a..9ad061a8fe 100644--- a/packages/playwright-test/src/reporters/base.ts+++ b/packages/playwright-test/src/reporters/base.ts@@ -17,8 +17,8 @@import { colors, ms as milliseconds, parseStackTraceLine } from 'playwright-core/lib/utilsBundle';import fs from 'fs';import path from 'path';-import type { FullConfig, TestCase, Suite, TestResult, TestError, Reporter, FullResult, TestStep, Location } from '../../types/testReporter';-import type { FullConfigInternal } from '../types';+import type { FullConfig, TestCase, Suite, TestResult, TestError, FullResult, TestStep, Location } from '../../types/testReporter';+import type { FullConfigInternal, ReporterInternal } from '../types';import { codeFrameColumns } from '../babelBundle';export type TestResultOutput = { chunk: string | Buffer, type: 'stdout' | 'stderr' };@@ -45,7 +45,7 @@ type TestSummary = {fatalErrors: TestError[];};-export class BaseReporter implements Reporter {+export class BaseReporter implements ReporterInternal {duration = 0;config!: FullConfigInternal;suite!: Suite;diff --git a/packages/playwright-test/src/reporters/html.ts b/packages/playwright-test/src/reporters/html.tsindex 2b9db8dc62..8ef1b4e3e0 100644--- a/packages/playwright-test/src/reporters/html.ts+++ b/packages/playwright-test/src/reporters/html.ts@@ -20,7 +20,7 @@ import { open } from '../utilsBundle';import path from 'path';import type { TransformCallback } from 'stream';import { Transform } from 'stream';-import type { FullConfig, Suite, Reporter } from '../../types/testReporter';+import type { FullConfig, Suite } from '../../types/testReporter';import { HttpServer } from 'playwright-core/lib/utils/httpServer';import { assert, calculateSha1 } from 'playwright-core/lib/utils';import { removeFolders } from 'playwright-core/lib/utils/fileUtils';@@ -28,7 +28,7 @@ import type { JsonAttachment, JsonReport, JsonSuite, JsonTestCase, JsonTestResulimport RawReporter from './raw';import { stripAnsiEscapes } from './base';import { getPackageJsonPath, sanitizeForFilePath } from '../util';-import type { FullConfigInternal, Metadata } from '../types';+import type { FullConfigInternal, Metadata, ReporterInternal } from '../types';import type { ZipFile } from 'playwright-core/lib/zipBundle';import { yazl } from 'playwright-core/lib/zipBundle';import { mime } from 'playwright-core/lib/utilsBundle';@@ -131,7 +131,7 @@ type HtmlReporterOptions = {open?: HtmlReportOpenOption,};-class HtmlReporter implements Reporter {+class HtmlReporter implements ReporterInternal {private config!: FullConfigInternal;private suite!: Suite;private _options: HtmlReporterOptions;@@ -193,7 +193,7 @@ class HtmlReporter implements Reporter {this._buildResult = await builder.build(this.config.metadata, reports);}- async onExit() {+ async _onExit() {if (process.env.CI)return;diff --git a/packages/playwright-test/src/reporters/multiplexer.ts b/packages/playwright-test/src/reporters/multiplexer.tsindex 4ad6a43beb..df55babd79 100644--- a/packages/playwright-test/src/reporters/multiplexer.ts+++ b/packages/playwright-test/src/reporters/multiplexer.ts@@ -14,12 +14,13 @@* limitations under the License.*/-import type { FullConfig, Suite, TestCase, TestError, TestResult, Reporter, FullResult, TestStep } from '../../types/testReporter';+import type { FullConfig, Suite, TestCase, TestError, TestResult, FullResult, TestStep } from '../../types/testReporter';+import type { ReporterInternal } from '../types';-export class Multiplexer implements Reporter {- private _reporters: Reporter[];+export class Multiplexer implements ReporterInternal {+ private _reporters: ReporterInternal[];- constructor(reporters: Reporter[]) {+ constructor(reporters: ReporterInternal[]) {this._reporters = reporters;}@@ -57,9 +58,9 @@ export class Multiplexer implements Reporter {await Promise.resolve().then(() => reporter.onEnd?.(result)).catch(e => console.error('Error in reporter', e));}- async onExit() {+ async _onExit() {for (const reporter of this._reporters)- await Promise.resolve().then(() => reporter.onExit?.()).catch(e => console.error('Error in reporter', e));+ await Promise.resolve().then(() => reporter._onExit?.()).catch(e => console.error('Error in reporter', e));}onError(error: TestError) {@@ -76,14 +77,6 @@ export class Multiplexer implements Reporter {for (const reporter of this._reporters)(reporter as any).onStepEnd?.(test, result, step);}-- _nextTest(): Promise<any | null> {- for (const reporter of this._reporters) {- if ((reporter as any)._nextTest)- return (reporter as any)._nextTest();- }- return Promise.resolve(null);- }}function wrap(callback: () => void) {diff --git a/packages/playwright-test/src/runner.ts b/packages/playwright-test/src/runner.tsindex 51b7c569e1..c16c5e7efd 100644--- a/packages/playwright-test/src/runner.ts+++ b/packages/playwright-test/src/runner.ts@@ -37,7 +37,7 @@ import JSONReporter from './reporters/json';import JUnitReporter from './reporters/junit';import EmptyReporter from './reporters/empty';import HtmlReporter from './reporters/html';-import type { Config, FullProjectInternal } from './types';+import type { Config, FullProjectInternal, ReporterInternal } from './types';import type { FullConfigInternal } from './types';import { raceAgainstTimeout } from 'playwright-core/lib/utils/timeoutRunner';import { SigIntWatcher } from './sigIntWatcher';@@ -85,7 +85,7 @@ type WatchProgress = {export class Runner {private _loader: Loader;- private _reporter!: Reporter;+ private _reporter!: ReporterInternal;private _plugins: TestRunnerPlugin[] = [];private _watchRepeatEachIndex = 0;private _watchJobsQueue = Promise.resolve();@@ -203,7 +203,7 @@ export class Runner {await new Promise<void>(resolve => process.stdout.write('', () => resolve()));await new Promise<void>(resolve => process.stderr.write('', () => resolve()));- await this._reporter.onExit?.();+ await this._reporter._onExit?.();return fullResult;}diff --git a/packages/playwright-test/src/types.ts b/packages/playwright-test/src/types.tsindex 8d9066b65f..79ed39d5b2 100644--- a/packages/playwright-test/src/types.ts+++ b/packages/playwright-test/src/types.ts@@ -15,7 +15,7 @@*/import type { Fixtures, TestError, Project } from '../types/test';-import type { Location } from '../types/testReporter';+import type { Location, Reporter } from '../types/testReporter';import type { WorkerIsolation } from './ipc';import type { FullConfig as FullConfigPublic, FullProject as FullProjectPublic } from './types';export * from '../types/test';@@ -71,3 +71,7 @@ export interface FullProjectInternal extends FullProjectPublic {_projectSetup?: string;_projectTeardown?: string;}++export interface ReporterInternal extends Reporter {+ _onExit?(): void | Promise<void>;+}diff --git a/packages/playwright-test/types/testReporter.d.ts b/packages/playwright-test/types/testReporter.d.tsindex beefad201c..ec1a2b1b73 100644--- a/packages/playwright-test/types/testReporter.d.ts+++ b/packages/playwright-test/types/testReporter.d.ts@@ -385,13 +385,6 @@ export interface Reporter {*/onError?(error: TestError): void;- /**- * Called before the test runner will terminate. Useful to perform work after all reporters have finished, for example open- * some UI. Fore regular reporting, you should use- * [reporter.onEnd(result)](https://playwright.dev/docs/api/class-reporter#reporter-on-end) instead.- */- onExit?(): Promise<void>;-/*** Called when something has been written to the standard error in the worker process.* @param chunk Output chunk.