Skip to content

Commit

Permalink
extension: expose URL shim (#5293)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickhulce authored and paulirish committed May 23, 2018
1 parent e04b29d commit 5598302
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lighthouse-core/lib/url-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class URLShim extends URL {
}
}

URLShim.URL = URL;
URLShim.URLSearchParams = (typeof self !== 'undefined' && self.URLSearchParams) ||
require('url').URLSearchParams;

Expand Down
6 changes: 6 additions & 0 deletions lighthouse-extension/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ gulp.task('browserify-lighthouse', () => {
bundle = bundle.require(artifact, {expose: artifact.replace(corePath, './')});
});

// browerify's url shim doesn't work with .URL in node_modules,
// and within robots-parser, it does `var URL = require('url').URL`, so we expose our own.
// @see https://github.com/GoogleChrome/lighthouse/issues/5273
const pathToURLShim = require.resolve('../lighthouse-core/lib/url-shim.js');
bundle = bundle.require(pathToURLShim, {expose: 'url'});

// Inject the new browserified contents back into our gulp pipeline
file.contents = bundle.bundle();
}))
Expand Down
5 changes: 5 additions & 0 deletions lighthouse-extension/test/extension-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,9 @@ describe('Lighthouse chrome extension', function() {
const errors = auditErrors.filter(item => item.debugString.includes('Audit error:'));
assert.deepStrictEqual(errors, [], 'Audit errors found within the report');
});

it('should pass the is-crawlable audit', async () => {
// this audit has regressed in the extension twice, so make sure it passes
assert.ok(await extensionPage.$('#is-crawlable.lh-audit--pass'), 'did not pass is-crawlable');
});
});

0 comments on commit 5598302

Please sign in to comment.