2023-10-17 22:14:08 +07:00
|
|
|
/**
|
|
|
|
* Copyright 2023 Fluence Labs Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
import { symlink, access } from "fs/promises";
|
|
|
|
import { dirname, join } from "path";
|
|
|
|
import { fileURLToPath } from "url";
|
|
|
|
|
|
|
|
import {
|
|
|
|
CDN_PUBLIC_PATH,
|
|
|
|
startContentServer,
|
|
|
|
stopServer,
|
|
|
|
} from "@test/test-utils";
|
|
|
|
import puppeteer from "puppeteer";
|
2023-03-07 20:07:52 +04:00
|
|
|
|
|
|
|
const port = 3000;
|
|
|
|
const uri = `http://localhost:${port}/`;
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
2023-10-17 22:14:08 +07:00
|
|
|
const publicPath = join(__dirname, "../public/");
|
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);
|
|
|
|
|
|
|
|
try {
|
|
|
|
await access(join(publicPath, "source"));
|
|
|
|
} catch {
|
|
|
|
await symlink(CDN_PUBLIC_PATH, join(publicPath, "source"));
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("starting puppeteer...");
|
|
|
|
const browser = await puppeteer.launch();
|
|
|
|
const page = (await browser.pages())[0];
|
|
|
|
|
|
|
|
// uncomment to debug what's happening inside the browser
|
|
|
|
// page.on('console', (msg) => console.log('// from console: ', msg.text()));
|
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...");
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
const content = await elem?.evaluate((x) => {
|
|
|
|
return x.textContent;
|
|
|
|
});
|
2023-03-07 20:07:52 +04:00
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
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 == null) {
|
|
|
|
throw new Error("smoke test failed!");
|
|
|
|
}
|
2023-03-07 20:07:52 +04:00
|
|
|
};
|
|
|
|
|
2023-10-17 22:14:08 +07:00
|
|
|
void test().then(() => {
|
|
|
|
console.log("smoke tests succeed!");
|
|
|
|
});
|