-
Notifications
You must be signed in to change notification settings - Fork 798
/
test-all.js
50 lines (40 loc) 路 1.55 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
/*
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').expect;
const {runUnitTests} = require('../../../infra/testing/webdriver/runUnitTests');
// Store local references of these globals.
const {webdriver, server} = global.__workbox;
describe(`[workbox-sw]`, function() {
it(`passes all SW unit tests`, async function() {
await runUnitTests('/test/workbox-sw/sw/');
});
});
describe(`WorkboxSW interface`, function() {
const wasRegistrationSuccessful = (swFile) => {
return webdriver.executeAsyncScript((swFile, cb) => {
// Invokes cb() with true when registration succeeds, and false otherwise.
navigator.serviceWorker.register(swFile)
.then(() => cb(true))
.catch(() => cb(false));
}, swFile);
};
const testServerAddress = server.getAddress();
const testPageURL = `${testServerAddress}/test/workbox-sw/static/integration/`;
before(async function() {
await webdriver.get(testPageURL);
});
it(`should fail to activate an invalid SW which loads non-existent modules`, async function() {
const invalidSW = 'invalid-sw.js';
const outcome = await wasRegistrationSuccessful(invalidSW);
expect(outcome).to.be.false;
});
it(`should be able to activate a SW which loads all valid modules`, async function() {
const validSW = 'valid-sw.js';
const outcome = await wasRegistrationSuccessful(validSW);
expect(outcome).to.be.true;
});
});