chore: do not use project id in telereporter (#29776)

This commit is contained in:
Pavel Feldman 2024-03-01 21:44:08 -08:00 committed by GitHub
parent bbcc3c1238
commit ef924c14e7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 69 additions and 88 deletions

View File

@ -55,7 +55,7 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: npx playwright install --with-deps ${{ matrix.browser }} chromium
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }}
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }}-*
- run: node tests/config/checkCoverage.js ${{ matrix.browser }}
- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
if: always()
@ -87,7 +87,7 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: npx playwright install --with-deps chromium-tip-of-tree
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=chromium
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=chromium-*
env:
PWTEST_CHANNEL: chromium-tip-of-tree
PWTEST_BOT_NAME: "${{ matrix.os }}-chromium-tip-of-tree"

View File

@ -42,7 +42,7 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: npx playwright install --with-deps ${{ matrix.browser }} chromium
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }}
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }}-*
- run: node tests/config/checkCoverage.js ${{ matrix.browser }}
- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
if: always()
@ -75,7 +75,7 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: npx playwright install --with-deps ${{ matrix.browser }} chromium
- run: npm run test -- --project=${{ matrix.browser }}
- run: npm run test -- --project=${{ matrix.browser }}-*
- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
if: always()
shell: bash
@ -106,10 +106,10 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: npx playwright install --with-deps ${{ matrix.browser }} chromium
- run: npm run test -- --project=${{ matrix.browser }} --workers=1
- run: npm run test -- --project=${{ matrix.browser }}-* --workers=1
if: matrix.browser == 'firefox'
shell: bash
- run: npm run test -- --project=${{ matrix.browser }}
- run: npm run test -- --project=${{ matrix.browser }}-*
if: matrix.browser != 'firefox'
shell: bash
- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
@ -175,9 +175,9 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: npx playwright install --with-deps ${{ matrix.browser }} chromium
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }} --headed
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }}-* --headed
if: always() && startsWith(matrix.os, 'ubuntu-')
- run: npm run test -- --project=${{ matrix.browser }} --headed
- run: npm run test -- --project=${{ matrix.browser }}-* --headed
if: always() && !startsWith(matrix.os, 'ubuntu-')
- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json
if: always()
@ -247,7 +247,7 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: npx playwright install --with-deps ${{ matrix.browser }} chromium ${{ matrix.channel }}
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }}
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }}-*
env:
PWTEST_TRACE: 1
PWTEST_CHANNEL: ${{ matrix.channel }}
@ -868,7 +868,7 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: npx playwright install --with-deps chromium
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=chromium
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=chromium-*
env:
PLAYWRIGHT_CHROMIUM_USE_HEADLESS_NEW: 1
- run: node tests/config/checkCoverage.js chromium

View File

@ -23,7 +23,7 @@ jobs:
env:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }} --workers=10 --retries=0
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }}-* --workers=10 --retries=0
env:
PWTEST_MODE: service2
PWTEST_TRACE: 1

View File

@ -32,7 +32,7 @@ jobs:
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: 1
- run: npm run build
- run: npx playwright install --with-deps ${{ matrix.browser }} chromium
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }}
- run: xvfb-run --auto-servernum --server-args="-screen 0 1280x960x24" -- npm run test -- --project=${{ matrix.browser }}-*
env:
PWTEST_VIDEO: 1
- run: ./utils/upload_flakiness_dashboard.sh ./test-results/report.json

View File

@ -16,9 +16,9 @@
},
"license": "Apache-2.0",
"scripts": {
"ctest": "playwright test --config=tests/library/playwright.config.ts --project=chromium",
"ftest": "playwright test --config=tests/library/playwright.config.ts --project=firefox",
"wtest": "playwright test --config=tests/library/playwright.config.ts --project=webkit",
"ctest": "playwright test --config=tests/library/playwright.config.ts --project=chromium-*",
"ftest": "playwright test --config=tests/library/playwright.config.ts --project=firefox-*",
"wtest": "playwright test --config=tests/library/playwright.config.ts --project=webkit-*",
"atest": "playwright test --config=tests/android/playwright.config.ts",
"etest": "playwright test --config=tests/electron/playwright.config.ts",
"webview2test": "playwright test --config=tests/webview2/playwright.config.ts",

View File

@ -14,7 +14,6 @@
limitations under the License.
*/
import { testCaseLabels } from './labelUtils';
import type { TestCaseSummary } from './types';
export class Filter {
@ -108,13 +107,13 @@ export class Filter {
if (test.outcome === 'skipped')
status = 'skipped';
const searchValues: SearchValues = {
text: (status + ' ' + test.projectName + ' ' + (test.botName || '') + ' ' + test.location.file + ' ' + test.path.join(' ') + ' ' + test.title).toLowerCase(),
text: (status + ' ' + test.projectName + ' ' + test.tags.join(' ') + ' ' + test.location.file + ' ' + test.path.join(' ') + ' ' + test.title).toLowerCase(),
project: test.projectName.toLowerCase(),
status: status as any,
file: test.location.file,
line: String(test.location.line),
column: String(test.location.column),
labels: testCaseLabels(test).map(label => label.toLowerCase()),
labels: test.tags.map(tag => tag.toLowerCase()),
};
(test as any).searchValues = searchValues;
}

View File

@ -14,22 +14,6 @@
* limitations under the License.
*/
import type { TestCaseSummary } from './types';
const labelsSymbol = Symbol('labels');
// Note: all labels start with "@"
export function testCaseLabels(test: TestCaseSummary): string[] {
if (!(test as any)[labelsSymbol]) {
const labels: string[] = [];
if (test.botName)
labels.push('@' + test.botName);
labels.push(...test.tags);
(test as any)[labelsSymbol] = labels;
}
return (test as any)[labelsSymbol];
}
// hash string to integer in range [0, 6] for color index, to get same color for same tag
export function hashStringToInt(str: string) {
let hash = 0;

View File

@ -23,7 +23,7 @@ import { ProjectLink } from './links';
import { statusIcon } from './statusIcon';
import './testCaseView.css';
import { TestResultView } from './testResultView';
import { hashStringToInt, testCaseLabels } from './labelUtils';
import { hashStringToInt } from './labelUtils';
import { msToString } from './uiUtils';
export const TestCaseView: React.FC<{
@ -37,7 +37,7 @@ export const TestCaseView: React.FC<{
const labels = React.useMemo(() => {
if (!test)
return undefined;
return testCaseLabels(test);
return test.tags;
}, [test]);
return <div className='test-case-column vbox'>

View File

@ -23,7 +23,7 @@ import { generateTraceUrl, Link, navigate, ProjectLink } from './links';
import { statusIcon } from './statusIcon';
import './testFileView.css';
import { video, image, trace } from './icons';
import { hashStringToInt, testCaseLabels } from './labelUtils';
import { hashStringToInt } from './labelUtils';
export const TestFileView: React.FC<React.PropsWithChildren<{
report: HTMLReport;
@ -52,7 +52,7 @@ export const TestFileView: React.FC<React.PropsWithChildren<{
</Link>
{report.projectNames.length > 1 && !!test.projectName &&
<ProjectLink projectNames={report.projectNames} projectName={test.projectName} />}
<LabelsClickView labels={testCaseLabels(test)} />
<LabelsClickView labels={test.tags} />
</span>
</div>
<span data-testid='test-duration' style={{ minWidth: '50px', textAlign: 'right' }}>{msToString(test.duration)}</span>

View File

@ -36,7 +36,6 @@ export type JsonPattern = {
};
export type JsonProject = {
id: string;
grep: JsonPattern[];
grepInvert: JsonPattern[];
metadata: Metadata;
@ -132,16 +131,18 @@ export class TeleReporterReceiver {
private _rootDir!: string;
private _listOnly = false;
private _clearPreviousResultsWhenTestBegins: boolean = false;
private _reuseTestCases: boolean;
private _mergeTestCases: boolean;
private _mergeProjects: boolean;
private _reportConfig: MergeReporterConfig | undefined;
private _config!: reporterTypes.FullConfig;
private _stringPool = new StringInternPool();
constructor(pathSeparator: string, reporter: Partial<ReporterV2>, reuseTestCases: boolean, reportConfig?: MergeReporterConfig) {
constructor(pathSeparator: string, reporter: Partial<ReporterV2>, mergeProjects: boolean, mergeTestCases: boolean, reportConfig?: MergeReporterConfig) {
this._rootSuite = new TeleSuite('', 'root');
this._pathSeparator = pathSeparator;
this._reporter = reporter;
this._reuseTestCases = reuseTestCases;
this._mergeProjects = mergeProjects;
this._mergeTestCases = mergeTestCases;
this._reportConfig = reportConfig;
}
@ -201,7 +202,7 @@ export class TeleReporterReceiver {
}
private _onProject(project: JsonProject) {
let projectSuite = this._rootSuite.suites.find(suite => suite.project()!.__projectId === project.id);
let projectSuite = this._mergeProjects ? this._rootSuite.suites.find(suite => suite.project()!.name === project.name) : undefined;
if (!projectSuite) {
projectSuite = new TeleSuite(project.name, 'project');
this._rootSuite.suites.push(projectSuite);
@ -331,7 +332,6 @@ export class TeleReporterReceiver {
private _parseProject(project: JsonProject): TeleFullProject {
return {
__projectId: project.id,
metadata: project.metadata,
name: project.name,
outputDir: this._absolutePath(project.outputDir),
@ -375,7 +375,7 @@ export class TeleReporterReceiver {
private _mergeTestsInto(jsonTests: JsonTestCase[], parent: TeleSuite) {
for (const jsonTest of jsonTests) {
let targetTest = this._reuseTestCases ? parent.tests.find(s => s.title === jsonTest.title && s.repeatEachIndex === jsonTest.repeatEachIndex) : undefined;
let targetTest = this._mergeTestCases ? parent.tests.find(s => s.title === jsonTest.title && s.repeatEachIndex === jsonTest.repeatEachIndex) : undefined;
if (!targetTest) {
targetTest = new TeleTestCase(jsonTest.testId, jsonTest.title, this._absoluteLocation(jsonTest.location), jsonTest.repeatEachIndex);
targetTest.parent = parent;
@ -593,7 +593,7 @@ class TeleTestResult implements reporterTypes.TestResult {
}
}
export type TeleFullProject = FullProject & { __projectId: string };
export type TeleFullProject = FullProject;
export const baseFullConfig: reporterTypes.FullConfig = {
forbidOnly: false,

View File

@ -241,7 +241,7 @@ class HtmlBuilder {
}
const { testFile, testFileSummary } = fileEntry;
const testEntries: TestEntry[] = [];
this._processJsonSuite(fileSuite, fileId, projectSuite.project()!.name, projectSuite.project()!.metadata?.reportName, [], testEntries);
this._processJsonSuite(fileSuite, fileId, projectSuite.project()!.name, [], testEntries);
for (const test of testEntries) {
testFile.tests.push(test.testCase);
testFileSummary.tests.push(test.testCaseSummary);
@ -341,13 +341,13 @@ class HtmlBuilder {
this._dataZipFile.addBuffer(Buffer.from(JSON.stringify(data)), fileName);
}
private _processJsonSuite(suite: Suite, fileId: string, projectName: string, botName: string | undefined, path: string[], outTests: TestEntry[]) {
private _processJsonSuite(suite: Suite, fileId: string, projectName: string, path: string[], outTests: TestEntry[]) {
const newPath = [...path, suite.title];
suite.suites.forEach(s => this._processJsonSuite(s, fileId, projectName, botName, newPath, outTests));
suite.tests.forEach(t => outTests.push(this._createTestEntry(fileId, t, projectName, botName, newPath)));
suite.suites.forEach(s => this._processJsonSuite(s, fileId, projectName, newPath, outTests));
suite.tests.forEach(t => outTests.push(this._createTestEntry(fileId, t, projectName, newPath)));
}
private _createTestEntry(fileId: string, test: TestCasePublic, projectName: string, botName: string | undefined, path: string[]): TestEntry {
private _createTestEntry(fileId: string, test: TestCasePublic, projectName: string, path: string[]): TestEntry {
const duration = test.results.reduce((a, r) => a + r.duration, 0);
const location = this._relativeLocation(test.location)!;
path = path.slice(1);
@ -363,7 +363,6 @@ class HtmlBuilder {
testId,
title: test.title,
projectName,
botName,
location,
duration,
// Annotations can be pushed directly, with a wrong type.
@ -378,7 +377,6 @@ class HtmlBuilder {
testId,
title: test.title,
projectName,
botName,
location,
duration,
// Annotations can be pushed directly, with a wrong type.

View File

@ -23,7 +23,7 @@ import { TeleReporterReceiver } from '../isomorphic/teleReceiver';
import { JsonStringInternalizer, StringInternPool } from '../isomorphic/stringInternPool';
import { createReporters } from '../runner/reporters';
import { Multiplexer } from './multiplexer';
import { ZipFile, calculateSha1 } from 'playwright-core/lib/utils';
import { ZipFile } from 'playwright-core/lib/utils';
import { currentBlobReportVersion, type BlobReportMetadata } from './blob';
import { relativeFilePath } from '../util';
import type { TestError } from '../../types/testReporter';
@ -53,7 +53,7 @@ export async function createMergedReport(config: FullConfigInternal, dir: string
const eventData = await mergeEvents(dir, shardFiles, stringPool, printStatus, rootDirOverride);
// If expicit config is provided, use platform path separator, otherwise use the one from the report (if any).
const pathSep = rootDirOverride ? path.sep : (eventData.pathSeparatorFromMetadata ?? path.sep);
const receiver = new TeleReporterReceiver(pathSep, multiplexer, false, config.config);
const receiver = new TeleReporterReceiver(pathSep, multiplexer, false, false, config.config);
printStatus(`processing test events`);
const dispatchEvents = async (events: JsonEvent[]) => {
@ -183,22 +183,15 @@ async function mergeEvents(dir: string, shardReportFiles: string[], stringPool:
return a.file.localeCompare(b.file);
});
const saltSet = new Set<string>();
printStatus(`merging events`);
const reports: ReportData[] = [];
for (const { file, parsedEvents, metadata, localPath } of blobs) {
for (let i = 0; i < blobs.length; ++i) {
// Generate unique salt for each blob.
const sha1 = calculateSha1(metadata.name || path.basename(file)).substring(0, 16);
let salt = sha1;
for (let i = 0; saltSet.has(salt); i++)
salt = sha1 + '-' + i;
saltSet.add(salt);
const { parsedEvents, metadata, localPath } = blobs[i];
const eventPatchers = new JsonEventPatchers();
eventPatchers.patchers.push(new IdsPatcher(stringPool, metadata.name, salt));
eventPatchers.patchers.push(new IdsPatcher(stringPool, metadata.name, String(i)));
// Only patch path separators if we are merging reports with explicit config.
if (rootDirOverride)
eventPatchers.patchers.push(new PathSeparatorPatcher(metadata.pathSeparator));
@ -354,10 +347,14 @@ class UniqueFileNameGenerator {
}
class IdsPatcher {
constructor(
private _stringPool: StringInternPool,
private _reportName: string | undefined,
private _salt: string) {
private _stringPool: StringInternPool;
private _botName: string | undefined;
private _salt: string;
constructor(stringPool: StringInternPool, botName: string | undefined, salt: string) {
this._stringPool = stringPool;
this._botName = botName;
this._salt = salt;
}
patchEvent(event: JsonEvent) {
@ -380,13 +377,18 @@ class IdsPatcher {
private _onProject(project: JsonProject) {
project.metadata = project.metadata ?? {};
project.metadata.reportName = this._reportName;
project.id = this._stringPool.internString(project.id + this._salt);
project.metadata.botName = this._botName;
project.suites.forEach(suite => this._updateTestIds(suite));
}
private _updateTestIds(suite: JsonSuite) {
suite.tests.forEach(test => test.testId = this._mapTestId(test.testId));
suite.tests.forEach(test => {
test.testId = this._mapTestId(test.testId);
if (this._botName) {
test.tags = test.tags || [];
test.tags.unshift('@' + this._botName);
}
});
suite.suites.forEach(suite => this._updateTestIds(suite));
}

View File

@ -17,7 +17,6 @@
import path from 'path';
import { createGuid } from 'playwright-core/lib/utils';
import type { FullConfig, FullResult, Location, Suite, TestCase, TestError, TestResult, TestStep } from '../../types/testReporter';
import { getProjectId } from '../common/config';
import type { JsonAttachment, JsonConfig, JsonEvent, JsonFullResult, JsonProject, JsonStdIOType, JsonSuite, JsonTestCase, JsonTestEnd, JsonTestResultEnd, JsonTestResultStart, JsonTestStepEnd, JsonTestStepStart } from '../isomorphic/teleReceiver';
import { serializeRegexPatterns } from '../isomorphic/teleReceiver';
import type { ReporterV2 } from './reporterV2';
@ -158,7 +157,6 @@ export class TeleReporterEmitter implements ReporterV2 {
private _serializeProject(suite: Suite): JsonProject {
const project = suite.project()!;
const report: JsonProject = {
id: getProjectId(project),
metadata: project.metadata,
name: project.name,
outputDir: this._relativePath(project.outputDir),

View File

@ -63,7 +63,7 @@ export async function createReporters(config: FullConfigInternal, mode: 'list' |
}
if (process.env.PW_TEST_REPORTER) {
const reporterConstructor = await loadReporter(config, process.env.PW_TEST_REPORTER);
reporters.push(wrapReporterAsV2(new reporterConstructor(runOptions)));
reporters.push(wrapReporterAsV2(new reporterConstructor()));
}
const someReporterPrintsToStdio = reporters.some(r => r.printsToStdio());

View File

@ -654,7 +654,7 @@ const refreshRootSuite = (eraseResults: boolean): Promise<void> => {
lastRunTestCount = suite.allTests().length;
lastRunReceiver = undefined;
}
}, false);
}, true, false);
},
onBegin: (suite: Suite) => {
@ -700,7 +700,7 @@ const refreshRootSuite = (eraseResults: boolean): Promise<void> => {
onExit: () => {},
onStepBegin: () => {},
onStepEnd: () => {},
}, true);
}, true, true);
receiver._setClearPreviousResultsWhenTestBegins();
return sendMessage('list', {});
};

View File

@ -50,23 +50,23 @@ const metadata = {
};
config.projects!.push({
name: 'android',
name: 'android-native',
use: {
loopback: '10.0.2.2',
browserName: 'chromium',
},
snapshotPathTemplate: '{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{ext}',
snapshotPathTemplate: '{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}-android{ext}',
testDir: path.join(testDir, 'android'),
metadata,
});
config.projects!.push({
name: 'android',
name: 'android-page',
use: {
loopback: '10.0.2.2',
browserName: 'chromium',
},
snapshotPathTemplate: '{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{ext}',
snapshotPathTemplate: '{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}-android{ext}',
testDir: path.join(testDir, 'page'),
metadata,
});

View File

@ -51,7 +51,7 @@ const metadata = {
};
config.projects.push({
name: 'electron',
name: 'electron-api',
use: {
browserName: 'chromium',
coverageName: 'electron',
@ -61,7 +61,7 @@ config.projects.push({
});
config.projects.push({
name: 'electron',
name: 'electron-page',
// Share screenshots with chromium.
snapshotPathTemplate: '{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}-chromium{ext}',
use: {

View File

@ -109,10 +109,10 @@ for (const browserName of browserNames) {
const testIgnore: RegExp[] = browserNames.filter(b => b !== browserName).map(b => new RegExp(b));
for (const folder of ['library', 'page']) {
config.projects.push({
name: browserName,
name: `${browserName}-${folder}`,
testDir: path.join(testDir, folder),
testIgnore,
snapshotPathTemplate: '{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}{-projectName}{ext}',
snapshotPathTemplate: `{testDir}/{testFileDir}/{testFileName}-snapshots/{arg}-${browserName}{ext}`,
use: {
mode,
browserName,

View File

@ -1205,9 +1205,9 @@ test('preserve reportName on projects', async ({ runInlineTest, mergeReports })
class EchoReporter {
onBegin(config, suite) {
const projects = suite.suites.map(s => s.project()).sort((a, b) => a.metadata.reportName.localeCompare(b.metadata.reportName));
const projects = suite.suites.map(s => s.project()).sort((a, b) => a.metadata.botName.localeCompare(b.metadata.botName));
console.log('projectNames: ' + projects.map(p => p.name));
console.log('reportNames: ' + projects.map(p => p.metadata.reportName));
console.log('botNames: ' + projects.map(p => p.metadata.botName));
}
}
module.exports = EchoReporter;
@ -1233,7 +1233,7 @@ test('preserve reportName on projects', async ({ runInlineTest, mergeReports })
const { exitCode, output } = await mergeReports(reportDir, {}, { additionalArgs: ['--reporter', test.info().outputPath('echo-reporter.js')] });
expect(exitCode).toBe(0);
expect(output).toContain(`projectNames: foo,foo`);
expect(output).toContain(`reportNames: first,second`);
expect(output).toContain(`botNames: first,second`);
});
test('no reports error', async ({ runInlineTest, mergeReports }) => {