Skip to content

Commit c91b39f

Browse files
Abe27342Abram Sanderson
andauthored
Improve presence-tracker test reliability (#23707)
## Description For the two-client tests (recently added), adds an attempt to load the presence tracker app in the newer browser as part of the 45s `beforeAll` timeout. This matches the one-client tests more closely, which already ensure the page loads once successfully within 45s before beginning the test suite. We saw this test suite fail on the subsequent `beforeEach` hook due to a 5s timeout, which is somewhat plausible if the browser startup wasn't fresh and/or page cache isn't shared with the first browser. --------- Co-authored-by: Abram Sanderson <[email protected]>
1 parent 0052d4c commit c91b39f

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

examples/apps/presence-tracker/tests/presenceTracker.test.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,25 @@ const initializeBrowser = async () => {
2121
return browser;
2222
};
2323

24+
/**
25+
* @param page The page to load the presence tracker app on.
26+
*/
27+
const loadPresenceTrackerApp = async (page: Page, url: string) => {
28+
await page.goto(url, { waitUntil: "load" });
29+
// eslint-disable-next-line @typescript-eslint/dot-notation, @typescript-eslint/no-unsafe-return
30+
await page.waitForFunction(() => window["fluidStarted"]);
31+
};
32+
2433
// Most tests are passing when tinylicious is running. Those that aren't are individually skipped.
2534
describe("presence-tracker", () => {
2635
beforeAll(async () => {
27-
// Wait for the page to load first before running any tests
28-
// so this time isn't attributed to the first test
29-
await page.goto(globals.PATH, { waitUntil: "load", timeout: 0 });
30-
// eslint-disable-next-line @typescript-eslint/dot-notation, @typescript-eslint/no-unsafe-return
31-
await page.waitForFunction(() => window["fluidStarted"]);
36+
// Wait for the page to load first before running any tests giving a more generous timeout
37+
// so this time isn't attributed to the first test.
38+
await loadPresenceTrackerApp(page, globals.PATH);
3239
}, 45000);
3340

3441
beforeEach(async () => {
35-
await page.goto(globals.PATH, { waitUntil: "load" });
36-
// eslint-disable-next-line @typescript-eslint/dot-notation, @typescript-eslint/no-unsafe-return
37-
await page.waitForFunction(() => window["fluidStarted"]);
42+
await loadPresenceTrackerApp(page, globals.PATH);
3843
});
3944

4045
describe("Single client", () => {
@@ -89,13 +94,11 @@ describe("presence-tracker", () => {
8994
// Create a second browser instance.
9095
browser2 = await initializeBrowser();
9196
page2 = await browser2.newPage();
97+
await loadPresenceTrackerApp(page2, page.url());
9298
}, 45000);
9399

94100
beforeEach(async () => {
95-
// Navigate to the URL/session created by the first browser.
96-
await page2.goto(page.url(), { waitUntil: "load" });
97-
// eslint-disable-next-line @typescript-eslint/dot-notation, @typescript-eslint/no-unsafe-return
98-
await page2.waitForFunction(() => window["fluidStarted"]);
101+
await loadPresenceTrackerApp(page2, page.url());
99102
});
100103

101104
afterAll(async () => {

0 commit comments

Comments
 (0)