mirror of
https://github.com/microsoft/playwright.git
synced 2024-09-11 20:37:54 +03:00
fix(merge): include command hash into the report name (#30528)
Reference https://github.com/microsoft/playwright/issues/30091
This commit is contained in:
parent
4fa1030af6
commit
714235d6c8
@ -16,7 +16,7 @@
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { ManualPromise, calculateSha1, createGuid, getUserAgent, removeFolders } 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';
|
||||
@ -30,6 +30,7 @@ type BlobReporterOptions = {
|
||||
configDir: string;
|
||||
outputDir?: string;
|
||||
fileName?: string;
|
||||
_commandHash: string;
|
||||
};
|
||||
|
||||
export const currentBlobReportVersion = 2;
|
||||
@ -114,6 +115,8 @@ export class BlobReporter extends TeleReporterEmitter {
|
||||
if (process.env.PLAYWRIGHT_BLOB_FILE_NAME)
|
||||
return process.env.PLAYWRIGHT_BLOB_FILE_NAME;
|
||||
let reportName = 'report';
|
||||
if (this._options._commandHash)
|
||||
reportName += '-' + sanitizeForFilePath(this._options._commandHash);
|
||||
if (config.shard) {
|
||||
const paddedNumber = `${config.shard.current}`.padStart(`${config.shard.total}`.length, '0');
|
||||
reportName = `${reportName}-${paddedNumber}`;
|
||||
|
@ -32,6 +32,7 @@ import { loadReporter } from './loadUtils';
|
||||
import { BlobReporter } from '../reporters/blob';
|
||||
import type { ReporterDescription } from '../../types/test';
|
||||
import { type ReporterV2, wrapReporterAsV2 } from '../reporters/reporterV2';
|
||||
import { calculateSha1 } from 'playwright-core/lib/utils';
|
||||
|
||||
export async function createReporters(config: FullConfigInternal, mode: 'list' | 'test' | 'merge', isTestServer: boolean, descriptions?: ReporterDescription[]): Promise<ReporterV2[]> {
|
||||
const defaultReporters: { [key in BuiltInReporter]: new(arg: any) => ReporterV2 } = {
|
||||
@ -90,9 +91,27 @@ function reporterOptions(config: FullConfigInternal, mode: 'list' | 'test' | 'me
|
||||
configDir: config.configDir,
|
||||
_mode: mode,
|
||||
_isTestServer: isTestServer,
|
||||
_commandHash: computeCommandHash(config),
|
||||
};
|
||||
}
|
||||
|
||||
function computeCommandHash(config: FullConfigInternal) {
|
||||
const parts = [];
|
||||
// Include project names for readability.
|
||||
if (config.cliProjectFilter)
|
||||
parts.push(...config.cliProjectFilter);
|
||||
const command = {} as any;
|
||||
if (config.cliArgs.length)
|
||||
command.cliArgs = config.cliArgs;
|
||||
if (config.cliGrep)
|
||||
command.cliGrep = config.cliGrep;
|
||||
if (config.cliGrepInvert)
|
||||
command.cliGrepInvert = config.cliGrepInvert;
|
||||
if (Object.keys(command).length)
|
||||
parts.push(calculateSha1(JSON.stringify(command)).substring(0, 7));
|
||||
return parts.join('-');
|
||||
}
|
||||
|
||||
class ListModeReporter extends EmptyReporter {
|
||||
private config!: FullConfig;
|
||||
|
||||
|
@ -1826,3 +1826,35 @@ test('preserve static annotations when tests did not run', async ({ runInlineTes
|
||||
await page.goBack();
|
||||
}
|
||||
});
|
||||
|
||||
test('project filter in report name', async ({ runInlineTest }) => {
|
||||
const files = {
|
||||
'playwright.config.ts': `
|
||||
module.exports = {
|
||||
reporter: 'blob',
|
||||
projects: [
|
||||
{ name: 'foo' },
|
||||
{ name: 'b%/\\ar' },
|
||||
{ name: 'baz' },
|
||||
]
|
||||
};
|
||||
`,
|
||||
'a.test.js': `
|
||||
import { test, expect } from '@playwright/test';
|
||||
test('math 1 @smoke', async ({}) => {});
|
||||
`,
|
||||
};
|
||||
|
||||
const reportDir = test.info().outputPath('blob-report');
|
||||
|
||||
{
|
||||
await runInlineTest(files, { shard: `2/2`, project: 'foo' });
|
||||
const reportFiles = await fs.promises.readdir(reportDir);
|
||||
expect(reportFiles.sort()).toEqual(['report-foo-2.zip']);
|
||||
}
|
||||
{
|
||||
await runInlineTest(files, { shard: `1/2`, project: 'foo,b*r', grep: 'smoke' });
|
||||
const reportFiles = await fs.promises.readdir(reportDir);
|
||||
expect(reportFiles.sort()).toEqual(['report-foo-b-r-6d9d49e-1.zip']);
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user