2023-10-17 22:14:08 +07:00
|
|
|
import puppeteer from "puppeteer";
|
|
|
|
import { dirname, join } from "path";
|
|
|
|
import { fileURLToPath } from "url";
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
import {
|
|
|
|
CDN_PUBLIC_PATH,
|
2023-10-18 08:38:49 +07:00
|
|
|
createSymlinkIfNotExists,
|
|
|
|
JS_CLIENT_DEPS_PATH,
|
2023-10-17 22:14:08 +07:00
|
|
|
startContentServer,
|
|
|
|
stopServer,
|
|
|
|
} from "@test/test-utils";
|
2023-03-07 20:07:52 +04:00
|
|
|
|
|
|
|
const port = 3001;
|
|
|
|
const uri = `http://localhost:${port}/`;
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
2023-10-17 22:14:08 +07:00
|
|
|
const publicPath = join(__dirname, "../build/");
|
2023-03-07 20:07:52 +04:00
|
|
|
|
|
|
|
const test = async () => {
|
2023-10-17 22:14:08 +07:00
|
|
|
const localServer = await startContentServer(port, publicPath);
|
2023-11-10 21:29:49 +07:00
|
|
|
|
2023-10-18 08:38:49 +07:00
|
|
|
await createSymlinkIfNotExists(
|
|
|
|
JS_CLIENT_DEPS_PATH,
|
|
|
|
join(publicPath, "node_modules"),
|
|
|
|
);
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
console.log("starting puppeteer...");
|
|
|
|
const browser = await puppeteer.launch();
|
|
|
|
const page = (await browser.pages())[0];
|
2023-10-18 09:50:35 +07:00
|
|
|
page.on("console", (message) =>
|
|
|
|
console.log(`${message.type().toUpperCase()}: ${message.text()}`),
|
|
|
|
);
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-18 11:48:58 +07:00
|
|
|
page.on("request", (request) => {
|
|
|
|
console.log(`INFO: ${request.url()} ${request.method()}`);
|
|
|
|
});
|
|
|
|
|
2023-10-18 10:54:14 +07:00
|
|
|
page.on("requestfailed", (request) => {
|
|
|
|
console.log(`ERROR: ${request.url()} ${request.failure()?.errorText}`);
|
|
|
|
});
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
console.log("going to the page in browser...");
|
|
|
|
await page.goto(uri);
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
console.log("clicking button...");
|
|
|
|
await page.click("#btn");
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
console.log("waiting for result to appear...");
|
|
|
|
const elem = await page.waitForSelector("#res");
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
console.log("getting the content of result div...");
|
|
|
|
const content = await elem?.evaluate((x) => x.textContent);
|
|
|
|
console.log("raw result: ", content);
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
await browser.close();
|
|
|
|
await stopServer(localServer);
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
if (!content) {
|
|
|
|
throw new Error("smoke test failed!");
|
|
|
|
}
|
2023-03-07 20:07:52 +04:00
|
|
|
};
|
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
test().then(() => console.log("smoke tests succeed!"));
|