Skip to content

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

chore(blob): add version to metadata (#24556)

Yury Semikhatskyf5d069541d2e
diff --git a/packages/playwright-test/src/reporters/blob.ts b/packages/playwright-test/src/reporters/blob.ts
index 151e7e548c..76cdfa3507 100644
--- a/packages/playwright-test/src/reporters/blob.ts
+++ b/packages/playwright-test/src/reporters/blob.ts
@@ -31,7 +31,10 @@ type BlobReporterOptions = {
outputDir?: string;
};
+const currentVersion = 1;
+
export type BlobReportMetadata = {
+ version: number;
projectSuffix?: string;
shard?: { total: number, current: number };
};
@@ -50,8 +53,9 @@ export class BlobReporter extends TeleReporterEmitter {
override onConfigure(config: FullConfig) {
const metadata: BlobReportMetadata = {
+ version: currentVersion,
projectSuffix: process.env.PWTEST_BLOB_SUFFIX,
- shard: config.shard ? config.shard : undefined,
+ shard: config.shard ?? undefined,
};
this._messages.push({
method: 'onBlobReportMetadata',
diff --git a/tests/playwright-test/reporter-blob.spec.ts b/tests/playwright-test/reporter-blob.spec.ts
index ca69e67466..469a7695a1 100644
--- a/tests/playwright-test/reporter-blob.spec.ts
+++ b/tests/playwright-test/reporter-blob.spec.ts
@@ -21,6 +21,7 @@ import url from 'url';
import type { HttpServer } from '../../packages/playwright-core/src/utils';
import { startHtmlReportServer } from '../../packages/playwright-test/lib/reporters/html';
import { expect as baseExpect, test as baseTest, stripAnsi } from './playwright-test-fixtures';
+import extractZip from '../../packages/playwright-core/bundles/zip/node_modules/extract-zip';
const DOES_NOT_SUPPORT_UTF8_IN_TERMINAL = process.platform === 'win32' && process.env.TERM_PROGRAM !== 'vscode' && !process.env.WT_SESSION;
const POSITIVE_STATUS_MARK = DOES_NOT_SUPPORT_UTF8_IN_TERMINAL ? 'ok' : '✓ ';
@@ -1159,3 +1160,28 @@ test('blob-report should be next to package.json', async ({ runInlineTest }, tes
expect(fs.existsSync(testInfo.outputPath('foo', 'bar', 'blob-report'))).toBe(false);
expect(fs.existsSync(testInfo.outputPath('foo', 'bar', 'baz', 'tests', 'blob-report'))).toBe(false);
});
+
+test('blob-report should include version', async ({ runInlineTest }) => {
+ const reportDir = test.info().outputPath('blob-report');
+ const files = {
+ 'playwright.config.ts': `
+ module.exports = {
+ reporter: [['blob']]
+ };
+ `,
+ 'tests/a.test.js': `
+ import { test, expect } from '@playwright/test';
+ test('test 1', async ({}) => {});
+ `,
+ };
+ await runInlineTest(files);
+ const reportFiles = await fs.promises.readdir(reportDir);
+ expect(reportFiles).toEqual([expect.stringMatching(/report-.*.zip/)]);
+
+ await extractZip(test.info().outputPath('blob-report', reportFiles[0]), { dir: test.info().outputPath('blob-report') });
+ const reportFile = test.info().outputPath('blob-report', reportFiles[0].replace(/\.zip$/, '.jsonl'));
+ const data = await fs.promises.readFile(reportFile, 'utf8');
+ const events = data.split('\n').filter(Boolean).map(line => JSON.parse(line));
+ const metadataEvent = events.find(e => e.method === 'onBlobReportMetadata');
+ expect(metadataEvent.params.version).toBe(1);
+});