Skip to content

Commit

Permalink
test: another attempt to fix sw test #2201
Browse files Browse the repository at this point in the history
  • Loading branch information
aslushnikov authored Mar 15, 2018
1 parent 150e5a9 commit c4b1ac9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/assets/serviceworkers/fetch/sw.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<link rel="stylesheet" href="./style.css">
<script>
window.registrationPromise = navigator.serviceWorker.register('sw.js');
window.activationPromise = new Promise(resolve => navigator.serviceWorker.oncontrollerchange = resolve);
</script>
4 changes: 4 additions & 0 deletions test/assets/serviceworkers/fetch/sw.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
self.addEventListener('fetch', event => {
event.respondWith(fetch(event.request));
});

self.addEventListener('activate', event => {
event.waitUntil(clients.claim());
});
3 changes: 2 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2855,7 +2855,7 @@ describe('Page', function() {

// 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.evaluate(async() => await window.registrationPromise);
await page.evaluate(async() => await window.activationPromise);
await page.reload();

expect(responses.size).toBe(2);
Expand Down Expand Up @@ -3766,6 +3766,7 @@ describe('Page', function() {
it('should report when a service worker is created and destroyed', async({page, server, browser}) => {
await page.goto(server.EMPTY_PAGE);
const createdTarget = new Promise(fulfill => browser.once('targetcreated', target => fulfill(target)));

await page.goto(server.PREFIX + '/serviceworkers/empty/sw.html');

expect((await createdTarget).type()).toBe('service_worker');
Expand Down

0 comments on commit c4b1ac9

Please sign in to comment.