mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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(),
|
||||
} = options;
|
||||
|
||||
let ensureNewDocumentNavigation = false;
|
||||
const watcher = new LifecycleWatcher(this, frame, waitUntil, timeout);
|
||||
let error = await Promise.race([
|
||||
navigate(this.#client, url, referer, frame._id),
|
||||
@ -221,8 +222,9 @@ export class FrameManager extends EventEmitter {
|
||||
if (!error) {
|
||||
error = await Promise.race([
|
||||
watcher.timeoutOrTerminationPromise(),
|
||||
watcher.newDocumentNavigationPromise(),
|
||||
watcher.sameDocumentNavigationPromise(),
|
||||
ensureNewDocumentNavigation
|
||||
? watcher.newDocumentNavigationPromise()
|
||||
: watcher.sameDocumentNavigationPromise(),
|
||||
]);
|
||||
}
|
||||
watcher.dispose();
|
||||
@ -243,6 +245,7 @@ export class FrameManager extends EventEmitter {
|
||||
referrer,
|
||||
frameId,
|
||||
});
|
||||
ensureNewDocumentNavigation = !!response.loaderId;
|
||||
return response.errorText
|
||||
? new Error(`${response.errorText} at ${url}`)
|
||||
: null;
|
||||
|
@ -70,6 +70,7 @@ export class LifecycleWatcher {
|
||||
#timeout: number;
|
||||
#navigationRequest: HTTPRequest | null = null;
|
||||
#eventListeners: PuppeteerEventListener[];
|
||||
#initialLoaderId: string;
|
||||
|
||||
#sameDocumentNavigationCompleteCallback: (x?: Error) => void = noop;
|
||||
#sameDocumentNavigationPromise = new Promise<Error | undefined>(fulfill => {
|
||||
@ -97,7 +98,6 @@ export class LifecycleWatcher {
|
||||
|
||||
#maximumTimer?: NodeJS.Timeout;
|
||||
#hasSameDocumentNavigation?: boolean;
|
||||
#newDocumentNavigation?: boolean;
|
||||
#swapped?: boolean;
|
||||
|
||||
constructor(
|
||||
@ -111,6 +111,7 @@ export class LifecycleWatcher {
|
||||
} else if (typeof waitUntil === 'string') {
|
||||
waitUntil = [waitUntil];
|
||||
}
|
||||
this.#initialLoaderId = frame._loaderId;
|
||||
this.#expectedLifecycle = waitUntil.map(value => {
|
||||
const protocolEvent = puppeteerToProtocolLifecycle.get(value);
|
||||
assert(protocolEvent, 'Unknown value for options.waitUntil: ' + value);
|
||||
@ -232,7 +233,6 @@ export class LifecycleWatcher {
|
||||
if (frame !== this.#frame) {
|
||||
return;
|
||||
}
|
||||
this.#newDocumentNavigation = true;
|
||||
this.#checkLifecycleComplete();
|
||||
}
|
||||
|
||||
@ -253,7 +253,7 @@ export class LifecycleWatcher {
|
||||
if (this.#hasSameDocumentNavigation) {
|
||||
this.#sameDocumentNavigationCompleteCallback();
|
||||
}
|
||||
if (this.#swapped || this.#newDocumentNavigation) {
|
||||
if (this.#swapped || this.#frame._loaderId !== this.#initialLoaderId) {
|
||||
this.#newDocumentNavigationCompleteCallback();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user