Skip to content

Commit 19c3bcb

Browse files
author
Orta
authored
Adds puppeteer to test whether typescript.js runs in the browser (microsoft#35471)
* Adds puppeteer to test whether typescript.js runs in the browser * Adds a check for the browser integration into the GitHub Actions CI * Update to use playwright, and test in three browsers
1 parent 0a7d54d commit 19c3bcb

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ jobs:
3535
npm install
3636
npm update
3737
npm test
38+
- name: Validate the browser can import TypeScript
39+
run: gulp test-browser-integration
40+

Gulpfile.js

+5
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ task("runtests-parallel").flags = {
472472
" --shardId": "1-based ID of this shard (default: 1)",
473473
};
474474

475+
476+
task("test-browser-integration", () => exec(process.execPath, ["scripts/browserIntegrationTest.js"]));
477+
task("test-browser-integration").description = "Runs scripts/browserIntegrationTest.ts which tests that typescript.js loads in a browser";
478+
479+
475480
task("diff", () => exec(getDiffTool(), [refBaseline, localBaseline], { ignoreExitCode: true, waitForExit: false }));
476481
task("diff").description = "Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable";
477482

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"through2": "latest",
9797
"travis-fold": "latest",
9898
"typescript": "next",
99+
"playwright": "latest",
99100
"vinyl": "latest",
100101
"vinyl-sourcemaps-apply": "latest",
101102
"xml2js": "^0.4.19"

scripts/browserIntegrationTest.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
const playwright = require("playwright");
2+
const chalk = require("chalk");
3+
const { join } = require("path");
4+
const { readFileSync } = require("fs");
5+
6+
// Turning this on will leave the Chromium browser open, giving you the
7+
// chance to open up the web inspector.
8+
const debugging = false;
9+
10+
(async () => {
11+
for (const browserType of ["chromium", "firefox", "webkit"]) {
12+
const browser = await playwright[browserType].launch({ headless: !debugging });
13+
const context = await browser.newContext();
14+
const page = await context.newPage();
15+
16+
const errorCaught = err => {
17+
console.error(chalk.red("There was an error running built/typescript.js in " + browserType));
18+
console.log(err.toString());
19+
process.exitCode = 1;
20+
};
21+
22+
page.on("error", errorCaught);
23+
page.on("pageerror", errorCaught);
24+
page.on("console", log => console[log._type](log._text));
25+
26+
await page.setContent(`
27+
<html>
28+
<script>${readFileSync(join("built", "local", "typescript.js"), "utf8")}</script>
29+
</html>
30+
`);
31+
32+
if (!debugging) {
33+
await browser.close();
34+
}
35+
else {
36+
console.log("Not closing the browser, you'll need to exit the process in your terminal manually");
37+
}
38+
}
39+
})();

0 commit comments

Comments
 (0)