chore: remove refined title (#22541)

This commit is contained in:
Pavel Feldman 2023-04-20 20:34:07 -07:00 committed by GitHub
parent d9a7aa584c
commit d95268ffc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 12 deletions

View File

@ -94,7 +94,6 @@ export type StepBeginPayload = {
export type StepEndPayload = { export type StepEndPayload = {
testId: string; testId: string;
stepId: string; stepId: string;
refinedTitle?: string;
wallTime: number; // milliseconds since unix epoch wallTime: number; // milliseconds since unix epoch
error?: TestInfoError; error?: TestInfoError;
}; };

View File

@ -46,7 +46,7 @@ import {
toHaveValues, toHaveValues,
toPass toPass
} from './matchers'; } from './matchers';
import { toMatchSnapshot, toHaveScreenshot } from './toMatchSnapshot'; import { toMatchSnapshot, toHaveScreenshot, toHaveScreenshotStepTitle } from './toMatchSnapshot';
import type { Expect } from '../../types/test'; import type { Expect } from '../../types/test';
import { currentTestInfo, currentExpectTimeout } from '../common/globals'; import { currentTestInfo, currentExpectTimeout } from '../common/globals';
import { filteredStackTrace, serializeError, stringifyStackFrames, trimLongString } from '../util'; import { filteredStackTrace, serializeError, stringifyStackFrames, trimLongString } from '../util';
@ -210,7 +210,9 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
const rawStack = captureRawStack(); const rawStack = captureRawStack();
const stackFrames = filteredStackTrace(rawStack); const stackFrames = filteredStackTrace(rawStack);
const customMessage = this._info.message || ''; const customMessage = this._info.message || '';
const defaultTitle = `expect${this._info.isPoll ? '.poll' : ''}${this._info.isSoft ? '.soft' : ''}${this._info.isNot ? '.not' : ''}.${matcherName}`; const argsSuffix = computeArgsSuffix(matcherName, args);
const defaultTitle = `expect${this._info.isPoll ? '.poll' : ''}${this._info.isSoft ? '.soft' : ''}${this._info.isNot ? '.not' : ''}.${matcherName}${argsSuffix}`;
const wallTime = Date.now(); const wallTime = Date.now();
const step = testInfo._addStep({ const step = testInfo._addStep({
location: stackFrames[0], location: stackFrames[0],
@ -218,7 +220,6 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
title: trimLongString(customMessage || defaultTitle, 1024), title: trimLongString(customMessage || defaultTitle, 1024),
wallTime wallTime
}); });
testInfo.currentStep = step;
const generateTraceEvent = matcherName !== 'poll' && matcherName !== 'toPass'; const generateTraceEvent = matcherName !== 'poll' && matcherName !== 'toPass';
const callId = ++lastCallId; const callId = ++lastCallId;
@ -314,4 +315,11 @@ async function pollMatcher(matcherName: any, isNot: boolean, pollIntervals: numb
} }
} }
function computeArgsSuffix(matcherName: string, args: any[]) {
let value = '';
if (matcherName === 'toHaveScreenshot')
value = toHaveScreenshotStepTitle(...args);
return value ? `(${value})` : '';
}
expectLibrary.extend(customMatchers); expectLibrary.extend(customMatchers);

View File

@ -110,7 +110,6 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
} }
} }
testInfo.currentStep!.refinedTitle = `${testInfo.currentStep!.title}(${path.basename(this.snapshotName)})`;
options = { options = {
...configOptions, ...configOptions,
...options, ...options,
@ -288,6 +287,18 @@ export function toMatchSnapshot(
type HaveScreenshotOptions = ImageComparatorOptions & Omit<PageScreenshotOptions, 'type' | 'quality' | 'path'>; type HaveScreenshotOptions = ImageComparatorOptions & Omit<PageScreenshotOptions, 'type' | 'quality' | 'path'>;
export function toHaveScreenshotStepTitle(
nameOrOptions: NameOrSegments | { name?: NameOrSegments } & HaveScreenshotOptions = {},
optOptions: HaveScreenshotOptions = {}
): string {
let name: NameOrSegments | undefined;
if (typeof nameOrOptions === 'object' && !Array.isArray(nameOrOptions))
name = nameOrOptions.name;
else
name = nameOrOptions;
return Array.isArray(name) ? name.join(path.sep) : name || '';
}
export async function toHaveScreenshot( export async function toHaveScreenshot(
this: ReturnType<Expect['getState']>, this: ReturnType<Expect['getState']>,
pageOrLocator: Page | Locator, pageOrLocator: Page | Locator,

View File

@ -301,8 +301,6 @@ export class Dispatcher {
this._reporter.onStdErr?.('Internal error: step end without step begin: ' + params.stepId, data.test, result); this._reporter.onStdErr?.('Internal error: step end without step begin: ' + params.stepId, data.test, result);
return; return;
} }
if (params.refinedTitle)
step.title = params.refinedTitle;
step.duration = params.wallTime - step.startTime.getTime(); step.duration = params.wallTime - step.startTime.getTime();
if (params.error) if (params.error)
step.error = params.error; step.error = params.error;

View File

@ -33,7 +33,6 @@ interface TestStepInternal {
category: string; category: string;
wallTime: number; wallTime: number;
location?: Location; location?: Location;
refinedTitle?: string;
} }
export class TestInfoImpl implements TestInfo { export class TestInfoImpl implements TestInfo {
@ -77,7 +76,6 @@ export class TestInfoImpl implements TestInfo {
readonly outputDir: string; readonly outputDir: string;
readonly snapshotDir: string; readonly snapshotDir: string;
errors: TestInfoError[] = []; errors: TestInfoError[] = [];
currentStep: TestStepInternal | undefined;
get error(): TestInfoError | undefined { get error(): TestInfoError | undefined {
return this.errors[0]; return this.errors[0];
@ -234,7 +232,6 @@ export class TestInfoImpl implements TestInfo {
} }
const payload: StepEndPayload = { const payload: StepEndPayload = {
testId: this._test.id, testId: this._test.id,
refinedTitle: step.refinedTitle,
stepId, stepId,
wallTime: Date.now(), wallTime: Date.now(),
error, error,

View File

@ -199,8 +199,7 @@ test('should report toHaveScreenshot step with expectation name in title', async
test('is a test', async ({ page }) => { test('is a test', async ({ page }) => {
// Named expectation. // Named expectation.
await expect(page).toHaveScreenshot('foo.png', { timeout: 2000 }); await expect(page).toHaveScreenshot('foo.png', { timeout: 2000 });
// Anonymous expectation. await expect(page).toHaveScreenshot({ name: 'is-a-test-1.png', timeout: 2000 });
await expect(page).toHaveScreenshot({ timeout: 2000 });
}); });
` `
}, { 'reporter': '', 'workers': 1, 'update-snapshots': true }); }, { 'reporter': '', 'workers': 1, 'update-snapshots': true });