@@ -28,6 +28,7 @@
|
||||
"@backstage/errors": "^0.1.2",
|
||||
"@types/fs-extra": "^9.0.1",
|
||||
"@types/node": "^14.14.32",
|
||||
"@types/puppeteer": "^5.4.4",
|
||||
"chalk": "^4.0.0",
|
||||
"commander": "^6.1.0",
|
||||
"cross-fetch": "^3.0.6",
|
||||
@@ -35,12 +36,14 @@
|
||||
"handlebars": "^4.7.3",
|
||||
"pgtools": "^0.3.0",
|
||||
"tree-kill": "^1.2.2",
|
||||
"ts-node": "^10.0.0",
|
||||
"zombie": "^6.1.4"
|
||||
"ts-node": "^10.0.0"
|
||||
},
|
||||
"nodemonConfig": {
|
||||
"watch": "./src",
|
||||
"exec": "bin/e2e-test",
|
||||
"ext": "ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"puppeteer": "^10.4.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ import fetch from 'cross-fetch';
|
||||
import handlebars from 'handlebars';
|
||||
import killTree from 'tree-kill';
|
||||
import { resolve as resolvePath, join as joinPath } from 'path';
|
||||
import Browser from 'zombie';
|
||||
import puppeteer from 'puppeteer';
|
||||
|
||||
import {
|
||||
spawnPiped,
|
||||
runPlain,
|
||||
@@ -350,17 +351,18 @@ async function testAppServe(pluginName: string, appDir: string) {
|
||||
GITHUB_TOKEN: 'abc',
|
||||
},
|
||||
});
|
||||
Browser.localhost('localhost', 3000);
|
||||
|
||||
const browser = await puppeteer.launch();
|
||||
const page = await browser.newPage();
|
||||
await page.goto('http://localhost:3000');
|
||||
|
||||
let successful = false;
|
||||
try {
|
||||
for (let attempts = 1; ; attempts++) {
|
||||
try {
|
||||
const browser = new Browser();
|
||||
|
||||
await waitForPageWithText(browser, '/', 'My Company Catalog');
|
||||
await waitForPageWithText(page, '/', 'My Company Catalog');
|
||||
await waitForPageWithText(
|
||||
browser,
|
||||
page,
|
||||
`/${pluginName}`,
|
||||
`Welcome to ${pluginName}!`,
|
||||
);
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
ChildProcess,
|
||||
} from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
import puppeteer from 'puppeteer';
|
||||
|
||||
const execFile = promisify(execFileCb);
|
||||
|
||||
@@ -125,7 +126,7 @@ export async function waitForExit(child: ChildProcess) {
|
||||
}
|
||||
|
||||
export async function waitForPageWithText(
|
||||
browser: any,
|
||||
page: puppeteer.Page,
|
||||
path: string,
|
||||
text: string,
|
||||
{ intervalMs = 1000, maxFindAttempts = 50 } = {},
|
||||
@@ -137,16 +138,17 @@ export async function waitForPageWithText(
|
||||
console.log(`Attempting to load page at ${path}, waiting ${waitTimeMs}`);
|
||||
await new Promise(resolve => setTimeout(resolve, waitTimeMs));
|
||||
|
||||
await browser.visit(path);
|
||||
|
||||
await new Promise(resolve => setTimeout(resolve, waitTimeMs));
|
||||
await page.goto(`http://localhost:3000${path}`);
|
||||
|
||||
const escapedText = text.replace(/"|\\/g, '\\$&');
|
||||
browser.assert.evaluate(
|
||||
`Array.from(document.querySelectorAll("*")).some(el => el.textContent === "${escapedText}")`,
|
||||
true,
|
||||
`expected to find text ${text}`,
|
||||
);
|
||||
await expect(() =>
|
||||
page.evaluate(() =>
|
||||
Array.from(document.querySelectorAll('*')).some(
|
||||
el => el.textContent === escapedText,
|
||||
),
|
||||
),
|
||||
).resolves.toBeTruthy();
|
||||
|
||||
break;
|
||||
} catch (error) {
|
||||
assertError(error);
|
||||
|
||||
Reference in New Issue
Block a user