diff --git a/etc/puppeteer.js b/etc/puppeteer.js new file mode 100644 index 0000000..9d561dc --- /dev/null +++ b/etc/puppeteer.js @@ -0,0 +1,39 @@ +const console = require("node:console"); +const {writeFile} = require("node:fs/promises"); +const {createServer} = require("node:http"); +const process = require("node:process"); +const puppeteer = require("puppeteer"); +const handler = require("serve-handler"); + +// Run the test suite. +(async function main() { + const browser = await puppeteer.launch(); + const server = createServer((req, res) => handler(req, res, {public: "var"})); + + const page = await browser.newPage(); + page.on("console", message => console.log(message.text())); + page.on("pageerror", error => console.error(error)); + + await page.evaluate(() => console.log(navigator.userAgent)); + await page.exposeFunction("exit", async code => { + await browser.close(); + server.close(); + process.exit(code); + }); + + await writeFile("var/tests.html", ` + + + + + + + + + `); + + server.listen(0, "127.0.0.1", () => { + const {address, port} = server.address(); + page.goto(`http://${address}:${port}/tests.html`); + }); +})(); diff --git a/etc/puppeteer.mjs b/etc/puppeteer.mjs deleted file mode 100644 index 0b447d8..0000000 --- a/etc/puppeteer.mjs +++ /dev/null @@ -1,38 +0,0 @@ -import console from "node:console"; -import {writeFile} from "node:fs/promises"; -import {createServer} from "node:http"; -import process from "node:process"; -import puppeteer from "puppeteer"; -import handler from "serve-handler"; - -// Start the browser. -const browser = await puppeteer.launch(); -const server = createServer((req, res) => handler(req, res, {public: "var"})); - -const page = await browser.newPage(); -page.on("console", message => console.log(message.text())); -page.on("pageerror", error => console.error(error)); - -await page.evaluate(() => console.log(navigator.userAgent)); -await page.exposeFunction("exit", async code => { - await browser.close(); - server.close(); - process.exit(code); -}); - -// Run the test suite. -await writeFile("var/tests.html", ` - - - - - - - - -`); - -server.listen(0, "127.0.0.1", () => { - const {address, port} = server.address(); - page.goto(`http://${address}:${port}/tests.html`); -}); diff --git a/test.hxml b/test.hxml index a91f3d7..006a83d 100644 --- a/test.hxml +++ b/test.hxml @@ -5,4 +5,4 @@ --library tink_unittest --main RunTests share/build.hxml ---cmd node etc/puppeteer.mjs +--cmd node etc/puppeteer.js