Skip to content

Adds playwright to test whether typescript.js runs in the browser #35471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,6 @@ jobs:
npm install
npm update
npm test
- name: Validate the browser can import TypeScript
run: gulp test-browser-integration

5 changes: 5 additions & 0 deletions Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,11 @@ task("runtests-parallel").flags = {
" --shardId": "1-based ID of this shard (default: 1)",
};


task("test-browser-integration", () => exec(process.execPath, ["scripts/browserIntegrationTest.js"]));
task("test-browser-integration").description = "Runs scripts/browserIntegrationTest.ts which tests that typescript.js loads in a browser";


task("diff", () => exec(getDiffTool(), [refBaseline, localBaseline], { ignoreExitCode: true, waitForExit: false }));
task("diff").description = "Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable";

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
"through2": "latest",
"travis-fold": "latest",
"typescript": "next",
"playwright": "latest",
"vinyl": "latest",
"vinyl-sourcemaps-apply": "latest",
"xml2js": "^0.4.19"
Expand Down
39 changes: 39 additions & 0 deletions scripts/browserIntegrationTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const playwright = require("playwright");
const chalk = require("chalk");
const { join } = require("path");
const { readFileSync } = require("fs");

// Turning this on will leave the Chromium browser open, giving you the
// chance to open up the web inspector.
const debugging = false;

(async () => {
for (const browserType of ["chromium", "firefox", "webkit"]) {
const browser = await playwright[browserType].launch({ headless: !debugging });
const context = await browser.newContext();
const page = await context.newPage();

const errorCaught = err => {
console.error(chalk.red("There was an error running built/typescript.js in " + browserType));
console.log(err.toString());
process.exitCode = 1;
};

page.on("error", errorCaught);
page.on("pageerror", errorCaught);
page.on("console", log => console[log._type](log._text));

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");
}
}
})();