Skip to content

Commit

Permalink
tests: simplify serving of zone.js (#9672)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Nov 6, 2019
1 parent 53774ef commit 0308e6f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 23 deletions.
12 changes: 7 additions & 5 deletions lighthouse-cli/test/fixtures/dobetterweb/dbw_tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -418,12 +418,14 @@ <h2>Do better web tester page</h2>
}
</script>

<!-- PASS: not in header, so it does not block rendering. zone.js is loaded
by the static-server and provides a polyfill for Promise. -->
<script src="/zone.js"></script>
<!-- Including this script validates that driver.evaluateAsync() still works even with
window.Promise being mucked with. See file source for details.
Also, script is located down here to avoid being flagged in render-blocking-resources. -->
<script src="./third_party/aggressive-promise-polyfill.js"></script>

<!-- FAIL(is-on-https): requires a non-localhost http file
FAIL: Loads a vulnerable JS library
-->
FAIL(no-vulnerable-libraries): Loads a vulnerable JS library -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

</body>
</html>

Large diffs are not rendered by default.

16 changes: 5 additions & 11 deletions lighthouse-cli/test/fixtures/static-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,13 @@ function requestHandler(request, response) {
absoluteFilePath = path.join(__dirname, '/../../../', filePath);
}

if (filePath === '/zone.js') {
// evaluateAsync previously had a bug that LH would fail if a page polyfilled Promise.
// We bring in an aggressive Promise polyfill (zone) to ensure we don't still fail.
const zonePath = '../../../node_modules/zone.js';
absoluteFilePath = path.join(__dirname, `${zonePath}/dist/zone.js`);
} else {
// Otherwise, disallow file requests outside of LH folder
const filePathDir = path.parse(absoluteFilePath).dir;
if (!filePathDir.startsWith(lhRootDirPath)) {
return readFileCallback(new Error('Disallowed path'));
}
// Disallow file requests outside of LH folder
const filePathDir = path.parse(absoluteFilePath).dir;
if (!filePathDir.startsWith(lhRootDirPath)) {
return readFileCallback(new Error('Disallowed path'));
}

// Check if the file exists, then read it and serve it.
fs.exists(absoluteFilePath, fsExistsCallback);

function fsExistsCallback(fileExists) {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@
"pretty-json-stringify": "^0.0.2",
"puppeteer": "^1.19.0",
"terser": "^4.2.0",
"typescript": "3.5.3",
"zone.js": "^0.7.3"
"typescript": "3.5.3"
},
"dependencies": {
"axe-core": "3.3.0",
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7964,8 +7964,3 @@ zip-stream@^2.0.1:
archiver-utils "^2.0.0"
compress-commons "^1.2.0"
readable-stream "^2.0.0"

zone.js@^0.7.3:
version "0.7.3"
resolved "https://registry.yarnpkg.com/zone.js/-/zone.js-0.7.3.tgz#d91432b6584f73c2c9e03ce4bb0870becc45d445"
integrity sha1-2RQytlhPc8LJ4DzkuwhwvsxF1EU=

0 comments on commit 0308e6f

Please sign in to comment.