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 75afd80ae8
commit e9de28111d
4 changed files with 6 additions and 37 deletions

View File

@ -33,14 +33,6 @@ jasmine_node_test(
karma_web_test_suite(
name = "test_web",
tags = [
# FIXME: fix on saucelabs
# ERROR: 'There is no timestamp for @angular/service-worker/worker/src/db-cache.js!'
# ERROR: 'There is no timestamp for @angular/service-worker/worker/src/driver.js!'
# ERROR: 'There is no timestamp for @angular/service-worker/worker/src/sha1.js!'
"fixme-saucelabs-ivy",
"fixme-saucelabs-ve",
],
deps = [
":test_lib",
],

View File

@ -13,14 +13,12 @@ ts_library(
"main.ts",
],
),
tsconfig = ":tsconfig.json",
deps = ["@npm//@types/node"],
)
ts_library(
name = "main",
srcs = ["main.ts"],
tsconfig = ":tsconfig.json",
deps = [":worker"],
)

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');

View File

@ -1,27 +0,0 @@
{
"compilerOptions": {
"baseUrl": ".",
"declaration": false,
"strict": true,
"module": "es2015",
"moduleResolution": "node",
"strictNullChecks": true,
"strictPropertyInitialization": true,
"outDir": "../../../dist/all/@angular/service-worker/worker-es2017",
"noImplicitAny": true,
"noFallthroughCasesInSwitch": true,
"rootDir": ".",
"inlineSourceMap": true,
"lib": ["es2015", "dom"],
"target": "es2017",
"typeRoots": [],
"types": []
},
"bazelOptions": {
"suppressTsconfigOverrideWarnings": true
},
"files": [
"main.ts",
"src/service-worker.d.ts"
]
}