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

This commit is contained in:
Yury Semikhatsky 2023-08-01 16:06:06 -07:00 committed by GitHub
parent 29e63d1deb
commit f5d069541d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -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',

View File

@ -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);
});