From 9c30e766f5d1aa972c59b37fa2ccaf844460a1de Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Thu, 25 Apr 2024 17:55:31 -0700 Subject: [PATCH] Add 2 more env variables --- docs/src/test-reporters-js.md | 8 ++++ packages/playwright/src/reporters/blob.ts | 10 +++- tests/playwright-test/reporter-blob.spec.ts | 51 +++++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/docs/src/test-reporters-js.md b/docs/src/test-reporters-js.md index 4fffcadf57..eb3e5218dd 100644 --- a/docs/src/test-reporters-js.md +++ b/docs/src/test-reporters-js.md @@ -225,6 +225,14 @@ export default defineConfig({ }); ``` +Blob report supports following configuration options and environment variables: + +| Environment Variable Name | Reporter Config Option| Description | Default +|---|---|---|---| +| `PLAYWRIGHT_BLOB_OUTPUT_DIR` | `outputDir` | Directory to save the output. Existing content is deleted before writing the new report. | `blob-report` +| `PLAYWRIGHT_BLOB_OUTPUT_NAME` | `fileName` | File name for the output. | `report--.zip` +| `PLAYWRIGHT_BLOB_OUTPUT_FILE` | `outputFile` | Full path for the output. If defined, `outputDir` and `fileName` will be overridden | `undefined` + ### JSON reporter JSON reporter produces an object with all information about the test run. diff --git a/packages/playwright/src/reporters/blob.ts b/packages/playwright/src/reporters/blob.ts index 33c642b65b..f2db23e1d3 100644 --- a/packages/playwright/src/reporters/blob.ts +++ b/packages/playwright/src/reporters/blob.ts @@ -112,8 +112,8 @@ export class BlobReporter extends TeleReporterEmitter { outputFile = path.resolve(this._options.configDir, this._options.outputFile); // Explicit `outputFile` overrides `outputDir` and `fileName` options. if (!outputFile) { - const reportName = this._options.fileName || this._defaultReportName(this._config); - const outputDir = resolveReporterOutputPath('blob-report', this._options.configDir, this._options.outputDir); + const reportName = this._options.fileName || process.env[`PLAYWRIGHT_BLOB_OUTPUT_NAME`] || this._defaultReportName(this._config); + const outputDir = resolveReporterOutputPath('blob-report', this._options.configDir, this._options.outputDir ?? reportOutputDirFromEnv()); if (!process.env.PWTEST_BLOB_DO_NOT_REMOVE) await removeFolders([outputDir]); outputFile = path.resolve(outputDir, reportName); @@ -150,6 +150,12 @@ export class BlobReporter extends TeleReporterEmitter { } } +function reportOutputDirFromEnv(): string | undefined { + if (process.env[`PLAYWRIGHT_BLOB_OUTPUT_DIR`]) + return path.resolve(process.cwd(), process.env[`PLAYWRIGHT_BLOB_OUTPUT_DIR`]); + return undefined; +} + function reportOutputFileFromEnv(): string | undefined { if (process.env[`PLAYWRIGHT_BLOB_OUTPUT_FILE`]) return path.resolve(process.cwd(), process.env[`PLAYWRIGHT_BLOB_OUTPUT_FILE`]); diff --git a/tests/playwright-test/reporter-blob.spec.ts b/tests/playwright-test/reporter-blob.spec.ts index 423cd1ca18..6ed8fdf9e7 100644 --- a/tests/playwright-test/reporter-blob.spec.ts +++ b/tests/playwright-test/reporter-blob.spec.ts @@ -1198,7 +1198,57 @@ test('support fileName option', async ({ runInlineTest, mergeReports }) => { expect(reportFiles.sort()).toEqual(['report-one.zip', 'report-two.zip']); }); +test('support PLAYWRIGHT_BLOB_OUTPUT_DIR env variable', async ({ runInlineTest, mergeReports }) => { + test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30091' }); + const files = { + 'playwright.config.ts': ` + module.exports = { + reporter: [['blob']], + projects: [ + { name: 'foo' }, + ] + }; + `, + 'a.test.js': ` + import { test, expect } from '@playwright/test'; + test('math 1 @smoke', async ({}) => {}); + `, + }; + + await runInlineTest(files, undefined, { PLAYWRIGHT_BLOB_OUTPUT_DIR: 'my/dir' }); + + const reportDir = test.info().outputPath('my', 'dir'); + const reportFiles = await fs.promises.readdir(reportDir); + expect(reportFiles.sort()).toEqual(['report.zip']); +}); + +test('support PLAYWRIGHT_BLOB_OUTPUT_NAME env variable', async ({ runInlineTest, mergeReports }) => { + test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30091' }); + const files = { + 'playwright.config.ts': ` + module.exports = { + reporter: [['blob']], + projects: [ + { name: 'foo' }, + ] + }; + `, + 'a.test.js': ` + import { test, expect } from '@playwright/test'; + test('math 1 @smoke', async ({}) => {}); + `, + }; + + await runInlineTest(files, undefined, { PLAYWRIGHT_BLOB_OUTPUT_NAME: 'report-one.zip' }); + await runInlineTest(files, undefined, { PLAYWRIGHT_BLOB_OUTPUT_NAME: 'report-two.zip', PWTEST_BLOB_DO_NOT_REMOVE: '1' }); + + const reportDir = test.info().outputPath('blob-report'); + const reportFiles = await fs.promises.readdir(reportDir); + expect(reportFiles.sort()).toEqual(['report-one.zip', 'report-two.zip']); +}); + test('support outputFile option', async ({ runInlineTest, mergeReports }) => { + test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30091' }); const files = (fileSuffix: string) => ({ 'playwright.config.ts': ` module.exports = { @@ -1223,6 +1273,7 @@ test('support outputFile option', async ({ runInlineTest, mergeReports }) => { }); test('support PLAYWRIGHT_BLOB_OUTPUT_FILE environment variable', async ({ runInlineTest, mergeReports }) => { + test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/30091' }); const files = { 'playwright.config.ts': ` module.exports = {