Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use loaderId to reduce test flakiness #8717

Merged
merged 1 commit into from Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/common/FrameManager.ts
Expand Up @@ -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),
Expand All @@ -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();
Expand All @@ -243,6 +245,7 @@ export class FrameManager extends EventEmitter {
referrer,
frameId,
});
ensureNewDocumentNavigation = !!response.loaderId;
return response.errorText
? new Error(`${response.errorText} at ${url}`)
: null;
Expand Down
6 changes: 3 additions & 3 deletions src/common/LifecycleWatcher.ts
Expand Up @@ -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 => {
Expand Down Expand Up @@ -97,7 +98,6 @@ export class LifecycleWatcher {

#maximumTimer?: NodeJS.Timeout;
#hasSameDocumentNavigation?: boolean;
#newDocumentNavigation?: boolean;
#swapped?: boolean;

constructor(
Expand All @@ -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);
Expand Down Expand Up @@ -232,7 +233,6 @@ export class LifecycleWatcher {
if (frame !== this.#frame) {
return;
}
this.#newDocumentNavigation = true;
this.#checkLifecycleComplete();
}

Expand All @@ -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();
}

Expand Down