chore: make Reporter.onExit an internal method (#16280)
This commit is contained in:
parent
7a16e1e238
commit
1f40e3d22b
|
|
@ -140,12 +140,6 @@ Called on some global error, for example unhandled exception in the worker proce
|
||||||
The error.
|
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
|
## optional method: Reporter.onStdErr
|
||||||
* since: v1.10
|
* since: v1.10
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,8 @@
|
||||||
import { colors, ms as milliseconds, parseStackTraceLine } from 'playwright-core/lib/utilsBundle';
|
import { colors, ms as milliseconds, parseStackTraceLine } from 'playwright-core/lib/utilsBundle';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import type { FullConfig, TestCase, Suite, TestResult, TestError, Reporter, FullResult, TestStep, Location } from '../../types/testReporter';
|
import type { FullConfig, TestCase, Suite, TestResult, TestError, FullResult, TestStep, Location } from '../../types/testReporter';
|
||||||
import type { FullConfigInternal } from '../types';
|
import type { FullConfigInternal, ReporterInternal } from '../types';
|
||||||
import { codeFrameColumns } from '../babelBundle';
|
import { codeFrameColumns } from '../babelBundle';
|
||||||
|
|
||||||
export type TestResultOutput = { chunk: string | Buffer, type: 'stdout' | 'stderr' };
|
export type TestResultOutput = { chunk: string | Buffer, type: 'stdout' | 'stderr' };
|
||||||
|
|
@ -45,7 +45,7 @@ type TestSummary = {
|
||||||
fatalErrors: TestError[];
|
fatalErrors: TestError[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export class BaseReporter implements Reporter {
|
export class BaseReporter implements ReporterInternal {
|
||||||
duration = 0;
|
duration = 0;
|
||||||
config!: FullConfigInternal;
|
config!: FullConfigInternal;
|
||||||
suite!: Suite;
|
suite!: Suite;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import { open } from '../utilsBundle';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import type { TransformCallback } from 'stream';
|
import type { TransformCallback } from 'stream';
|
||||||
import { Transform } 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 { HttpServer } from 'playwright-core/lib/utils/httpServer';
|
||||||
import { assert, calculateSha1 } from 'playwright-core/lib/utils';
|
import { assert, calculateSha1 } from 'playwright-core/lib/utils';
|
||||||
import { removeFolders } from 'playwright-core/lib/utils/fileUtils';
|
import { removeFolders } from 'playwright-core/lib/utils/fileUtils';
|
||||||
|
|
@ -28,7 +28,7 @@ import type { JsonAttachment, JsonReport, JsonSuite, JsonTestCase, JsonTestResul
|
||||||
import RawReporter from './raw';
|
import RawReporter from './raw';
|
||||||
import { stripAnsiEscapes } from './base';
|
import { stripAnsiEscapes } from './base';
|
||||||
import { getPackageJsonPath, sanitizeForFilePath } from '../util';
|
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 type { ZipFile } from 'playwright-core/lib/zipBundle';
|
||||||
import { yazl } from 'playwright-core/lib/zipBundle';
|
import { yazl } from 'playwright-core/lib/zipBundle';
|
||||||
import { mime } from 'playwright-core/lib/utilsBundle';
|
import { mime } from 'playwright-core/lib/utilsBundle';
|
||||||
|
|
@ -131,7 +131,7 @@ type HtmlReporterOptions = {
|
||||||
open?: HtmlReportOpenOption,
|
open?: HtmlReportOpenOption,
|
||||||
};
|
};
|
||||||
|
|
||||||
class HtmlReporter implements Reporter {
|
class HtmlReporter implements ReporterInternal {
|
||||||
private config!: FullConfigInternal;
|
private config!: FullConfigInternal;
|
||||||
private suite!: Suite;
|
private suite!: Suite;
|
||||||
private _options: HtmlReporterOptions;
|
private _options: HtmlReporterOptions;
|
||||||
|
|
@ -193,7 +193,7 @@ class HtmlReporter implements Reporter {
|
||||||
this._buildResult = await builder.build(this.config.metadata, reports);
|
this._buildResult = await builder.build(this.config.metadata, reports);
|
||||||
}
|
}
|
||||||
|
|
||||||
async onExit() {
|
async _onExit() {
|
||||||
if (process.env.CI)
|
if (process.env.CI)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,13 @@
|
||||||
* limitations under the License.
|
* 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 {
|
export class Multiplexer implements ReporterInternal {
|
||||||
private _reporters: Reporter[];
|
private _reporters: ReporterInternal[];
|
||||||
|
|
||||||
constructor(reporters: Reporter[]) {
|
constructor(reporters: ReporterInternal[]) {
|
||||||
this._reporters = reporters;
|
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));
|
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)
|
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) {
|
onError(error: TestError) {
|
||||||
|
|
@ -76,14 +77,6 @@ export class Multiplexer implements Reporter {
|
||||||
for (const reporter of this._reporters)
|
for (const reporter of this._reporters)
|
||||||
(reporter as any).onStepEnd?.(test, result, step);
|
(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) {
|
function wrap(callback: () => void) {
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import JSONReporter from './reporters/json';
|
||||||
import JUnitReporter from './reporters/junit';
|
import JUnitReporter from './reporters/junit';
|
||||||
import EmptyReporter from './reporters/empty';
|
import EmptyReporter from './reporters/empty';
|
||||||
import HtmlReporter from './reporters/html';
|
import HtmlReporter from './reporters/html';
|
||||||
import type { Config, FullProjectInternal } from './types';
|
import type { Config, FullProjectInternal, ReporterInternal } from './types';
|
||||||
import type { FullConfigInternal } from './types';
|
import type { FullConfigInternal } from './types';
|
||||||
import { raceAgainstTimeout } from 'playwright-core/lib/utils/timeoutRunner';
|
import { raceAgainstTimeout } from 'playwright-core/lib/utils/timeoutRunner';
|
||||||
import { SigIntWatcher } from './sigIntWatcher';
|
import { SigIntWatcher } from './sigIntWatcher';
|
||||||
|
|
@ -85,7 +85,7 @@ type WatchProgress = {
|
||||||
|
|
||||||
export class Runner {
|
export class Runner {
|
||||||
private _loader: Loader;
|
private _loader: Loader;
|
||||||
private _reporter!: Reporter;
|
private _reporter!: ReporterInternal;
|
||||||
private _plugins: TestRunnerPlugin[] = [];
|
private _plugins: TestRunnerPlugin[] = [];
|
||||||
private _watchRepeatEachIndex = 0;
|
private _watchRepeatEachIndex = 0;
|
||||||
private _watchJobsQueue = Promise.resolve();
|
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.stdout.write('', () => resolve()));
|
||||||
await new Promise<void>(resolve => process.stderr.write('', () => resolve()));
|
await new Promise<void>(resolve => process.stderr.write('', () => resolve()));
|
||||||
|
|
||||||
await this._reporter.onExit?.();
|
await this._reporter._onExit?.();
|
||||||
return fullResult;
|
return fullResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import type { Fixtures, TestError, Project } from '../types/test';
|
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 { WorkerIsolation } from './ipc';
|
||||||
import type { FullConfig as FullConfigPublic, FullProject as FullProjectPublic } from './types';
|
import type { FullConfig as FullConfigPublic, FullProject as FullProjectPublic } from './types';
|
||||||
export * from '../types/test';
|
export * from '../types/test';
|
||||||
|
|
@ -71,3 +71,7 @@ export interface FullProjectInternal extends FullProjectPublic {
|
||||||
_projectSetup?: string;
|
_projectSetup?: string;
|
||||||
_projectTeardown?: string;
|
_projectTeardown?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ReporterInternal extends Reporter {
|
||||||
|
_onExit?(): void | Promise<void>;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -385,13 +385,6 @@ export interface Reporter {
|
||||||
*/
|
*/
|
||||||
onError?(error: TestError): void;
|
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.
|
* Called when something has been written to the standard error in the worker process.
|
||||||
* @param chunk Output chunk.
|
* @param chunk Output chunk.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue