test(service-worker): do not create testing artifacts on environments that do not support SW (#27080)

The tests will not be run anyway, so the artifacts are never used and
there might be errors if creating the testing artifacts relies on APIs
that are not available in that environment (e.g. `URL`).

PR Close #27080
This commit is contained in:
George Kalpakas
2019-03-20 23:29:14 +02:00
committed by Matias Niemelä
parent 415de9a291
commit 37a154e4e6
5 changed files with 362 additions and 358 deletions

View File

@ -21,56 +21,58 @@ import {take} from 'rxjs/operators';
import {async_beforeEach, async_fit, async_it} from './async';
const dist = new MockFileSystemBuilder().addFile('/only.txt', 'this is only').build();
const distUpdate = new MockFileSystemBuilder().addFile('/only.txt', 'this is only v2').build();
function obsToSinglePromise<T>(obs: Observable<T>): Promise<T> {
return obs.pipe(take(1)).toPromise();
}
const manifest: Manifest = {
configVersion: 1,
timestamp: 1234567890123,
appData: {version: '1'},
index: '/only.txt',
assetGroups: [{
name: 'assets',
installMode: 'prefetch',
updateMode: 'prefetch',
urls: ['/only.txt'],
patterns: [],
}],
navigationUrls: [],
hashTable: tmpHashTableForFs(dist),
};
const manifestUpdate: Manifest = {
configVersion: 1,
timestamp: 1234567890123,
appData: {version: '2'},
index: '/only.txt',
assetGroups: [{
name: 'assets',
installMode: 'prefetch',
updateMode: 'prefetch',
urls: ['/only.txt'],
patterns: [],
}],
navigationUrls: [],
hashTable: tmpHashTableForFs(distUpdate),
};
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
const serverUpdate =
new MockServerStateBuilder().withStaticFiles(distUpdate).withManifest(manifestUpdate).build();
(function() {
// Skip environments that don't support the minimum APIs needed to run the SW tests.
if (!SwTestHarness.envIsSupported()) {
return;
}
const dist = new MockFileSystemBuilder().addFile('/only.txt', 'this is only').build();
const distUpdate = new MockFileSystemBuilder().addFile('/only.txt', 'this is only v2').build();
function obsToSinglePromise<T>(obs: Observable<T>): Promise<T> {
return obs.pipe(take(1)).toPromise();
}
const manifest: Manifest = {
configVersion: 1,
timestamp: 1234567890123,
appData: {version: '1'},
index: '/only.txt',
assetGroups: [{
name: 'assets',
installMode: 'prefetch',
updateMode: 'prefetch',
urls: ['/only.txt'],
patterns: [],
}],
navigationUrls: [],
hashTable: tmpHashTableForFs(dist),
};
const manifestUpdate: Manifest = {
configVersion: 1,
timestamp: 1234567890123,
appData: {version: '2'},
index: '/only.txt',
assetGroups: [{
name: 'assets',
installMode: 'prefetch',
updateMode: 'prefetch',
urls: ['/only.txt'],
patterns: [],
}],
navigationUrls: [],
hashTable: tmpHashTableForFs(distUpdate),
};
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
const serverUpdate =
new MockServerStateBuilder().withStaticFiles(distUpdate).withManifest(manifestUpdate).build();
describe('ngsw + companion lib', () => {
let mock: MockServiceWorkerContainer;
let comm: NgswCommChannel;