providers/tests/browser/startup.mjs

37 lines
807 B
JavaScript
Raw Normal View History

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,
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);
}
}
console.log('Success!');
2024-03-29 20:23:32 +00:00
process.exit(0);