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

View File

@ -48,11 +48,12 @@ export async function createReporter(config: FullConfigInternal, mode: 'list' |
} else {
for (const r of config.reporter) {
const [name, arg] = r;
const options = { ...arg, configDir: config._internal.configDir };
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 {
const reporterConstructor = await loadReporter(config, name);
reporters.push(new reporterConstructor(arg));
reporters.push(new reporterConstructor(options));
}
}
reporters.push(...additionalReporters);