chore: include log in matcherResult (#27164)

This commit is contained in:
Pavel Feldman 2023-09-21 16:23:46 -07:00 committed by GitHub
parent 287d720b8e
commit 51a774f8a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 6 deletions

View File

@ -253,6 +253,7 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
params: args[0] ? { expected: args[0] } : undefined, params: args[0] ? { expected: args[0] } : undefined,
wallTime, wallTime,
infectParentStepsWithError: this._info.isSoft, infectParentStepsWithError: this._info.isSoft,
laxParent: true,
}) : undefined; }) : undefined;
const reportStepError = (jestError: Error) => { const reportStepError = (jestError: Error) => {

View File

@ -34,4 +34,5 @@ export type MatcherResult<E, A> = {
message: () => string; message: () => string;
pass: boolean; pass: boolean;
actual?: A; actual?: A;
log?: string[];
}; };

View File

@ -48,5 +48,5 @@ export async function toBeTruthy(
return matches ? `${header}Expected: not ${expected}\nReceived: ${expected}${logText}` : return matches ? `${header}Expected: not ${expected}\nReceived: ${expected}${logText}` :
`${header}Expected: ${expected}\nReceived: ${unexpected}${logText}`; `${header}Expected: ${expected}\nReceived: ${unexpected}${logText}`;
}; };
return { locator: receiver, message, pass: matches, actual, name: matcherName, expected }; return { locator: receiver, message, pass: matches, actual, name: matcherName, expected, log };
} }

View File

@ -67,5 +67,5 @@ export async function toEqual<T>(
// Passing the actual and expected objects so that a custom reporter // Passing the actual and expected objects so that a custom reporter
// could access them, for example in order to display a custom visual diff, // could access them, for example in order to display a custom visual diff,
// or create a different error message // or create a different error message
return { locator: receiver, actual: received, expected, message, name: matcherName, pass }; return { locator: receiver, actual: received, expected, message, name: matcherName, pass, log };
} }

View File

@ -157,7 +157,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
this.kind = this.mimeType.startsWith('image/') ? 'Screenshot' : 'Snapshot'; this.kind = this.mimeType.startsWith('image/') ? 'Screenshot' : 'Snapshot';
} }
createMatcherResult(message: string, pass: boolean): ImageMatcherResult { createMatcherResult(message: string, pass: boolean, log?: string[]): ImageMatcherResult {
const unfiltered: ImageMatcherResult = { const unfiltered: ImageMatcherResult = {
name: this.matcherName, name: this.matcherName,
locator: this.locator, locator: this.locator,
@ -166,6 +166,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
diff: this.diffPath, diff: this.diffPath,
pass, pass,
message: () => message, message: () => message,
log,
}; };
return Object.fromEntries(Object.entries(unfiltered).filter(([_, v]) => v !== undefined)) as ImageMatcherResult; return Object.fromEntries(Object.entries(unfiltered).filter(([_, v]) => v !== undefined)) as ImageMatcherResult;
} }
@ -255,7 +256,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
else else
output.push(''); output.push('');
return this.createMatcherResult(output.join('\n'), false); return this.createMatcherResult(output.join('\n'), false, log);
} }
handleMatching(): ImageMatcherResult { handleMatching(): ImageMatcherResult {

View File

@ -105,6 +105,7 @@ export async function toMatchText(
message, message,
pass, pass,
actual: received, actual: received,
log,
}; };
} }

View File

@ -348,8 +348,8 @@ export class TestInfoImpl implements TestInfo {
this.errors.push(error); this.errors.push(error);
} }
async _runAsStep<T>(stepInfo: Omit<TestStepInternal, 'complete' | 'wallTime' | 'parentStepId' | 'stepId' | 'steps'>, cb: (step: TestStepInternal) => Promise<T>): Promise<T> { async _runAsStep<T>(stepInfo: Omit<TestStepInternal, 'complete' | 'wallTime' | 'parentStepId' | 'stepId' | 'steps'> & { wallTime?: number }, cb: (step: TestStepInternal) => Promise<T>): Promise<T> {
const step = this._addStep({ ...stepInfo, wallTime: Date.now() }); const step = this._addStep({ wallTime: Date.now(), ...stepInfo });
return await zones.run('stepZone', step, async () => { return await zones.run('stepZone', step, async () => {
try { try {
const result = await cb(step); const result = await cb(step);

View File

@ -31,6 +31,7 @@ test('toMatchText-based assertions should have matcher result', async ({ page })
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toHaveText(expected)`), message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toHaveText(expected)`),
name: 'toHaveText', name: 'toHaveText',
pass: false, pass: false,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toHaveText(expected) expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toHaveText(expected)
@ -52,6 +53,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toHaveText(expected)`), message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toHaveText(expected)`),
name: 'toHaveText', name: 'toHaveText',
pass: true, pass: true,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toHaveText(expected) expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toHaveText(expected)
@ -77,6 +79,7 @@ test('toBeTruthy-based assertions should have matcher result', async ({ page })
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toBeVisible()`), message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toBeVisible()`),
name: 'toBeVisible', name: 'toBeVisible',
pass: false, pass: false,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toBeVisible() expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toBeVisible()
@ -98,6 +101,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toBeVisible()`), message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toBeVisible()`),
name: 'toBeVisible', name: 'toBeVisible',
pass: true, pass: true,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toBeVisible() expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toBeVisible()
@ -123,6 +127,7 @@ test('toEqual-based assertions should have matcher result', async ({ page }) =>
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toHaveCount(expected)`), message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toHaveCount(expected)`),
name: 'toHaveCount', name: 'toHaveCount',
pass: false, pass: false,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toHaveCount(expected) expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toHaveCount(expected)
@ -143,6 +148,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toHaveCount(expected)`), message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toHaveCount(expected)`),
name: 'toHaveCount', name: 'toHaveCount',
pass: true, pass: true,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toHaveCount(expected) expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toHaveCount(expected)
@ -171,6 +177,7 @@ test('toBeChecked({ checked: false }) should have expected: false', async ({ pag
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toBeChecked()`), message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toBeChecked()`),
name: 'toBeChecked', name: 'toBeChecked',
pass: false, pass: false,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toBeChecked() expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toBeChecked()
@ -192,6 +199,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toBeChecked()`), message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toBeChecked()`),
name: 'toBeChecked', name: 'toBeChecked',
pass: true, pass: true,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toBeChecked() expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toBeChecked()
@ -213,6 +221,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toBeChecked({ checked: false })`), message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).toBeChecked({ checked: false })`),
name: 'toBeChecked', name: 'toBeChecked',
pass: false, pass: false,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toBeChecked({ checked: false }) expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).toBeChecked({ checked: false })
@ -234,6 +243,7 @@ Call log`);
message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toBeChecked({ checked: false })`), message: expect.stringContaining(`Timed out 1ms waiting for expect(locator).not.toBeChecked({ checked: false })`),
name: 'toBeChecked', name: 'toBeChecked',
pass: true, pass: true,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toBeChecked({ checked: false }) expect.soft(stripAnsi(e.toString())).toContain(`Error: Timed out 1ms waiting for expect(locator).not.toBeChecked({ checked: false })
@ -259,6 +269,7 @@ test('toHaveScreenshot should populate matcherResult', async ({ page, server })
message: expect.stringContaining(`Screenshot comparison failed`), message: expect.stringContaining(`Screenshot comparison failed`),
name: 'toHaveScreenshot', name: 'toHaveScreenshot',
pass: false, pass: false,
log: expect.any(Array),
}); });
expect.soft(stripAnsi(e.toString())).toContain(`Error: Screenshot comparison failed: expect.soft(stripAnsi(e.toString())).toContain(`Error: Screenshot comparison failed: