mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
chore: include log in matcherResult (#27164)
This commit is contained in:
parent
287d720b8e
commit
51a774f8a3
@ -253,6 +253,7 @@ class ExpectMetaInfoProxyHandler implements ProxyHandler<any> {
|
||||
params: args[0] ? { expected: args[0] } : undefined,
|
||||
wallTime,
|
||||
infectParentStepsWithError: this._info.isSoft,
|
||||
laxParent: true,
|
||||
}) : undefined;
|
||||
|
||||
const reportStepError = (jestError: Error) => {
|
||||
|
@ -34,4 +34,5 @@ export type MatcherResult<E, A> = {
|
||||
message: () => string;
|
||||
pass: boolean;
|
||||
actual?: A;
|
||||
log?: string[];
|
||||
};
|
||||
|
@ -48,5 +48,5 @@ export async function toBeTruthy(
|
||||
return matches ? `${header}Expected: not ${expected}\nReceived: ${expected}${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 };
|
||||
}
|
||||
|
@ -67,5 +67,5 @@ export async function toEqual<T>(
|
||||
// Passing the actual and expected objects so that a custom reporter
|
||||
// could access them, for example in order to display a custom visual diff,
|
||||
// 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 };
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
|
||||
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 = {
|
||||
name: this.matcherName,
|
||||
locator: this.locator,
|
||||
@ -166,6 +166,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
|
||||
diff: this.diffPath,
|
||||
pass,
|
||||
message: () => message,
|
||||
log,
|
||||
};
|
||||
return Object.fromEntries(Object.entries(unfiltered).filter(([_, v]) => v !== undefined)) as ImageMatcherResult;
|
||||
}
|
||||
@ -255,7 +256,7 @@ class SnapshotHelper<T extends ImageComparatorOptions> {
|
||||
else
|
||||
output.push('');
|
||||
|
||||
return this.createMatcherResult(output.join('\n'), false);
|
||||
return this.createMatcherResult(output.join('\n'), false, log);
|
||||
}
|
||||
|
||||
handleMatching(): ImageMatcherResult {
|
||||
|
@ -105,6 +105,7 @@ export async function toMatchText(
|
||||
message,
|
||||
pass,
|
||||
actual: received,
|
||||
log,
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -348,8 +348,8 @@ export class TestInfoImpl implements TestInfo {
|
||||
this.errors.push(error);
|
||||
}
|
||||
|
||||
async _runAsStep<T>(stepInfo: Omit<TestStepInternal, 'complete' | 'wallTime' | 'parentStepId' | 'stepId' | 'steps'>, cb: (step: TestStepInternal) => Promise<T>): Promise<T> {
|
||||
const step = this._addStep({ ...stepInfo, wallTime: Date.now() });
|
||||
async _runAsStep<T>(stepInfo: Omit<TestStepInternal, 'complete' | 'wallTime' | 'parentStepId' | 'stepId' | 'steps'> & { wallTime?: number }, cb: (step: TestStepInternal) => Promise<T>): Promise<T> {
|
||||
const step = this._addStep({ wallTime: Date.now(), ...stepInfo });
|
||||
return await zones.run('stepZone', step, async () => {
|
||||
try {
|
||||
const result = await cb(step);
|
||||
|
@ -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)`),
|
||||
name: 'toHaveText',
|
||||
pass: false,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
|
||||
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)`),
|
||||
name: 'toHaveText',
|
||||
pass: true,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
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()`),
|
||||
name: 'toBeVisible',
|
||||
pass: false,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
|
||||
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()`),
|
||||
name: 'toBeVisible',
|
||||
pass: true,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
|
||||
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)`),
|
||||
name: 'toHaveCount',
|
||||
pass: false,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
|
||||
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)`),
|
||||
name: 'toHaveCount',
|
||||
pass: true,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
|
||||
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()`),
|
||||
name: 'toBeChecked',
|
||||
pass: false,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
|
||||
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()`),
|
||||
name: 'toBeChecked',
|
||||
pass: true,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
|
||||
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 })`),
|
||||
name: 'toBeChecked',
|
||||
pass: false,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
|
||||
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 })`),
|
||||
name: 'toBeChecked',
|
||||
pass: true,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
|
||||
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`),
|
||||
name: 'toHaveScreenshot',
|
||||
pass: false,
|
||||
log: expect.any(Array),
|
||||
});
|
||||
|
||||
expect.soft(stripAnsi(e.toString())).toContain(`Error: Screenshot comparison failed:
|
||||
|
Loading…
x
Reference in New Issue
Block a user