chore: make test more timing resilient (#1473)
This commit is contained in:
+32
-87
@@ -5,7 +5,11 @@ import {
|
||||
delay,
|
||||
Page,
|
||||
} from "./deps.ts";
|
||||
import { withPageName } from "./test_utils.ts";
|
||||
import {
|
||||
clickWhenListenerReady,
|
||||
waitForText,
|
||||
withPageName,
|
||||
} from "./test_utils.ts";
|
||||
|
||||
Deno.test({
|
||||
name: "island tests",
|
||||
@@ -14,16 +18,11 @@ Deno.test({
|
||||
async function counterTest(counterId: string, originalValue: number) {
|
||||
const pElem = await page.waitForSelector(`#${counterId} > p`);
|
||||
|
||||
let value = await pElem?.evaluate((el) => el.textContent);
|
||||
const value = await pElem?.evaluate((el) => el.textContent);
|
||||
assert(value === `${originalValue}`, `${counterId} first value`);
|
||||
|
||||
const buttonPlus = await page.$(`#b-${counterId}`);
|
||||
await buttonPlus?.click();
|
||||
|
||||
await delay(100);
|
||||
|
||||
value = await pElem?.evaluate((el) => el.textContent);
|
||||
assert(value === `${originalValue + 1}`, `${counterId} click`);
|
||||
await clickWhenListenerReady(page, `#b-${counterId}`);
|
||||
await waitForText(page, `#${counterId} > p`, String(originalValue + 1));
|
||||
}
|
||||
|
||||
await page.goto(`${address}/islands`, {
|
||||
@@ -66,16 +65,11 @@ Deno.test({
|
||||
async function counterTest(counterId: string, originalValue: number) {
|
||||
const pElem = await page.waitForSelector(`#${counterId} > p`);
|
||||
|
||||
let value = await pElem?.evaluate((el) => el.textContent);
|
||||
const value = await pElem?.evaluate((el) => el.textContent);
|
||||
assert(value === `${originalValue}`, `${counterId} first value`);
|
||||
|
||||
const buttonPlus = await page.$(`#b-${counterId}`);
|
||||
await buttonPlus?.click();
|
||||
|
||||
await delay(100);
|
||||
|
||||
value = await pElem?.evaluate((el) => el.textContent);
|
||||
assert(value === `${originalValue + 1}`, `${counterId} click`);
|
||||
await clickWhenListenerReady(page, `#b-${counterId}`);
|
||||
await waitForText(page, `#${counterId} > p`, String(originalValue + 1));
|
||||
}
|
||||
|
||||
await page.goto(`${address}/islands/multiple_island_exports`, {
|
||||
@@ -141,21 +135,10 @@ Deno.test({
|
||||
|
||||
await page.waitForSelector(clickableSelector);
|
||||
|
||||
const contentBeforeClick = await getIslandParentTextContent();
|
||||
assert(contentBeforeClick === "HelloWorld");
|
||||
await waitForText(page, `#island-parent`, "HelloWorld");
|
||||
|
||||
await page.click(clickableSelector);
|
||||
await delay(100);
|
||||
|
||||
const contentAfterClick = await getIslandParentTextContent();
|
||||
assert(contentAfterClick === "HelloWorldI'm rendered now");
|
||||
|
||||
async function getIslandParentTextContent() {
|
||||
return await page.$eval(
|
||||
"#island-parent",
|
||||
(el: Element) => el.textContent,
|
||||
);
|
||||
}
|
||||
await clickWhenListenerReady(page, clickableSelector);
|
||||
await waitForText(page, `#island-parent`, "HelloWorldI'm rendered now");
|
||||
});
|
||||
},
|
||||
|
||||
@@ -178,14 +161,14 @@ Deno.test({
|
||||
const clickableSelector = "#root-fragment-conditional-first-click-me";
|
||||
await page.waitForSelector(clickableSelector);
|
||||
|
||||
const contentBeforeClick = await getIslandParentTextContent(page);
|
||||
assert(contentBeforeClick === "HelloWorld");
|
||||
await waitForText(page, "#island-parent", "HelloWorld");
|
||||
|
||||
await page.click(clickableSelector);
|
||||
await delay(100);
|
||||
|
||||
const contentAfterClick = await getIslandParentTextContent(page);
|
||||
assert(contentAfterClick === "I'm rendered on topHelloWorld");
|
||||
await clickWhenListenerReady(page, clickableSelector);
|
||||
await waitForText(
|
||||
page,
|
||||
"#island-parent",
|
||||
"I'm rendered on topHelloWorld",
|
||||
);
|
||||
});
|
||||
},
|
||||
|
||||
@@ -193,10 +176,6 @@ Deno.test({
|
||||
sanitizeResources: false,
|
||||
});
|
||||
|
||||
async function getIslandParentTextContent(page: Page) {
|
||||
return await page.$eval("#island-parent", (el: Element) => el.textContent);
|
||||
}
|
||||
|
||||
Deno.test({
|
||||
name: "island that returns `null`",
|
||||
|
||||
@@ -244,10 +223,7 @@ Deno.test({
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
await page.waitForSelector("#foo");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval("#foo", (el) => el.textContent);
|
||||
assertEquals(text, "it works");
|
||||
await waitForText(page, "#foo", "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -267,10 +243,7 @@ Deno.test({
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(".island", (el) => el.textContent);
|
||||
assertEquals(text, "it works");
|
||||
await waitForText(page, ".island", "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -336,13 +309,7 @@ Deno.test({
|
||||
waitUntil: "networkidle2",
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(
|
||||
".island .island p",
|
||||
(el) => el.textContent,
|
||||
);
|
||||
assertEquals(text, "it works");
|
||||
await waitForText(page, ".island .island p", "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -363,17 +330,11 @@ Deno.test({
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(
|
||||
".island .island p",
|
||||
(el) => el.textContent,
|
||||
);
|
||||
assertEquals(text, "it works");
|
||||
await waitForText(page, ".island .island p", "it works");
|
||||
|
||||
// Check that there is no duplicated content which could happen
|
||||
// when islands aren't initialized correctly
|
||||
const pageText = await page.$eval("#page", (el) => el.textContent);
|
||||
assertEquals(pageText, "it works");
|
||||
await waitForText(page, "#page", "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -395,12 +356,11 @@ Deno.test({
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(
|
||||
await waitForText(
|
||||
page,
|
||||
".island .server .island .server p",
|
||||
(el) => el.textContent,
|
||||
"it works",
|
||||
);
|
||||
assertEquals(text, "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -421,18 +381,8 @@ Deno.test({
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(
|
||||
".island .a",
|
||||
(el) => el.textContent,
|
||||
);
|
||||
assertEquals(text, "it works");
|
||||
|
||||
const text2 = await page.$eval(
|
||||
".island + .island .b",
|
||||
(el) => el.textContent,
|
||||
);
|
||||
assertEquals(text2, "it works");
|
||||
await waitForText(page, ".island .a", "it works");
|
||||
await waitForText(page, ".island + .island .b", "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
@@ -484,12 +434,7 @@ Deno.test({
|
||||
});
|
||||
await page.waitForSelector(".island");
|
||||
|
||||
await delay(100);
|
||||
const text = await page.$eval(
|
||||
".island .island p",
|
||||
(el) => el.textContent,
|
||||
);
|
||||
assertEquals(text, "it works");
|
||||
await waitForText(page, ".island .island p", "it works");
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user