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:
parent
415de9a291
commit
37a154e4e6
|
@ -21,15 +21,21 @@ import {take} from 'rxjs/operators';
|
||||||
|
|
||||||
import {async_beforeEach, async_fit, async_it} from './async';
|
import {async_beforeEach, async_fit, async_it} from './async';
|
||||||
|
|
||||||
const dist = new MockFileSystemBuilder().addFile('/only.txt', 'this is only').build();
|
(function() {
|
||||||
|
// Skip environments that don't support the minimum APIs needed to run the SW tests.
|
||||||
|
if (!SwTestHarness.envIsSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const distUpdate = new MockFileSystemBuilder().addFile('/only.txt', 'this is only v2').build();
|
const dist = new MockFileSystemBuilder().addFile('/only.txt', 'this is only').build();
|
||||||
|
|
||||||
function obsToSinglePromise<T>(obs: Observable<T>): Promise<T> {
|
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();
|
return obs.pipe(take(1)).toPromise();
|
||||||
}
|
}
|
||||||
|
|
||||||
const manifest: Manifest = {
|
const manifest: Manifest = {
|
||||||
configVersion: 1,
|
configVersion: 1,
|
||||||
timestamp: 1234567890123,
|
timestamp: 1234567890123,
|
||||||
appData: {version: '1'},
|
appData: {version: '1'},
|
||||||
|
@ -43,9 +49,9 @@ const manifest: Manifest = {
|
||||||
}],
|
}],
|
||||||
navigationUrls: [],
|
navigationUrls: [],
|
||||||
hashTable: tmpHashTableForFs(dist),
|
hashTable: tmpHashTableForFs(dist),
|
||||||
};
|
};
|
||||||
|
|
||||||
const manifestUpdate: Manifest = {
|
const manifestUpdate: Manifest = {
|
||||||
configVersion: 1,
|
configVersion: 1,
|
||||||
timestamp: 1234567890123,
|
timestamp: 1234567890123,
|
||||||
appData: {version: '2'},
|
appData: {version: '2'},
|
||||||
|
@ -59,18 +65,14 @@ const manifestUpdate: Manifest = {
|
||||||
}],
|
}],
|
||||||
navigationUrls: [],
|
navigationUrls: [],
|
||||||
hashTable: tmpHashTableForFs(distUpdate),
|
hashTable: tmpHashTableForFs(distUpdate),
|
||||||
};
|
};
|
||||||
|
|
||||||
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
|
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
|
||||||
|
|
||||||
const serverUpdate =
|
const serverUpdate =
|
||||||
new MockServerStateBuilder().withStaticFiles(distUpdate).withManifest(manifestUpdate).build();
|
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;
|
|
||||||
}
|
|
||||||
describe('ngsw + companion lib', () => {
|
describe('ngsw + companion lib', () => {
|
||||||
let mock: MockServiceWorkerContainer;
|
let mock: MockServiceWorkerContainer;
|
||||||
let comm: NgswCommChannel;
|
let comm: NgswCommChannel;
|
||||||
|
|
|
@ -15,7 +15,13 @@ import {SwTestHarness, SwTestHarnessBuilder} from '../testing/scope';
|
||||||
|
|
||||||
import {async_beforeEach, async_fit, async_it} from './async';
|
import {async_beforeEach, async_fit, async_it} from './async';
|
||||||
|
|
||||||
const dist = new MockFileSystemBuilder()
|
(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('/foo.txt', 'this is foo')
|
.addFile('/foo.txt', 'this is foo')
|
||||||
.addFile('/bar.txt', 'this is bar')
|
.addFile('/bar.txt', 'this is bar')
|
||||||
.addFile('/api/test', 'version 1')
|
.addFile('/api/test', 'version 1')
|
||||||
|
@ -29,7 +35,7 @@ const dist = new MockFileSystemBuilder()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
const distUpdate = new MockFileSystemBuilder()
|
const distUpdate = new MockFileSystemBuilder()
|
||||||
.addFile('/foo.txt', 'this is foo v2')
|
.addFile('/foo.txt', 'this is foo v2')
|
||||||
.addFile('/bar.txt', 'this is bar')
|
.addFile('/bar.txt', 'this is bar')
|
||||||
.addFile('/api/test', 'version 2')
|
.addFile('/api/test', 'version 2')
|
||||||
|
@ -37,7 +43,7 @@ const distUpdate = new MockFileSystemBuilder()
|
||||||
.addFile('/refresh/data', 'this is refreshed data')
|
.addFile('/refresh/data', 'this is refreshed data')
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const manifest: Manifest = {
|
const manifest: Manifest = {
|
||||||
configVersion: 1,
|
configVersion: 1,
|
||||||
timestamp: 1234567890123,
|
timestamp: 1234567890123,
|
||||||
index: '/index.html',
|
index: '/index.html',
|
||||||
|
@ -85,9 +91,9 @@ const manifest: Manifest = {
|
||||||
],
|
],
|
||||||
navigationUrls: [],
|
navigationUrls: [],
|
||||||
hashTable: tmpHashTableForFs(dist),
|
hashTable: tmpHashTableForFs(dist),
|
||||||
};
|
};
|
||||||
|
|
||||||
const seqIncreasedManifest: Manifest = {
|
const seqIncreasedManifest: Manifest = {
|
||||||
...manifest,
|
...manifest,
|
||||||
dataGroups: [
|
dataGroups: [
|
||||||
{
|
{
|
||||||
|
@ -97,30 +103,22 @@ const seqIncreasedManifest: Manifest = {
|
||||||
manifest.dataGroups ![1],
|
manifest.dataGroups ![1],
|
||||||
manifest.dataGroups ![2],
|
manifest.dataGroups ![2],
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
|
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
|
||||||
|
|
||||||
const serverUpdate =
|
const serverUpdate =
|
||||||
new MockServerStateBuilder().withStaticFiles(distUpdate).withManifest(manifest).build();
|
new MockServerStateBuilder().withStaticFiles(distUpdate).withManifest(manifest).build();
|
||||||
|
|
||||||
const serverSeqUpdate = new MockServerStateBuilder()
|
const serverSeqUpdate = new MockServerStateBuilder()
|
||||||
.withStaticFiles(distUpdate)
|
.withStaticFiles(distUpdate)
|
||||||
.withManifest(seqIncreasedManifest)
|
.withManifest(seqIncreasedManifest)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const scope = new SwTestHarnessBuilder().withServerState(server).build();
|
const scope = new SwTestHarnessBuilder().withServerState(server).build();
|
||||||
|
|
||||||
function asyncWrap(fn: () => Promise<void>): (done: DoneFn) => void {
|
|
||||||
return (done: DoneFn) => { fn().then(() => done(), err => done.fail(err)); };
|
|
||||||
}
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
// Skip environments that don't support the minimum APIs needed to run the SW tests.
|
|
||||||
if (!SwTestHarness.envIsSupported()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
describe('data cache', () => {
|
describe('data cache', () => {
|
||||||
let scope: SwTestHarness;
|
let scope: SwTestHarness;
|
||||||
let driver: Driver;
|
let driver: Driver;
|
||||||
|
|
|
@ -18,7 +18,13 @@ import {SwTestHarness, SwTestHarnessBuilder} from '../testing/scope';
|
||||||
|
|
||||||
import {async_beforeEach, async_fit, async_it} from './async';
|
import {async_beforeEach, async_fit, async_it} from './async';
|
||||||
|
|
||||||
const dist =
|
(function() {
|
||||||
|
// Skip environments that don't support the minimum APIs needed to run the SW tests.
|
||||||
|
if (!SwTestHarness.envIsSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const dist =
|
||||||
new MockFileSystemBuilder()
|
new MockFileSystemBuilder()
|
||||||
.addFile('/foo.txt', 'this is foo')
|
.addFile('/foo.txt', 'this is foo')
|
||||||
.addFile('/bar.txt', 'this is bar')
|
.addFile('/bar.txt', 'this is bar')
|
||||||
|
@ -32,7 +38,7 @@ const dist =
|
||||||
.addUnhashedFile('/unhashed/b.txt', 'this is unhashed b', {'Cache-Control': 'no-cache'})
|
.addUnhashedFile('/unhashed/b.txt', 'this is unhashed b', {'Cache-Control': 'no-cache'})
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const distUpdate =
|
const distUpdate =
|
||||||
new MockFileSystemBuilder()
|
new MockFileSystemBuilder()
|
||||||
.addFile('/foo.txt', 'this is foo v2')
|
.addFile('/foo.txt', 'this is foo v2')
|
||||||
.addFile('/bar.txt', 'this is bar')
|
.addFile('/bar.txt', 'this is bar')
|
||||||
|
@ -42,14 +48,15 @@ const distUpdate =
|
||||||
.addFile('/quuux.txt', 'this is quuux v2')
|
.addFile('/quuux.txt', 'this is quuux v2')
|
||||||
.addFile('/lazy/unchanged1.txt', 'this is unchanged (1)')
|
.addFile('/lazy/unchanged1.txt', 'this is unchanged (1)')
|
||||||
.addFile('/lazy/unchanged2.txt', 'this is unchanged (2)')
|
.addFile('/lazy/unchanged2.txt', 'this is unchanged (2)')
|
||||||
.addUnhashedFile('/unhashed/a.txt', 'this is unhashed v2', {'Cache-Control': 'max-age=10'})
|
.addUnhashedFile(
|
||||||
|
'/unhashed/a.txt', 'this is unhashed v2', {'Cache-Control': 'max-age=10'})
|
||||||
.addUnhashedFile('/ignored/file1', 'this is not handled by the SW')
|
.addUnhashedFile('/ignored/file1', 'this is not handled by the SW')
|
||||||
.addUnhashedFile('/ignored/dir/file2', 'this is not handled by the SW either')
|
.addUnhashedFile('/ignored/dir/file2', 'this is not handled by the SW either')
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const brokenFs = new MockFileSystemBuilder().addFile('/foo.txt', 'this is foo').build();
|
const brokenFs = new MockFileSystemBuilder().addFile('/foo.txt', 'this is foo').build();
|
||||||
|
|
||||||
const brokenManifest: Manifest = {
|
const brokenManifest: Manifest = {
|
||||||
configVersion: 1,
|
configVersion: 1,
|
||||||
timestamp: 1234567890123,
|
timestamp: 1234567890123,
|
||||||
index: '/foo.txt',
|
index: '/foo.txt',
|
||||||
|
@ -65,27 +72,27 @@ const brokenManifest: Manifest = {
|
||||||
dataGroups: [],
|
dataGroups: [],
|
||||||
navigationUrls: processNavigationUrls(''),
|
navigationUrls: processNavigationUrls(''),
|
||||||
hashTable: tmpHashTableForFs(brokenFs, {'/foo.txt': true}),
|
hashTable: tmpHashTableForFs(brokenFs, {'/foo.txt': true}),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Manifest without navigation urls to test backward compatibility with
|
// Manifest without navigation urls to test backward compatibility with
|
||||||
// versions < 6.0.0.
|
// versions < 6.0.0.
|
||||||
export interface ManifestV5 {
|
interface ManifestV5 {
|
||||||
configVersion: number;
|
configVersion: number;
|
||||||
appData?: {[key: string]: string};
|
appData?: {[key: string]: string};
|
||||||
index: string;
|
index: string;
|
||||||
assetGroups?: AssetGroupConfig[];
|
assetGroups?: AssetGroupConfig[];
|
||||||
dataGroups?: DataGroupConfig[];
|
dataGroups?: DataGroupConfig[];
|
||||||
hashTable: {[url: string]: string};
|
hashTable: {[url: string]: string};
|
||||||
}
|
}
|
||||||
|
|
||||||
// To simulate versions < 6.0.0
|
// To simulate versions < 6.0.0
|
||||||
const manifestOld: ManifestV5 = {
|
const manifestOld: ManifestV5 = {
|
||||||
configVersion: 1,
|
configVersion: 1,
|
||||||
index: '/foo.txt',
|
index: '/foo.txt',
|
||||||
hashTable: tmpHashTableForFs(dist),
|
hashTable: tmpHashTableForFs(dist),
|
||||||
};
|
};
|
||||||
|
|
||||||
const manifest: Manifest = {
|
const manifest: Manifest = {
|
||||||
configVersion: 1,
|
configVersion: 1,
|
||||||
timestamp: 1234567890123,
|
timestamp: 1234567890123,
|
||||||
appData: {
|
appData: {
|
||||||
|
@ -131,9 +138,9 @@ const manifest: Manifest = {
|
||||||
],
|
],
|
||||||
navigationUrls: processNavigationUrls(''),
|
navigationUrls: processNavigationUrls(''),
|
||||||
hashTable: tmpHashTableForFs(dist),
|
hashTable: tmpHashTableForFs(dist),
|
||||||
};
|
};
|
||||||
|
|
||||||
const manifestUpdate: Manifest = {
|
const manifestUpdate: Manifest = {
|
||||||
configVersion: 1,
|
configVersion: 1,
|
||||||
timestamp: 1234567890123,
|
timestamp: 1234567890123,
|
||||||
appData: {
|
appData: {
|
||||||
|
@ -186,39 +193,35 @@ const manifestUpdate: Manifest = {
|
||||||
'!/ignored/dir/**',
|
'!/ignored/dir/**',
|
||||||
]),
|
]),
|
||||||
hashTable: tmpHashTableForFs(distUpdate),
|
hashTable: tmpHashTableForFs(distUpdate),
|
||||||
};
|
};
|
||||||
|
|
||||||
const serverBuilderBase =
|
const serverBuilderBase =
|
||||||
new MockServerStateBuilder()
|
new MockServerStateBuilder()
|
||||||
.withStaticFiles(dist)
|
.withStaticFiles(dist)
|
||||||
.withRedirect('/redirected.txt', '/redirect-target.txt', 'this was a redirect')
|
.withRedirect('/redirected.txt', '/redirect-target.txt', 'this was a redirect')
|
||||||
.withError('/error.txt');
|
.withError('/error.txt');
|
||||||
|
|
||||||
const server = serverBuilderBase.withManifest(manifest).build();
|
const server = serverBuilderBase.withManifest(manifest).build();
|
||||||
|
|
||||||
const serverRollback =
|
const serverRollback =
|
||||||
serverBuilderBase.withManifest({...manifest, timestamp: manifest.timestamp + 1}).build();
|
serverBuilderBase.withManifest({...manifest, timestamp: manifest.timestamp + 1}).build();
|
||||||
|
|
||||||
const serverUpdate =
|
const serverUpdate =
|
||||||
new MockServerStateBuilder()
|
new MockServerStateBuilder()
|
||||||
.withStaticFiles(distUpdate)
|
.withStaticFiles(distUpdate)
|
||||||
.withManifest(manifestUpdate)
|
.withManifest(manifestUpdate)
|
||||||
.withRedirect('/redirected.txt', '/redirect-target.txt', 'this was a redirect')
|
.withRedirect('/redirected.txt', '/redirect-target.txt', 'this was a redirect')
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const brokenServer =
|
const brokenServer =
|
||||||
new MockServerStateBuilder().withStaticFiles(brokenFs).withManifest(brokenManifest).build();
|
new MockServerStateBuilder().withStaticFiles(brokenFs).withManifest(brokenManifest).build();
|
||||||
|
|
||||||
const server404 = new MockServerStateBuilder().withStaticFiles(dist).build();
|
const server404 = new MockServerStateBuilder().withStaticFiles(dist).build();
|
||||||
|
|
||||||
|
const manifestHash = sha1(JSON.stringify(manifest));
|
||||||
|
const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
|
||||||
|
|
||||||
const manifestHash = sha1(JSON.stringify(manifest));
|
|
||||||
const manifestUpdateHash = sha1(JSON.stringify(manifestUpdate));
|
|
||||||
|
|
||||||
(function() {
|
|
||||||
// Skip environments that don't support the minimum APIs needed to run the SW tests.
|
|
||||||
if (!SwTestHarness.envIsSupported()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
describe('Driver', () => {
|
describe('Driver', () => {
|
||||||
let scope: SwTestHarness;
|
let scope: SwTestHarness;
|
||||||
let driver: Driver;
|
let driver: Driver;
|
||||||
|
|
|
@ -15,6 +15,7 @@ import {async_beforeEach, async_fit, async_it} from './async';
|
||||||
if (!SwTestHarness.envIsSupported()) {
|
if (!SwTestHarness.envIsSupported()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('IdleScheduler', () => {
|
describe('IdleScheduler', () => {
|
||||||
let scope: SwTestHarness;
|
let scope: SwTestHarness;
|
||||||
let idle: IdleScheduler;
|
let idle: IdleScheduler;
|
||||||
|
|
|
@ -14,26 +14,26 @@ import {SwTestHarness, SwTestHarnessBuilder} from '../testing/scope';
|
||||||
|
|
||||||
import {async_fit, async_it} from './async';
|
import {async_fit, async_it} from './async';
|
||||||
|
|
||||||
const dist = new MockFileSystemBuilder()
|
|
||||||
.addFile('/foo.txt', 'this is foo')
|
|
||||||
.addFile('/bar.txt', 'this is bar')
|
|
||||||
.build();
|
|
||||||
|
|
||||||
const manifest = tmpManifestSingleAssetGroup(dist);
|
|
||||||
|
|
||||||
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
|
|
||||||
|
|
||||||
const scope = new SwTestHarnessBuilder().withServerState(server).build();
|
|
||||||
|
|
||||||
const db = new CacheDatabase(scope, scope);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
// Skip environments that don't support the minimum APIs needed to run the SW tests.
|
// Skip environments that don't support the minimum APIs needed to run the SW tests.
|
||||||
if (!SwTestHarness.envIsSupported()) {
|
if (!SwTestHarness.envIsSupported()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dist = new MockFileSystemBuilder()
|
||||||
|
.addFile('/foo.txt', 'this is foo')
|
||||||
|
.addFile('/bar.txt', 'this is bar')
|
||||||
|
.build();
|
||||||
|
|
||||||
|
const manifest = tmpManifestSingleAssetGroup(dist);
|
||||||
|
|
||||||
|
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
|
||||||
|
|
||||||
|
const scope = new SwTestHarnessBuilder().withServerState(server).build();
|
||||||
|
|
||||||
|
const db = new CacheDatabase(scope, scope);
|
||||||
|
|
||||||
|
|
||||||
describe('prefetch assets', () => {
|
describe('prefetch assets', () => {
|
||||||
let group: PrefetchAssetGroup;
|
let group: PrefetchAssetGroup;
|
||||||
let idle: IdleScheduler;
|
let idle: IdleScheduler;
|
||||||
|
|
Loading…
Reference in New Issue