chore: make Reporter.onExit an internal method (#16280)

This commit is contained in:
Dmitry Gozman 2022-08-05 13:41:00 -07:00 committed by GitHub
parent 7a16e1e238
commit 1f40e3d22b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 38 deletions

View file

@ -140,12 +140,6 @@ Called on some global error, for example unhandled exception in the worker proce
The 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.10

View file

@ -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;

View file

@ -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, JsonTestResul
import 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;

View file

@ -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) {

View file

@ -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;
}

View file

@ -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>;
}

View file

@ -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.