build: enable service-worker tests on saucelabs (#36129)

Enables the `service-worker` tests on Saucelabs and fixes some issues that were preventing them from running on IE. The issues were:
1. We were serving es2017 code during tests. I've set it to es5.
2. The check which was verifying whether the environment is supported ended up hitting a `require` call in the browser which caused it to fail on browsers that don't support the `URL` API.

PR Close #36129
This commit is contained in:
crisbeto
2020-03-19 17:52:11 +01:00
committed by Kara Erickson
parent 21da0346c7
commit c3ce1903b6
4 changed files with 6 additions and 37 deletions

View File

@ -100,6 +100,12 @@ export class SwTestHarness implements ServiceWorkerGlobalScope, Adapter, Context
return true;
}
// If we're in a browser that doesn't support URL at this point, don't go any further
// since browser builds use requirejs which will fail on the `require` call below.
if (typeof window !== 'undefined' && window) {
return false;
}
// In older Node.js versions, the `URL` global does not exist. We can use `url` instead.
const url = (typeof require === 'function') && require('url');
return url && (typeof url.parse === 'function') && (typeof url.resolve === 'function');