chore: remove private config usage from telereporter (#29771)

This commit is contained in:
Pavel Feldman 2024-03-01 13:14:12 -08:00 committed by GitHub
parent d0cc5871d8
commit bbcc3c1238
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 24 additions and 28 deletions

View File

@ -58,11 +58,6 @@ export class FullConfigInternal {
testIdMatcher?: Matcher;
defineConfigWasUsed = false;
// TODO: when merging reports, there could be no internal config. This is very unfortunate.
static from(config: FullConfig): FullConfigInternal | undefined {
return (config as any)[configInternalSymbol];
}
constructor(location: ConfigLocation, userConfig: Config, configCLIOverrides: ConfigCLIOverrides) {
if (configCLIOverrides.projects && userConfig.projects)
throw new Error(`Cannot use --browser option when configuration file defines projects. Specify browserName in the projects instead.`);

View File

@ -26,9 +26,7 @@ export type JsonStackFrame = { file: string, line: number, column: number };
export type JsonStdIOType = 'stdout' | 'stderr';
export type JsonConfig = Pick<reporterTypes.FullConfig, 'configFile' | 'globalTimeout' | 'maxFailures' | 'metadata' | 'rootDir' | 'version' | 'workers'> & {
listOnly: boolean;
};
export type JsonConfig = Pick<reporterTypes.FullConfig, 'configFile' | 'globalTimeout' | 'maxFailures' | 'metadata' | 'rootDir' | 'version' | 'workers'>;
export type MergeReporterConfig = Pick<reporterTypes.FullConfig, 'configFile' | 'quiet' | 'reportSlowTests' | 'rootDir' | 'reporter' >;
@ -147,10 +145,11 @@ export class TeleReporterReceiver {
this._reportConfig = reportConfig;
}
dispatch(message: JsonEvent): Promise<void> | void {
dispatch(mode: 'list' | 'test', message: JsonEvent): Promise<void> | void {
const { method, params } = message;
if (method === 'onConfigure') {
this._onConfigure(params.config);
this._listOnly = mode === 'list';
return;
}
if (method === 'onProject') {
@ -197,7 +196,6 @@ export class TeleReporterReceiver {
private _onConfigure(config: JsonConfig) {
this._rootDir = config.rootDir;
this._listOnly = config.listOnly;
this._config = this._parseConfig(config);
this._reporter.onConfigure?.(this._config);
}

View File

@ -30,7 +30,6 @@ import type { ZipFile } from 'playwright-core/lib/zipBundle';
import { yazl } from 'playwright-core/lib/zipBundle';
import { mime } from 'playwright-core/lib/utilsBundle';
import type { HTMLReport, Stats, TestAttachment, TestCase, TestCaseSummary, TestFile, TestFileSummary, TestResult, TestStep } from '@html-reporter/types';
import { FullConfigInternal } from '../common/config';
import EmptyReporter from './empty';
type TestEntry = {
@ -52,6 +51,7 @@ type HtmlReporterOptions = {
host?: string,
port?: number,
attachmentsBaseURL?: string,
_mode?: string;
};
class HtmlReporter extends EmptyReporter {
@ -124,12 +124,11 @@ class HtmlReporter extends EmptyReporter {
override async onExit() {
if (process.env.CI || !this._buildResult)
return;
const { ok, singleTestId } = this._buildResult;
const shouldOpen = this._open === 'always' || (!ok && this._open === 'on-failure');
if (shouldOpen) {
await showHTMLReport(this._outputFolder, this._options.host, this._options.port, singleTestId);
} else if (!FullConfigInternal.from(this.config)?.cliListOnly) {
} else if (this._options._mode === 'run') {
const packageManagerCommand = getPackageManagerExecCommand();
const relativeReportPath = this._outputFolder === standaloneDefaultFolder() ? '' : ' ' + path.relative(process.cwd(), this._outputFolder);
const hostArg = this._options.host ? ` --host ${this._options.host}` : '';

View File

@ -60,7 +60,7 @@ export async function createMergedReport(config: FullConfigInternal, dir: string
for (const event of events) {
if (event.method === 'onEnd')
printStatus(`building final report`);
await receiver.dispatch(event);
await receiver.dispatch('test', event);
if (event.method === 'onEnd')
printStatus(`finished building report`);
}
@ -248,7 +248,6 @@ function mergeConfigureEvents(configureEvents: JsonEvent[], rootDirOverride: str
rootDir: '',
version: '',
workers: 0,
listOnly: false
};
for (const event of configureEvents)
config = mergeConfigs(config, event.params.config);

View File

@ -17,7 +17,7 @@
import path from 'path';
import { createGuid } from 'playwright-core/lib/utils';
import type { FullConfig, FullResult, Location, Suite, TestCase, TestError, TestResult, TestStep } from '../../types/testReporter';
import { FullConfigInternal, getProjectId } from '../common/config';
import { getProjectId } from '../common/config';
import type { JsonAttachment, JsonConfig, JsonEvent, JsonFullResult, JsonProject, JsonStdIOType, JsonSuite, JsonTestCase, JsonTestEnd, JsonTestResultEnd, JsonTestResultStart, JsonTestStepEnd, JsonTestStepStart } from '../isomorphic/teleReceiver';
import { serializeRegexPatterns } from '../isomorphic/teleReceiver';
import type { ReporterV2 } from './reporterV2';
@ -152,7 +152,6 @@ export class TeleReporterEmitter implements ReporterV2 {
rootDir: config.rootDir,
version: config.version,
workers: config.workers,
listOnly: !!FullConfigInternal.from(config)?.cliListOnly,
};
}

View File

@ -50,9 +50,10 @@ export async function createReporters(config: FullConfigInternal, mode: 'list' |
descriptions ??= config.config.reporter;
if (config.configCLIOverrides.additionalReporters)
descriptions = [...descriptions, ...config.configCLIOverrides.additionalReporters];
const runOptions = { configDir: config.configDir, _mode: mode };
for (const r of descriptions) {
const [name, arg] = r;
const options = { ...arg, configDir: config.configDir };
const options = { ...runOptions, ...arg };
if (name in defaultReporters) {
reporters.push(new defaultReporters[name as keyof typeof defaultReporters](options));
} else {
@ -62,7 +63,7 @@ export async function createReporters(config: FullConfigInternal, mode: 'list' |
}
if (process.env.PW_TEST_REPORTER) {
const reporterConstructor = await loadReporter(config, process.env.PW_TEST_REPORTER);
reporters.push(wrapReporterAsV2(new reporterConstructor()));
reporters.push(wrapReporterAsV2(new reporterConstructor(runOptions)));
}
const someReporterPrintsToStdio = reporters.some(r => r.printsToStdio());

View File

@ -167,7 +167,7 @@ class UIMode {
}
private async _listTests() {
const reporter = new InternalReporter(new TeleReporterEmitter(e => this._dispatchEvent(e.method, e.params), true));
const reporter = new InternalReporter(new TeleReporterEmitter(e => this._dispatchEvent('listReport', e), true));
this._config.cliListOnly = true;
this._config.testIdMatcher = undefined;
const taskRunner = createTaskRunnerForList(this._config, reporter, 'out-of-process', { failOnLoadErrors: false });
@ -195,7 +195,7 @@ class UIMode {
this._config.testIdMatcher = id => !testIdSet || testIdSet.has(id);
const reporters = await createReporters(this._config, 'ui');
reporters.push(new TeleReporterEmitter(e => this._dispatchEvent(e.method, e.params), true));
reporters.push(new TeleReporterEmitter(e => this._dispatchEvent('testReport', e), true));
const reporter = new InternalReporter(new Multiplexer(reporters));
const taskRunner = createTaskRunnerForWatch(this._config, reporter);
const testRun = new TestRun(this._config, reporter);

View File

@ -737,10 +737,15 @@ const dispatchEvent = (method: string, params?: any) => {
return;
}
// The order of receiver dispatches matters here, we want to assign `lastRunTestCount`
// before we use it.
lastRunReceiver?.dispatch({ method, params })?.catch(() => {});
receiver?.dispatch({ method, params })?.catch(() => {});
if (method === 'listReport')
receiver?.dispatch('list', params)?.catch(() => {});
if (method === 'testReport') {
// The order of receiver dispatches matters here, we want to assign `lastRunTestCount`
// before we use it.
lastRunReceiver?.dispatch('test', params)?.catch(() => {});
receiver?.dispatch('test', params)?.catch(() => {});
}
};
const outputDirForTestCase = (testCase: TestCase): string | undefined => {

View File

@ -212,7 +212,7 @@ test('should merge into html with dependencies', async ({ runInlineTest, mergeRe
const { exitCode, output } = await mergeReports(reportDir, { 'PW_TEST_HTML_REPORT_OPEN': 'never' }, { additionalArgs: ['--reporter', 'html'] });
expect(exitCode).toBe(0);
expect(output).toContain('To open last HTML report run:');
expect(output).not.toContain('To open last HTML report run:');
await showReport();
@ -377,7 +377,7 @@ test('total time is from test run not from merge', async ({ runInlineTest, merge
const { exitCode, output } = await mergeReports(reportDir, { 'PW_TEST_HTML_REPORT_OPEN': 'never' }, { additionalArgs: ['--reporter', 'html'] });
expect(exitCode).toBe(0);
expect(output).toContain('To open last HTML report run:');
expect(output).not.toContain('To open last HTML report run:');
await showReport();
@ -1152,7 +1152,7 @@ test('preserve steps in html report', async ({ runInlineTest, mergeReports, show
const { exitCode, output } = await mergeReports(reportDir, { 'PW_TEST_HTML_REPORT_OPEN': 'never' }, { additionalArgs: ['--reporter', 'html'], cwd: mergeCwd });
expect(exitCode).toBe(0);
expect(output).toContain('To open last HTML report run:');
expect(output).not.toContain('To open last HTML report run:');
await showReport();