1// @ts-check 2const chalk = require("chalk"); 3const { join } = require("path"); 4const { readFileSync } = require("fs"); 5try { 6 // eslint-disable-next-line import/no-extraneous-dependencies 7 require("playwright"); 8} 9catch (error) { 10 throw new Error("Playwright is expected to be installed manually before running this script"); 11} 12 13// eslint-disable-next-line import/no-extraneous-dependencies 14const playwright = require("playwright"); 15 16// Turning this on will leave the Chromium browser open, giving you the 17// chance to open up the web inspector. 18const debugging = false; 19 20(async () => { 21 for (const browserType of ["chromium", "firefox"]) { 22 const browser = await playwright[browserType].launch({ headless: !debugging }); 23 const context = await browser.newContext(); 24 const page = await context.newPage(); 25 26 const errorCaught = err => { 27 console.error(chalk.red("There was an error running built/typescript.js in " + browserType)); 28 console.log(err.toString()); 29 process.exitCode = 1; 30 }; 31 32 page.on("error", errorCaught); 33 page.on("pageerror", errorCaught); 34 35 await page.setContent(` 36 <html> 37 <script>${readFileSync(join("built", "local", "typescript.js"), "utf8")}</script> 38 </html> 39 `); 40 41 if (!debugging) { 42 await browser.close(); 43 } 44 else { 45 console.log("Not closing the browser, you'll need to exit the process in your terminal manually"); 46 } 47 console.log(`${browserType} :+1:`); 48 } 49})(); 50 51process.on("unhandledRejection", (/** @type {any}*/ err) => { 52 if (err) { 53 console.error(err.stack || err.message); 54 } 55 process.exit(1); 56}); 57 58