mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-15 22:15:18 -05:00
Convert scripts/Gulpfile to checked mjs/cjs so they can run without compilation (#50988)
This commit is contained in:
50
scripts/browserIntegrationTest.mjs
Normal file
50
scripts/browserIntegrationTest.mjs
Normal file
@@ -0,0 +1,50 @@
|
||||
import chalk from "chalk";
|
||||
import { join } from "path";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
let playwright;
|
||||
try {
|
||||
// @ts-ignore-error
|
||||
playwright = await import("playwright");
|
||||
}
|
||||
catch (error) {
|
||||
throw new Error("Playwright is expected to be installed manually before running this script");
|
||||
}
|
||||
|
||||
// Turning this on will leave the Chromium browser open, giving you the
|
||||
// chance to open up the web inspector.
|
||||
const debugging = false;
|
||||
|
||||
/** @type {["chromium", "firefox"]} */
|
||||
const browsers = ["chromium", "firefox"];
|
||||
|
||||
for (const browserType of browsers) {
|
||||
const browser = await playwright[browserType].launch({ headless: !debugging });
|
||||
const context = await browser.newContext();
|
||||
const page = await context.newPage();
|
||||
|
||||
/** @type {(err: Error) => void} */
|
||||
const errorCaught = err => {
|
||||
console.error(chalk.red("There was an error running built/typescript.js in " + browserType));
|
||||
console.log(err.toString());
|
||||
process.exitCode = 1;
|
||||
};
|
||||
|
||||
// @ts-ignore-error
|
||||
page.on("error", errorCaught);
|
||||
page.on("pageerror", errorCaught);
|
||||
|
||||
await page.setContent(`
|
||||
<html>
|
||||
<script>${readFileSync(join("built", "local", "typescript.js"), "utf8")}</script>
|
||||
</html>
|
||||
`);
|
||||
|
||||
if (!debugging) {
|
||||
await browser.close();
|
||||
}
|
||||
else {
|
||||
console.log("Not closing the browser, you'll need to exit the process in your terminal manually");
|
||||
}
|
||||
console.log(`${browserType} :+1:`);
|
||||
}
|
||||
Reference in New Issue
Block a user