-
Notifications
You must be signed in to change notification settings - Fork 798
/
test-all.js
97 lines (85 loc) 路 2.95 KB
/
test-all.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
const {expect} = require('chai');
const {runUnitTests} = require('../../../infra/testing/webdriver/runUnitTests');
const activateAndControlSW = require('../../../infra/testing/activate-and-control');
const crossOriginServer = require('../../../infra/testing/server/cross-origin-server');
const upath = require('upath');
// Store local references of these globals.
const {webdriver, server} = global.__workbox;
describe(`[workbox-streams]`, function () {
it(`passes all SW unit tests`, async function () {
await runUnitTests('/test/workbox-streams/sw/');
});
});
describe(`[workbox-streams] Integration Tests`, function () {
const testServerAddress = server.getAddress();
const testingURL = `${testServerAddress}/test/workbox-streams/static/`;
const swURL = `${testingURL}sw.js`;
let crossOriginURL;
before(async function () {
await webdriver.get(testingURL);
await activateAndControlSW(swURL);
const crossOrigin = await crossOriginServer.start(
upath.join('..', 'static'),
);
crossOriginURL = `${crossOrigin}/4.txt`;
});
after(function () {
crossOriginServer.stop();
});
for (const testCase of ['concatenate', 'concatenateToResponse', 'strategy']) {
it(`should return the expected response for the '${testCase}' approach`, async function () {
const {text, headers} = await webdriver.executeAsyncScript(
async (testCase, cb) => {
try {
const response = await fetch(new URL(testCase, location));
const headers = [...response.headers].sort((a, b) => {
return a[0] > b[0];
});
const text = await response.text();
cb({headers, text});
} catch (error) {
cb({text: error.message});
}
},
testCase,
);
if (text === 'No streams support') {
this.skip();
} else {
expect(text).to.eql('01234\n');
expect(headers).to.eql([
['content-type', 'text/plain'],
['x-test-case', testCase],
]);
}
});
}
it(`should error when a stream source results in an opaque response`, async function () {
const {text} = await webdriver.executeAsyncScript(
async (crossOriginURL, cb) => {
try {
const url = new URL('/crossOriginURL', location);
url.searchParams.set('cross-origin-url', crossOriginURL);
const response = await fetch(url);
const text = await response.text();
cb({text});
} catch (error) {
cb({text: error.name});
}
},
crossOriginURL,
);
if (text === 'No streams support') {
this.skip();
} else {
// The exception name varies from browser to browser.
expect(text).to.be.oneOf(['TypeError', 'AbortError']);
}
});
});