2023-03-07 20:07:52 +04:00
|
|
|
import puppeteer from 'puppeteer';
|
|
|
|
import { dirname, join } from 'path';
|
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
|
2023-08-25 00:15:49 +07:00
|
|
|
import { CDN_PUBLIC_PATH, startContentServer, stopServer } from '@test/test-utils';
|
|
|
|
import { access, symlink } from 'fs/promises';
|
2023-03-07 20:07:52 +04:00
|
|
|
|
|
|
|
const port = 3001;
|
|
|
|
const uri = `http://localhost:${port}/`;
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
const publicPath = join(__dirname, '../build/');
|
|
|
|
|
|
|
|
const test = async () => {
|
|
|
|
const localServer = await startContentServer(port, publicPath);
|
2023-08-25 00:15:49 +07:00
|
|
|
try {
|
|
|
|
await access(join(publicPath, 'source'))
|
|
|
|
} catch {
|
|
|
|
await symlink(CDN_PUBLIC_PATH, join(publicPath, 'source'));
|
|
|
|
}
|
2023-03-07 20:07:52 +04:00
|
|
|
|
|
|
|
console.log('starting puppeteer...');
|
2023-09-29 16:23:06 +07:00
|
|
|
const browser = await puppeteer.launch();
|
2023-08-25 00:15:49 +07:00
|
|
|
const page = (await browser.pages())[0];
|
2023-03-07 20:07:52 +04:00
|
|
|
|
|
|
|
// uncomment to debug what's happening inside the browser
|
|
|
|
// page.on('console', (msg) => console.log('// from console: ', msg.text()));
|
|
|
|
|
|
|
|
console.log('going to the page in browser...');
|
|
|
|
await page.goto(uri);
|
|
|
|
|
|
|
|
console.log('clicking button...');
|
|
|
|
await page.click('#btn');
|
|
|
|
|
|
|
|
console.log('waiting for result to appear...');
|
|
|
|
const elem = await page.waitForSelector('#res');
|
|
|
|
|
|
|
|
console.log('getting the content of result div...');
|
|
|
|
const content = await elem?.evaluate((x) => x.textContent);
|
|
|
|
console.log('raw result: ', content);
|
|
|
|
|
|
|
|
await browser.close();
|
|
|
|
await stopServer(localServer);
|
|
|
|
|
|
|
|
if (!content) {
|
|
|
|
throw new Error('smoke test failed!');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
test().then(() => console.log('smoke tests succeed!'));
|