return timedOut bool
This commit is contained in:
parent
70ddc7ebe2
commit
d2ee0916d2
|
|
@ -63,6 +63,7 @@ type PDFOptions = Omit<channels.PagePdfParams, 'width' | 'height' | 'margin'> &
|
|||
export type ExpectScreenshotOptions = Omit<channels.PageExpectScreenshotOptions, 'locator' | 'expected' | 'mask'> & {
|
||||
expected?: Buffer,
|
||||
locator?: api.Locator,
|
||||
timeout: number,
|
||||
isNot: boolean,
|
||||
mask?: api.Locator[],
|
||||
};
|
||||
|
|
@ -589,7 +590,7 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
|
|||
return result.binary;
|
||||
}
|
||||
|
||||
async _expectScreenshot(options: ExpectScreenshotOptions): Promise<{ actual?: Buffer, previous?: Buffer, diff?: Buffer, errorMessage?: string, log?: string[], timeout?: number}> {
|
||||
async _expectScreenshot(options: ExpectScreenshotOptions): Promise<{ actual?: Buffer, previous?: Buffer, diff?: Buffer, errorMessage?: string, log?: string[], timedOut?: boolean}> {
|
||||
const mask = options?.mask ? options?.mask.map(locator => ({
|
||||
frame: (locator as Locator)._frame._channel,
|
||||
selector: (locator as Locator)._selector,
|
||||
|
|
|
|||
|
|
@ -1165,7 +1165,7 @@ scheme.PageReloadResult = tObject({
|
|||
});
|
||||
scheme.PageExpectScreenshotParams = tObject({
|
||||
expected: tOptional(tBinary),
|
||||
timeout: tOptional(tNumber),
|
||||
timeout: tNumber,
|
||||
isNot: tBoolean,
|
||||
locator: tOptional(tObject({
|
||||
frame: tChannel(['Frame']),
|
||||
|
|
@ -1193,7 +1193,7 @@ scheme.PageExpectScreenshotResult = tObject({
|
|||
errorMessage: tOptional(tString),
|
||||
actual: tOptional(tBinary),
|
||||
previous: tOptional(tBinary),
|
||||
timeout: tOptional(tNumber),
|
||||
timedOut: tOptional(tBoolean),
|
||||
log: tOptional(tArray(tString)),
|
||||
});
|
||||
scheme.PageScreenshotParams = tObject({
|
||||
|
|
|
|||
|
|
@ -679,7 +679,7 @@ export class Page extends SdkObject {
|
|||
log: e.message ? [...metadata.log, e.message] : metadata.log,
|
||||
...intermediateResult,
|
||||
errorMessage,
|
||||
...((e instanceof TimeoutError) ? { timeout: callTimeout } : {}),
|
||||
timedOut: (e instanceof TimeoutError),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -370,6 +370,7 @@ export async function toHaveScreenshot(
|
|||
throw new Error(`Screenshot name "${path.basename(helper.expectedPath)}" must have '.png' extension`);
|
||||
expectTypes(pageOrLocator, ['Page', 'Locator'], 'toHaveScreenshot');
|
||||
const style = await loadScreenshotStyles(helper.options.stylePath);
|
||||
const timeout = helper.options.timeout ?? this.timeout;
|
||||
const expectScreenshotOptions: ExpectScreenshotOptions = {
|
||||
locator,
|
||||
animations: helper.options.animations ?? 'disabled',
|
||||
|
|
@ -382,7 +383,7 @@ export async function toHaveScreenshot(
|
|||
scale: helper.options.scale ?? 'css',
|
||||
style,
|
||||
isNot: !!this.isNot,
|
||||
timeout: helper.options.timeout ?? this.timeout,
|
||||
timeout,
|
||||
comparator: helper.options.comparator,
|
||||
maxDiffPixels: helper.options.maxDiffPixels,
|
||||
maxDiffPixelRatio: helper.options.maxDiffPixelRatio,
|
||||
|
|
@ -409,11 +410,11 @@ export async function toHaveScreenshot(
|
|||
const receiver = locator ? 'locator' : 'page';
|
||||
if (!hasSnapshot) {
|
||||
// Regenerate a new screenshot by waiting until two screenshots are the same.
|
||||
const { actual, previous, diff, errorMessage, log, timeout } = await page._expectScreenshot(expectScreenshotOptions);
|
||||
const { actual, previous, diff, errorMessage, log, timedOut } = await page._expectScreenshot(expectScreenshotOptions);
|
||||
// We tried re-generating new snapshot but failed.
|
||||
// This can be due to e.g. spinning animation, so we want to show it as a diff.
|
||||
if (errorMessage) {
|
||||
const header = matcherHint(this, locator, 'toHaveScreenshot', receiver, undefined, undefined, timeout);
|
||||
const header = matcherHint(this, locator, 'toHaveScreenshot', receiver, undefined, undefined, timedOut ? timeout : undefined);
|
||||
return helper.handleDifferent(actual, undefined, previous, diff, header, errorMessage, log);
|
||||
}
|
||||
|
||||
|
|
@ -426,7 +427,7 @@ export async function toHaveScreenshot(
|
|||
// - regular matcher (i.e. not a `.not`)
|
||||
// - perhaps an 'all' flag to update non-matching screenshots
|
||||
expectScreenshotOptions.expected = await fs.promises.readFile(helper.expectedPath);
|
||||
const { actual, previous, diff, errorMessage, log, timeout } = await page._expectScreenshot(expectScreenshotOptions);
|
||||
const { actual, previous, diff, errorMessage, log, timedOut } = await page._expectScreenshot(expectScreenshotOptions);
|
||||
|
||||
if (!errorMessage)
|
||||
return helper.handleMatching();
|
||||
|
|
@ -439,7 +440,7 @@ export async function toHaveScreenshot(
|
|||
return helper.createMatcherResult(helper.expectedPath + ' running with --update-snapshots, writing actual.', true);
|
||||
}
|
||||
|
||||
const header = matcherHint(this, undefined, 'toHaveScreenshot', receiver, undefined, undefined, timeout);
|
||||
const header = matcherHint(this, undefined, 'toHaveScreenshot', receiver, undefined, undefined, timedOut ? timeout : undefined);
|
||||
return helper.handleDifferent(actual, expectScreenshotOptions.expected, previous, diff, header, errorMessage, log);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2141,7 +2141,7 @@ export type PageReloadResult = {
|
|||
};
|
||||
export type PageExpectScreenshotParams = {
|
||||
expected?: Binary,
|
||||
timeout?: number,
|
||||
timeout: number,
|
||||
isNot: boolean,
|
||||
locator?: {
|
||||
frame: FrameChannel,
|
||||
|
|
@ -2166,7 +2166,6 @@ export type PageExpectScreenshotParams = {
|
|||
};
|
||||
export type PageExpectScreenshotOptions = {
|
||||
expected?: Binary,
|
||||
timeout?: number,
|
||||
locator?: {
|
||||
frame: FrameChannel,
|
||||
selector: string,
|
||||
|
|
@ -2193,7 +2192,7 @@ export type PageExpectScreenshotResult = {
|
|||
errorMessage?: string,
|
||||
actual?: Binary,
|
||||
previous?: Binary,
|
||||
timeout?: number,
|
||||
timedOut?: boolean,
|
||||
log?: string[],
|
||||
};
|
||||
export type PageScreenshotParams = {
|
||||
|
|
|
|||
|
|
@ -1482,7 +1482,7 @@ Page:
|
|||
expectScreenshot:
|
||||
parameters:
|
||||
expected: binary?
|
||||
timeout: number?
|
||||
timeout: number
|
||||
isNot: boolean
|
||||
locator:
|
||||
type: object?
|
||||
|
|
@ -1501,7 +1501,7 @@ Page:
|
|||
errorMessage: string?
|
||||
actual: binary?
|
||||
previous: binary?
|
||||
timeout: number?
|
||||
timedOut: boolean?
|
||||
log:
|
||||
type: array?
|
||||
items: string
|
||||
|
|
|
|||
Loading…
Reference in a new issue