Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore: add configDir to reporter options (#22250)

Yury Semikhatsky1ea9f02944a6
diff --git a/packages/playwright-test/src/reporters/html.ts b/packages/playwright-test/src/reporters/html.ts
index ffc617b9b6..a2ad7136f6 100644
--- a/packages/playwright-test/src/reporters/html.ts
+++ b/packages/playwright-test/src/reporters/html.ts
@@ -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',
};
}
diff --git a/packages/playwright-test/src/runner/reporters.ts b/packages/playwright-test/src/runner/reporters.ts
index cb8ee06c0e..66edb08bd7 100644
--- a/packages/playwright-test/src/runner/reporters.ts
+++ b/packages/playwright-test/src/runner/reporters.ts
@@ -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);