import assert from 'assert'; import fs from 'node:fs/promises'; import http from 'http'; import path from 'path'; import { fileURLToPath } from 'url'; import { chromium } from 'playwright'; const PORT = 5001; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const pkgPath = path.join(__dirname, '../package.json'); const { version } = JSON.parse(await fs.readFile(pkgPath, 'utf-8')); const fixture = ` `; const expected = ` `; const content = ` `; const server = http.createServer(async (req, res) => { if (req.url === '/') { res.setHeader('Content-Type', 'text/html'); res.end(content); } if (req.url === '/svgo.browser.js') { res.setHeader('Content-Type', 'application/javascript'); res.end(await fs.readFile('./dist/svgo.browser.js')); } res.end(); }); const runTest = async () => { const browser = await chromium.launch(); const context = await browser.newContext(); const page = await context.newPage(); await page.goto(`http://localhost:${PORT}`); const actual = await page.evaluate(() => ({ version: globalThis.version, builtinPlugins: globalThis.builtinPlugins, _collections: globalThis._collections, result: globalThis.result, })); assert.strictEqual(actual.version, version); assert.notEqual( actual.builtinPlugins, undefined, 'builtinPlugins must be defined', ); assert.notEqual( actual._collections, undefined, '_collections must be defined', ); assert.equal(actual.result, expected); await browser.close(); }; server.listen(PORT, async () => { try { await runTest(); console.info('Tested successfully'); server.close(); } catch (error) { server.close(); console.error(error.toString()); process.exit(1); } });