fix: use loaderId to reduce test flakiness (#8717)
This commit is contained in:
parent
6b35128e3e
commit
d2f6db2073
@ -213,6 +213,7 @@ export class FrameManager extends EventEmitter {
|
|||||||
timeout = this.#timeoutSettings.navigationTimeout(),
|
timeout = this.#timeoutSettings.navigationTimeout(),
|
||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
|
let ensureNewDocumentNavigation = false;
|
||||||
const watcher = new LifecycleWatcher(this, frame, waitUntil, timeout);
|
const watcher = new LifecycleWatcher(this, frame, waitUntil, timeout);
|
||||||
let error = await Promise.race([
|
let error = await Promise.race([
|
||||||
navigate(this.#client, url, referer, frame._id),
|
navigate(this.#client, url, referer, frame._id),
|
||||||
@ -221,8 +222,9 @@ export class FrameManager extends EventEmitter {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
error = await Promise.race([
|
error = await Promise.race([
|
||||||
watcher.timeoutOrTerminationPromise(),
|
watcher.timeoutOrTerminationPromise(),
|
||||||
watcher.newDocumentNavigationPromise(),
|
ensureNewDocumentNavigation
|
||||||
watcher.sameDocumentNavigationPromise(),
|
? watcher.newDocumentNavigationPromise()
|
||||||
|
: watcher.sameDocumentNavigationPromise(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
watcher.dispose();
|
watcher.dispose();
|
||||||
@ -243,6 +245,7 @@ export class FrameManager extends EventEmitter {
|
|||||||
referrer,
|
referrer,
|
||||||
frameId,
|
frameId,
|
||||||
});
|
});
|
||||||
|
ensureNewDocumentNavigation = !!response.loaderId;
|
||||||
return response.errorText
|
return response.errorText
|
||||||
? new Error(`${response.errorText} at ${url}`)
|
? new Error(`${response.errorText} at ${url}`)
|
||||||
: null;
|
: null;
|
||||||
|
@ -70,6 +70,7 @@ export class LifecycleWatcher {
|
|||||||
#timeout: number;
|
#timeout: number;
|
||||||
#navigationRequest: HTTPRequest | null = null;
|
#navigationRequest: HTTPRequest | null = null;
|
||||||
#eventListeners: PuppeteerEventListener[];
|
#eventListeners: PuppeteerEventListener[];
|
||||||
|
#initialLoaderId: string;
|
||||||
|
|
||||||
#sameDocumentNavigationCompleteCallback: (x?: Error) => void = noop;
|
#sameDocumentNavigationCompleteCallback: (x?: Error) => void = noop;
|
||||||
#sameDocumentNavigationPromise = new Promise<Error | undefined>(fulfill => {
|
#sameDocumentNavigationPromise = new Promise<Error | undefined>(fulfill => {
|
||||||
@ -97,7 +98,6 @@ export class LifecycleWatcher {
|
|||||||
|
|
||||||
#maximumTimer?: NodeJS.Timeout;
|
#maximumTimer?: NodeJS.Timeout;
|
||||||
#hasSameDocumentNavigation?: boolean;
|
#hasSameDocumentNavigation?: boolean;
|
||||||
#newDocumentNavigation?: boolean;
|
|
||||||
#swapped?: boolean;
|
#swapped?: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -111,6 +111,7 @@ export class LifecycleWatcher {
|
|||||||
} else if (typeof waitUntil === 'string') {
|
} else if (typeof waitUntil === 'string') {
|
||||||
waitUntil = [waitUntil];
|
waitUntil = [waitUntil];
|
||||||
}
|
}
|
||||||
|
this.#initialLoaderId = frame._loaderId;
|
||||||
this.#expectedLifecycle = waitUntil.map(value => {
|
this.#expectedLifecycle = waitUntil.map(value => {
|
||||||
const protocolEvent = puppeteerToProtocolLifecycle.get(value);
|
const protocolEvent = puppeteerToProtocolLifecycle.get(value);
|
||||||
assert(protocolEvent, 'Unknown value for options.waitUntil: ' + value);
|
assert(protocolEvent, 'Unknown value for options.waitUntil: ' + value);
|
||||||
@ -232,7 +233,6 @@ export class LifecycleWatcher {
|
|||||||
if (frame !== this.#frame) {
|
if (frame !== this.#frame) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.#newDocumentNavigation = true;
|
|
||||||
this.#checkLifecycleComplete();
|
this.#checkLifecycleComplete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -253,7 +253,7 @@ export class LifecycleWatcher {
|
|||||||
if (this.#hasSameDocumentNavigation) {
|
if (this.#hasSameDocumentNavigation) {
|
||||||
this.#sameDocumentNavigationCompleteCallback();
|
this.#sameDocumentNavigationCompleteCallback();
|
||||||
}
|
}
|
||||||
if (this.#swapped || this.#newDocumentNavigation) {
|
if (this.#swapped || this.#frame._loaderId !== this.#initialLoaderId) {
|
||||||
this.#newDocumentNavigationCompleteCallback();
|
this.#newDocumentNavigationCompleteCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user