Skip to content

Commit 37a154e

Browse files
gkalpakmatsko
authored andcommitted
test(service-worker): do not create testing artifacts on environments that do not support SW (angular#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 angular#27080
1 parent 415de9a commit 37a154e

File tree

5 files changed

+348
-344
lines changed

5 files changed

+348
-344
lines changed

packages/service-worker/test/integration_spec.ts

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,56 +21,58 @@ import {take} from 'rxjs/operators';
2121

2222
import {async_beforeEach, async_fit, async_it} from './async';
2323

24-
const dist = new MockFileSystemBuilder().addFile('/only.txt', 'this is only').build();
25-
26-
const distUpdate = new MockFileSystemBuilder().addFile('/only.txt', 'this is only v2').build();
27-
28-
function obsToSinglePromise<T>(obs: Observable<T>): Promise<T> {
29-
return obs.pipe(take(1)).toPromise();
30-
}
31-
32-
const manifest: Manifest = {
33-
configVersion: 1,
34-
timestamp: 1234567890123,
35-
appData: {version: '1'},
36-
index: '/only.txt',
37-
assetGroups: [{
38-
name: 'assets',
39-
installMode: 'prefetch',
40-
updateMode: 'prefetch',
41-
urls: ['/only.txt'],
42-
patterns: [],
43-
}],
44-
navigationUrls: [],
45-
hashTable: tmpHashTableForFs(dist),
46-
};
47-
48-
const manifestUpdate: Manifest = {
49-
configVersion: 1,
50-
timestamp: 1234567890123,
51-
appData: {version: '2'},
52-
index: '/only.txt',
53-
assetGroups: [{
54-
name: 'assets',
55-
installMode: 'prefetch',
56-
updateMode: 'prefetch',
57-
urls: ['/only.txt'],
58-
patterns: [],
59-
}],
60-
navigationUrls: [],
61-
hashTable: tmpHashTableForFs(distUpdate),
62-
};
63-
64-
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
65-
66-
const serverUpdate =
67-
new MockServerStateBuilder().withStaticFiles(distUpdate).withManifest(manifestUpdate).build();
68-
6924
(function() {
7025
// Skip environments that don't support the minimum APIs needed to run the SW tests.
7126
if (!SwTestHarness.envIsSupported()) {
7227
return;
7328
}
29+
30+
const dist = new MockFileSystemBuilder().addFile('/only.txt', 'this is only').build();
31+
32+
const distUpdate = new MockFileSystemBuilder().addFile('/only.txt', 'this is only v2').build();
33+
34+
function obsToSinglePromise<T>(obs: Observable<T>): Promise<T> {
35+
return obs.pipe(take(1)).toPromise();
36+
}
37+
38+
const manifest: Manifest = {
39+
configVersion: 1,
40+
timestamp: 1234567890123,
41+
appData: {version: '1'},
42+
index: '/only.txt',
43+
assetGroups: [{
44+
name: 'assets',
45+
installMode: 'prefetch',
46+
updateMode: 'prefetch',
47+
urls: ['/only.txt'],
48+
patterns: [],
49+
}],
50+
navigationUrls: [],
51+
hashTable: tmpHashTableForFs(dist),
52+
};
53+
54+
const manifestUpdate: Manifest = {
55+
configVersion: 1,
56+
timestamp: 1234567890123,
57+
appData: {version: '2'},
58+
index: '/only.txt',
59+
assetGroups: [{
60+
name: 'assets',
61+
installMode: 'prefetch',
62+
updateMode: 'prefetch',
63+
urls: ['/only.txt'],
64+
patterns: [],
65+
}],
66+
navigationUrls: [],
67+
hashTable: tmpHashTableForFs(distUpdate),
68+
};
69+
70+
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
71+
72+
const serverUpdate =
73+
new MockServerStateBuilder().withStaticFiles(distUpdate).withManifest(manifestUpdate).build();
74+
75+
7476
describe('ngsw + companion lib', () => {
7577
let mock: MockServiceWorkerContainer;
7678
let comm: NgswCommChannel;

packages/service-worker/worker/test/data_spec.ts

Lines changed: 93 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -15,112 +15,110 @@ import {SwTestHarness, SwTestHarnessBuilder} from '../testing/scope';
1515

1616
import {async_beforeEach, async_fit, async_it} from './async';
1717

18-
const dist = new MockFileSystemBuilder()
19-
.addFile('/foo.txt', 'this is foo')
20-
.addFile('/bar.txt', 'this is bar')
21-
.addFile('/api/test', 'version 1')
22-
.addFile('/api/a', 'version A')
23-
.addFile('/api/b', 'version B')
24-
.addFile('/api/c', 'version C')
25-
.addFile('/api/d', 'version D')
26-
.addFile('/api/e', 'version E')
27-
.addFile('/fresh/data', 'this is fresh data')
28-
.addFile('/refresh/data', 'this is some data')
29-
.build();
18+
(function() {
19+
// Skip environments that don't support the minimum APIs needed to run the SW tests.
20+
if (!SwTestHarness.envIsSupported()) {
21+
return;
22+
}
3023

24+
const dist = new MockFileSystemBuilder()
25+
.addFile('/foo.txt', 'this is foo')
26+
.addFile('/bar.txt', 'this is bar')
27+
.addFile('/api/test', 'version 1')
28+
.addFile('/api/a', 'version A')
29+
.addFile('/api/b', 'version B')
30+
.addFile('/api/c', 'version C')
31+
.addFile('/api/d', 'version D')
32+
.addFile('/api/e', 'version E')
33+
.addFile('/fresh/data', 'this is fresh data')
34+
.addFile('/refresh/data', 'this is some data')
35+
.build();
3136

32-
const distUpdate = new MockFileSystemBuilder()
33-
.addFile('/foo.txt', 'this is foo v2')
34-
.addFile('/bar.txt', 'this is bar')
35-
.addFile('/api/test', 'version 2')
36-
.addFile('/fresh/data', 'this is fresher data')
37-
.addFile('/refresh/data', 'this is refreshed data')
38-
.build();
3937

40-
const manifest: Manifest = {
41-
configVersion: 1,
42-
timestamp: 1234567890123,
43-
index: '/index.html',
44-
assetGroups: [
45-
{
46-
name: 'assets',
47-
installMode: 'prefetch',
48-
updateMode: 'prefetch',
49-
urls: [
50-
'/foo.txt',
51-
'/bar.txt',
52-
],
53-
patterns: [],
54-
},
55-
],
56-
dataGroups: [
57-
{
58-
name: 'testPerf',
59-
maxSize: 3,
60-
strategy: 'performance',
61-
patterns: ['^/api/.*$'],
62-
timeoutMs: 1000,
63-
maxAge: 5000,
64-
version: 1,
65-
},
66-
{
67-
name: 'testRefresh',
68-
maxSize: 3,
69-
strategy: 'performance',
70-
patterns: ['^/refresh/.*$'],
71-
timeoutMs: 1000,
72-
refreshAheadMs: 1000,
73-
maxAge: 5000,
74-
version: 1,
75-
},
76-
{
77-
name: 'testFresh',
78-
maxSize: 3,
79-
strategy: 'freshness',
80-
patterns: ['^/fresh/.*$'],
81-
timeoutMs: 1000,
82-
maxAge: 5000,
83-
version: 1,
84-
},
85-
],
86-
navigationUrls: [],
87-
hashTable: tmpHashTableForFs(dist),
88-
};
38+
const distUpdate = new MockFileSystemBuilder()
39+
.addFile('/foo.txt', 'this is foo v2')
40+
.addFile('/bar.txt', 'this is bar')
41+
.addFile('/api/test', 'version 2')
42+
.addFile('/fresh/data', 'this is fresher data')
43+
.addFile('/refresh/data', 'this is refreshed data')
44+
.build();
8945

90-
const seqIncreasedManifest: Manifest = {
91-
...manifest,
92-
dataGroups: [
93-
{
94-
...manifest.dataGroups ![0],
95-
version: 2,
96-
},
97-
manifest.dataGroups ![1],
98-
manifest.dataGroups ![2],
99-
],
100-
};
46+
const manifest: Manifest = {
47+
configVersion: 1,
48+
timestamp: 1234567890123,
49+
index: '/index.html',
50+
assetGroups: [
51+
{
52+
name: 'assets',
53+
installMode: 'prefetch',
54+
updateMode: 'prefetch',
55+
urls: [
56+
'/foo.txt',
57+
'/bar.txt',
58+
],
59+
patterns: [],
60+
},
61+
],
62+
dataGroups: [
63+
{
64+
name: 'testPerf',
65+
maxSize: 3,
66+
strategy: 'performance',
67+
patterns: ['^/api/.*$'],
68+
timeoutMs: 1000,
69+
maxAge: 5000,
70+
version: 1,
71+
},
72+
{
73+
name: 'testRefresh',
74+
maxSize: 3,
75+
strategy: 'performance',
76+
patterns: ['^/refresh/.*$'],
77+
timeoutMs: 1000,
78+
refreshAheadMs: 1000,
79+
maxAge: 5000,
80+
version: 1,
81+
},
82+
{
83+
name: 'testFresh',
84+
maxSize: 3,
85+
strategy: 'freshness',
86+
patterns: ['^/fresh/.*$'],
87+
timeoutMs: 1000,
88+
maxAge: 5000,
89+
version: 1,
90+
},
91+
],
92+
navigationUrls: [],
93+
hashTable: tmpHashTableForFs(dist),
94+
};
10195

96+
const seqIncreasedManifest: Manifest = {
97+
...manifest,
98+
dataGroups: [
99+
{
100+
...manifest.dataGroups ![0],
101+
version: 2,
102+
},
103+
manifest.dataGroups ![1],
104+
manifest.dataGroups ![2],
105+
],
106+
};
102107

103-
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
104108

105-
const serverUpdate =
106-
new MockServerStateBuilder().withStaticFiles(distUpdate).withManifest(manifest).build();
109+
const server = new MockServerStateBuilder().withStaticFiles(dist).withManifest(manifest).build();
107110

108-
const serverSeqUpdate = new MockServerStateBuilder()
109-
.withStaticFiles(distUpdate)
110-
.withManifest(seqIncreasedManifest)
111-
.build();
111+
const serverUpdate =
112+
new MockServerStateBuilder().withStaticFiles(distUpdate).withManifest(manifest).build();
112113

113-
const scope = new SwTestHarnessBuilder().withServerState(server).build();
114+
const serverSeqUpdate = new MockServerStateBuilder()
115+
.withStaticFiles(distUpdate)
116+
.withManifest(seqIncreasedManifest)
117+
.build();
118+
119+
const scope = new SwTestHarnessBuilder().withServerState(server).build();
114120

115-
function asyncWrap(fn: () => Promise<void>): (done: DoneFn) => void {
116-
return (done: DoneFn) => { fn().then(() => done(), err => done.fail(err)); };
117-
}
118121

119-
(function() {
120-
// Skip environments that don't support the minimum APIs needed to run the SW tests.
121-
if (!SwTestHarness.envIsSupported()) {
122-
return;
123-
}
124122
describe('data cache', () => {
125123
let scope: SwTestHarness;
126124
let driver: Driver;

0 commit comments

Comments
 (0)