chore(blob): store playwright user agent (#26337)

This commit is contained in:
Yury Semikhatsky 2023-08-08 10:39:48 -07:00 committed by GitHub
parent 0e20d352cf
commit 8fcb6383ce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -16,7 +16,7 @@
import fs from 'fs';
import path from 'path';
import { ManualPromise, calculateSha1, createGuid, removeFolders, sanitizeForFilePath } from 'playwright-core/lib/utils';
import { ManualPromise, calculateSha1, createGuid, getUserAgent, removeFolders, sanitizeForFilePath } from 'playwright-core/lib/utils';
import { mime } from 'playwright-core/lib/utilsBundle';
import { Readable } from 'stream';
import type { EventEmitter } from 'events';
@ -35,6 +35,7 @@ export const currentBlobReportVersion = 1;
export type BlobReportMetadata = {
version: number;
userAgent: string;
name?: string;
shard?: { total: number, current: number };
};
@ -55,6 +56,7 @@ export class BlobReporter extends TeleReporterEmitter {
override onConfigure(config: FullConfig) {
const metadata: BlobReportMetadata = {
version: currentBlobReportVersion,
userAgent: getUserAgent(),
name: process.env.PWTEST_BLOB_REPORT_NAME,
shard: config.shard ?? undefined,
};

View file

@ -23,6 +23,7 @@ import { startHtmlReportServer } from '../../packages/playwright-test/lib/report
import { expect as baseExpect, test as baseTest, stripAnsi } from './playwright-test-fixtures';
import extractZip from '../../packages/playwright-core/bundles/zip/node_modules/extract-zip';
import * as yazl from '../../packages/playwright-core/bundles/zip/node_modules/yazl';
import { getUserAgent } from '../../packages/playwright-core/lib/utils/userAgent';
import { Readable } from 'stream';
const DOES_NOT_SUPPORT_UTF8_IN_TERMINAL = process.platform === 'win32' && process.env.TERM_PROGRAM !== 'vscode' && !process.env.WT_SESSION;
@ -1200,7 +1201,8 @@ test('blob report should include version', async ({ runInlineTest }) => {
test('test 1', async ({}) => {});
`,
};
await runInlineTest(files);
// CI/1 is a part of user agent string, make sure it matches in the nested test runner.
await runInlineTest(files, undefined, { CI: process.env.CI });
const reportFiles = await fs.promises.readdir(reportDir);
expect(reportFiles).toEqual(['report.zip']);
@ -1210,6 +1212,7 @@ test('blob report should include version', async ({ runInlineTest }) => {
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);
expect(metadataEvent.params.userAgent).toBe(getUserAgent());
});
test('merge-reports should throw if report version is from the future', async ({ runInlineTest, mergeReports }) => {