feat(json-reporter): added parallelIndex to TestResult (#34740)

This commit is contained in:
Christopher Tangonan 2025-02-28 10:00:51 -08:00 committed by GitHub
parent 4a79c214f0
commit c22c10f7d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 31 additions and 0 deletions

View File

@ -203,6 +203,7 @@ class JSONReporter implements ReporterV2 {
const steps = result.steps.filter(s => s.category === 'test.step');
const jsonResult: JSONReportTestResult = {
workerIndex: result.workerIndex,
parallelIndex: result.parallelIndex,
status: result.status,
duration: result.duration,
error: result.error,

View File

@ -291,6 +291,7 @@ export interface JSONReportError {
export interface JSONReportTestResult {
workerIndex: number;
parallelIndex: number;
status: TestStatus | undefined;
duration: number;
error: TestError | undefined;

View File

@ -327,3 +327,31 @@ test.describe('report location', () => {
expect(fs.existsSync(testInfo.outputPath('foo', 'bar', 'baz', 'my-report.json'))).toBe(true);
});
});
test('should report parallelIndex', async ({ runInlineTest }, testInfo) => {
const result = await runInlineTest({
'tests/a.spec.js': `
import { test, expect } from '@playwright/test';
const fs = require('fs');
test.describe.configure({ mode: 'parallel' });
test('test 1 passes!', async ({}) => {
await new Promise(f => setTimeout(f, 1000));
});
test('test 2 fails!', async ({}) => {
expect(1 + 1).toBe(3);
await new Promise(f => setTimeout(f, 1000));
});
test('test 3 passes!', async ({}) => {
await new Promise(f => setTimeout(f, 1000));
});
`
}, { 'workers': '2', 'reporter': 'json' });
expect(result.passed).toBe(2);
expect(result.failed).toBe(1);
expect(result.report.suites[0].specs[0].tests[0].results[0].workerIndex).toBe(0);
expect(result.report.suites[0].specs[1].tests[0].results[0].workerIndex).toBe(1);
expect(result.report.suites[0].specs[2].tests[0].results[0].workerIndex).toBe(2);
expect(result.report.suites[0].specs[0].tests[0].results[0].parallelIndex).toBe(0);
expect(result.report.suites[0].specs[1].tests[0].results[0].parallelIndex).toBe(1);
expect(result.report.suites[0].specs[2].tests[0].results[0].parallelIndex).toBe(1);
});

View File

@ -109,6 +109,7 @@ export interface JSONReportError {
export interface JSONReportTestResult {
workerIndex: number;
parallelIndex: number;
status: TestStatus | undefined;
duration: number;
error: TestError | undefined;