2023-12-24 17:02:56 +00:00
|
|
|
import { build, preview } from 'vite';
|
|
|
|
import puppeteer from 'puppeteer';
|
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
import { dirname } from 'path';
|
|
|
|
|
|
|
|
const root = dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
|
|
|
await build({
|
|
|
|
root,
|
|
|
|
});
|
|
|
|
const server = await preview({
|
|
|
|
root,
|
|
|
|
});
|
|
|
|
let browser;
|
|
|
|
try {
|
|
|
|
browser = await puppeteer.launch({
|
2024-03-31 13:25:30 +00:00
|
|
|
headless: true,
|
2023-12-24 17:02:56 +00:00
|
|
|
args: ['--no-sandbox', '--disable-setuid-sandbox'],
|
|
|
|
});
|
|
|
|
const page = await browser.newPage();
|
|
|
|
await page.goto(server.resolvedUrls.local[0]);
|
|
|
|
await page.waitForFunction('!!window.TEST', { timeout: 5000 });
|
|
|
|
await page.evaluate(() => {
|
|
|
|
window.TEST();
|
|
|
|
});
|
|
|
|
} finally {
|
|
|
|
server.httpServer.close();
|
2024-03-31 13:26:33 +00:00
|
|
|
try {
|
|
|
|
await browser.close();
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Failed to close browser:', e);
|
|
|
|
}
|
2023-12-24 17:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Success!');
|
2024-03-29 20:23:32 +00:00
|
|
|
process.exit(0);
|