test: another attempt to fix sw test #2201

This commit is contained in:
Andrey Lushnikov 2018-03-15 16:58:02 -07:00 committed by GitHub
parent 150e5a9bbf
commit c4b1ac99b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 1 deletions

View File

@ -1,4 +1,5 @@
<link rel="stylesheet" href="./style.css"> <link rel="stylesheet" href="./style.css">
<script> <script>
window.registrationPromise = navigator.serviceWorker.register('sw.js'); window.registrationPromise = navigator.serviceWorker.register('sw.js');
window.activationPromise = new Promise(resolve => navigator.serviceWorker.oncontrollerchange = resolve);
</script> </script>

View File

@ -1,3 +1,7 @@
self.addEventListener('fetch', event => { self.addEventListener('fetch', event => {
event.respondWith(fetch(event.request)); event.respondWith(fetch(event.request));
}); });
self.addEventListener('activate', event => {
event.waitUntil(clients.claim());
});

View File

@ -2855,7 +2855,7 @@ describe('Page', function() {
// Load and re-load to make sure serviceworker is installed and running. // Load and re-load to make sure serviceworker is installed and running.
await page.goto(server.PREFIX + '/serviceworkers/fetch/sw.html', {waitUntil: 'networkidle2'}); await page.goto(server.PREFIX + '/serviceworkers/fetch/sw.html', {waitUntil: 'networkidle2'});
await page.evaluate(async() => await window.registrationPromise); await page.evaluate(async() => await window.activationPromise);
await page.reload(); await page.reload();
expect(responses.size).toBe(2); expect(responses.size).toBe(2);
@ -3766,6 +3766,7 @@ describe('Page', function() {
it('should report when a service worker is created and destroyed', async({page, server, browser}) => { it('should report when a service worker is created and destroyed', async({page, server, browser}) => {
await page.goto(server.EMPTY_PAGE); await page.goto(server.EMPTY_PAGE);
const createdTarget = new Promise(fulfill => browser.once('targetcreated', target => fulfill(target))); const createdTarget = new Promise(fulfill => browser.once('targetcreated', target => fulfill(target)));
await page.goto(server.PREFIX + '/serviceworkers/empty/sw.html'); await page.goto(server.PREFIX + '/serviceworkers/empty/sw.html');
expect((await createdTarget).type()).toBe('service_worker'); expect((await createdTarget).type()).toBe('service_worker');