()
| 299 | } |
| 300 | |
| 301 | async function testDom() { |
| 302 | const port = getAvailablePort(); |
| 303 | let served404 = false; |
| 304 | const httpServer = Deno.serve({ port }, async (req) => { |
| 305 | const url = new URL(req.url); |
| 306 | let path = decodeURIComponent(url.pathname); |
| 307 | if (path.startsWith("/")) { |
| 308 | path = "." + path; |
| 309 | } |
| 310 | if (!(await fs.exists(path))) { |
| 311 | console.error("dom-tests: requested missing file (not found):", path); |
| 312 | served404 = true; |
| 313 | return new Response(null, { status: 404 }); |
| 314 | } else { |
| 315 | return fileServer.serveFile(req, path); |
| 316 | } |
| 317 | }); |
| 318 | |
| 319 | const files = ["dom_tests.html"]; |
| 320 | const browser = await puppeteer.launch(); |
| 321 | let success = true; |
| 322 | for (const file of files) { |
| 323 | const page = await browser.newPage(); |
| 324 | console.log("Running", file); |
| 325 | setupPuppeteerPageForTests(page); |
| 326 | const url = `http://localhost:${port}/tests/dom_tests/${file}?dom_tests=true`; |
| 327 | const result = await runPuppeteerTest(page, url); |
| 328 | success = success && result; |
| 329 | if (served404) { |
| 330 | console.log(`${file} failed: a background or content script requested a missing file.`); |
| 331 | } |
| 332 | if (page.receivedErrorOutput) { |
| 333 | console.log(`${file} failed: there was a page level error.`); |
| 334 | success = false; |
| 335 | } |
| 336 | // If we close the puppeteer page (tab) via page.close(), we can get innocuous but noisy output |
| 337 | // like this: |
| 338 | // net::ERR_ABORTED http://localhost:43524/pages/hud_page.html?dom_tests=true |
| 339 | // There's probably a way to prevent that, but as a work around, we avoid closing the page. |
| 340 | // browser.close() will close all of its owned pages. |
| 341 | } |
| 342 | // NOTE(philc): At one point in development, I noticed that the output from Deno would suddenly |
| 343 | // pause, prior to the tests fully finishing, so closing the browser here may be racy. If it |
| 344 | // occurs again, we may need to add "await delay(200)". |
| 345 | await browser.close(); |
| 346 | await httpServer.shutdown(); |
| 347 | if (served404 || !success) { |
| 348 | abort("test-dom failed."); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | desc("Run DOM tests"); |
| 353 | task("test-dom", [], testDom); |
nothing calls this directly
no test coverage detected