chore: now we have puppeteer!

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2021-10-28 18:06:47 +02:00
parent e3ef16366e
commit 4b2740332c
3 changed files with 16 additions and 13 deletions
+1 -3
View File
@@ -35,6 +35,7 @@
"fs-extra": "9.1.0",
"handlebars": "^4.7.3",
"pgtools": "^0.3.0",
"puppeteer": "^10.4.0",
"tree-kill": "^1.2.2",
"ts-node": "^10.0.0"
},
@@ -42,8 +43,5 @@
"watch": "./src",
"exec": "bin/e2e-test",
"ext": "ts"
},
"dependencies": {
"puppeteer": "^10.4.0"
}
}
+7 -4
View File
@@ -352,14 +352,16 @@ async function testAppServe(pluginName: string, appDir: string) {
},
});
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://localhost:3000');
let successful = false;
let browser;
try {
for (let attempts = 1; ; attempts++) {
try {
browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('http://localhost:3000');
await waitForPageWithText(page, '/', 'My Company Catalog');
await waitForPageWithText(
page,
@@ -380,6 +382,7 @@ async function testAppServe(pluginName: string, appDir: string) {
}
} finally {
// Kill entire process group, otherwise we'll end up with hanging serve processes
if (browser) await browser.close();
killTree(startApp.pid);
}
+8 -6
View File
@@ -141,13 +141,15 @@ export async function waitForPageWithText(
await page.goto(`http://localhost:3000${path}`);
const escapedText = text.replace(/"|\\/g, '\\$&');
await expect(() =>
page.evaluate(() =>
Array.from(document.querySelectorAll('*')).some(
el => el.textContent === escapedText,
),
const match = await page.evaluate(() =>
Array.from(document.querySelectorAll('*')).some(
el => el.textContent === escapedText,
),
).resolves.toBeTruthy();
);
if (!match) {
throw new Error(`Expected to find text ${escapedText}`);
}
break;
} catch (error) {