chore(ui): update expected state on test end (#22104)

Fixes https://github.com/microsoft/playwright/issues/22096
This commit is contained in:
Pavel Feldman 2023-03-30 16:17:34 -07:00 committed by GitHub
parent 539d9873c2
commit eacaf5fc89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 12 deletions

View file

@ -66,10 +66,14 @@ export type JsonTestCase = {
testId: string;
title: string;
location: JsonLocation;
retries: number;
};
export type JsonTestEnd = {
testId: string;
expectedStatus: TestStatus;
timeout: number;
annotations: { type: string, description?: string }[];
retries: number;
};
export type JsonTestResultStart = {
@ -127,7 +131,7 @@ export class TeleReporterReceiver {
return;
}
if (method === 'onTestEnd') {
this._onTestEnd(params.testId, params.result);
this._onTestEnd(params.test, params.result);
return;
}
if (method === 'onStepBegin') {
@ -196,8 +200,11 @@ export class TeleReporterReceiver {
this._reporter.onTestBegin?.(test, testResult);
}
private _onTestEnd(testId: string, payload: JsonTestResultEnd) {
const test = this._tests.get(testId)!;
private _onTestEnd(testEndPayload: JsonTestEnd, payload: JsonTestResultEnd) {
const test = this._tests.get(testEndPayload.testId)!;
test.timeout = testEndPayload.timeout;
test.expectedStatus = testEndPayload.expectedStatus;
test.annotations = testEndPayload.annotations;
const result = test.resultsMap.get(payload.id)!;
result.duration = payload.duration;
result.status = payload.status;
@ -313,10 +320,7 @@ export class TeleReporterReceiver {
private _updateTest(payload: JsonTestCase, test: TeleTestCase): TeleTestCase {
test.id = payload.testId;
test.expectedStatus = payload.expectedStatus;
test.timeout = payload.timeout;
test.location = this._absoluteLocation(payload.location);
test.annotations = payload.annotations;
test.retries = payload.retries;
return test;
}

View file

@ -16,7 +16,7 @@
import type { FullConfig, FullResult, Reporter, TestError, TestResult, TestStep, Location } from '../../types/testReporter';
import type { Suite, TestCase } from '../common/test';
import type { JsonConfig, JsonProject, JsonSuite, JsonTestCase, JsonTestResultEnd, JsonTestResultStart, JsonTestStepEnd, JsonTestStepStart } from '../isomorphic/teleReceiver';
import type { JsonConfig, JsonProject, JsonSuite, JsonTestCase, JsonTestEnd, JsonTestResultEnd, JsonTestResultStart, JsonTestStepEnd, JsonTestStepStart } from '../isomorphic/teleReceiver';
import type { SuitePrivate } from '../../types/reporterPrivate';
import type { FullConfigInternal, FullProjectInternal } from '../common/types';
import { createGuid } from 'playwright-core/lib/utils';
@ -53,10 +53,16 @@ export class TeleReporterEmitter implements Reporter {
}
onTestEnd(test: TestCase, result: TestResult): void {
const testEnd: JsonTestEnd = {
testId: test.id,
expectedStatus: test.expectedStatus,
annotations: test.annotations,
timeout: test.timeout,
};
this._messageSink({
method: 'onTestEnd',
params: {
testId: test.id,
test: testEnd,
result: this._serializeResultEnd(result),
}
});
@ -163,9 +169,6 @@ export class TeleReporterEmitter implements Reporter {
testId: test.id,
title: test.title,
location: this._relativeLocation(test.location),
expectedStatus: test.expectedStatus,
timeout: test.timeout,
annotations: test.annotations,
retries: test.retries,
};
}

View file

@ -306,3 +306,27 @@ test('should show time', async ({ runUITest }) => {
await expect(page.getByTestId('status-line')).toHaveText('4/8 passed (50%)');
});
test('should show test.fail as passing', async ({ runUITest }) => {
const { page } = await runUITest({
'a.test.ts': `
import { test, expect } from '@playwright/test';
test('should fail', () => {
test.fail();
expect(1).toBe(2);
});
`,
});
await expect.poll(dumpTestTree(page), { timeout: 15000 }).toContain(`
a.test.ts
`);
await page.getByTitle('Run all').click();
await expect.poll(dumpTestTree(page, { time: true }), { timeout: 15000 }).toBe(`
a.test.ts
should fail XXms
`);
await expect(page.getByTestId('status-line')).toHaveText('1/1 passed (100%)');
});