chore: add configDir to reporter options (#22250)

This commit is contained in:
Yury Semikhatsky 2023-04-06 14:23:47 -07:00 committed by GitHub
parent c36b96fd8c
commit 1ea9f02944
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 8 deletions

View file

@ -26,7 +26,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 '../common/types'; import type { Metadata } from '../common/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';
@ -41,6 +41,7 @@ const kMissingContentType = 'x-playwright/missing';
type HtmlReportOpenOption = 'always' | 'never' | 'on-failure'; type HtmlReportOpenOption = 'always' | 'never' | 'on-failure';
type HtmlReporterOptions = { type HtmlReporterOptions = {
configDir: string,
outputFolder?: string, outputFolder?: string,
open?: HtmlReportOpenOption, open?: HtmlReportOpenOption,
host?: string, host?: string,
@ -48,7 +49,7 @@ type HtmlReporterOptions = {
}; };
class HtmlReporter implements Reporter { class HtmlReporter implements Reporter {
private config!: FullConfigInternal; private config!: FullConfig;
private suite!: Suite; private suite!: Suite;
private _montonicStartTime: number = 0; private _montonicStartTime: number = 0;
private _options: HtmlReporterOptions; private _options: HtmlReporterOptions;
@ -56,7 +57,7 @@ class HtmlReporter implements Reporter {
private _open: string | undefined; private _open: string | undefined;
private _buildResult: { ok: boolean, singleTestId: string | undefined } | undefined; private _buildResult: { ok: boolean, singleTestId: string | undefined } | undefined;
constructor(options: HtmlReporterOptions = {}) { constructor(options: HtmlReporterOptions) {
this._options = options; this._options = options;
} }
@ -66,7 +67,7 @@ class HtmlReporter implements Reporter {
onBegin(config: FullConfig, suite: Suite) { onBegin(config: FullConfig, suite: Suite) {
this._montonicStartTime = monotonicTime(); this._montonicStartTime = monotonicTime();
this.config = config as FullConfigInternal; this.config = config;
const { outputFolder, open } = this._resolveOptions(); const { outputFolder, open } = this._resolveOptions();
this._outputFolder = outputFolder; this._outputFolder = outputFolder;
this._open = open; this._open = open;
@ -92,9 +93,9 @@ class HtmlReporter implements Reporter {
_resolveOptions(): { outputFolder: string, open: HtmlReportOpenOption } { _resolveOptions(): { outputFolder: string, open: HtmlReportOpenOption } {
let { outputFolder } = this._options; let { outputFolder } = this._options;
if (outputFolder) if (outputFolder)
outputFolder = path.resolve(this.config._internal.configDir, outputFolder); outputFolder = path.resolve(this._options.configDir, outputFolder);
return { return {
outputFolder: reportFolderFromEnv() ?? outputFolder ?? defaultReportFolder(this.config._internal.configDir), outputFolder: reportFolderFromEnv() ?? outputFolder ?? defaultReportFolder(this._options.configDir),
open: process.env.PW_TEST_HTML_REPORT_OPEN as any || this._options.open || 'on-failure', open: process.env.PW_TEST_HTML_REPORT_OPEN as any || this._options.open || 'on-failure',
}; };
} }

View file

@ -48,11 +48,12 @@ export async function createReporter(config: FullConfigInternal, mode: 'list' |
} else { } else {
for (const r of config.reporter) { for (const r of config.reporter) {
const [name, arg] = r; const [name, arg] = r;
const options = { ...arg, configDir: config._internal.configDir };
if (name in defaultReporters) { if (name in defaultReporters) {
reporters.push(new defaultReporters[name as keyof typeof defaultReporters](arg)); reporters.push(new defaultReporters[name as keyof typeof defaultReporters](options));
} else { } else {
const reporterConstructor = await loadReporter(config, name); const reporterConstructor = await loadReporter(config, name);
reporters.push(new reporterConstructor(arg)); reporters.push(new reporterConstructor(options));
} }
} }
reporters.push(...additionalReporters); reporters.push(...additionalReporters);