-
Notifications
You must be signed in to change notification settings - Fork 829
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Caches to a temp directory until activate event occurs * Remove private * Changing to actual activation vs just controller change * Delete entries as we move them acorss * Adding extra logic to wait for controller change on top of activate
- Loading branch information
Matt Gaunt
authored
Mar 5, 2018
1 parent
047aac5
commit f5792fd
Showing
25 changed files
with
256 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const activateSWSafari = require('./activate-sw-safari'); | ||
|
||
module.exports = async (swUrl) => { | ||
if (global.__workbox.seleniumBrowser.getId() === 'safari') { | ||
return activateSWSafari(swUrl); | ||
} | ||
|
||
const error = await global.__workbox.webdriver.executeAsyncScript((swUrl, cb) => { | ||
function _onStateChangePromise(registration, desiredState) { | ||
return new Promise((resolve, reject) => { | ||
if (registration.installing === null) { | ||
throw new Error('Service worker is not installing.'); | ||
} | ||
|
||
let serviceWorker = registration.installing; | ||
|
||
// We unregister all service workers after each test - this should | ||
// always trigger an install state change | ||
let stateChangeListener = function(evt) { | ||
if (evt.target.state === desiredState) { | ||
serviceWorker.removeEventListener('statechange', stateChangeListener); | ||
resolve(); | ||
return; | ||
} | ||
|
||
if (evt.target.state === 'redundant') { | ||
serviceWorker.removeEventListener('statechange', stateChangeListener); | ||
|
||
// Must call reject rather than throw error here due to this | ||
// being inside the scope of the callback function stateChangeListener | ||
reject(new Error('Installing servier worker became redundant')); | ||
return; | ||
} | ||
}; | ||
|
||
serviceWorker.addEventListener('statechange', stateChangeListener); | ||
}); | ||
} | ||
|
||
navigator.serviceWorker.register(swUrl) | ||
.then((registration) => { | ||
return _onStateChangePromise(registration, 'activated'); | ||
}) | ||
.then(() => { | ||
// Ensure the page is being controlled by the SW. | ||
if (navigator.serviceWorker.controller && | ||
navigator.serviceWorker.controller.scriptURL === swUrl) { | ||
return; | ||
} else { | ||
return new Promise((resolve) => { | ||
navigator.serviceWorker.addEventListener('controllerchange', () => { | ||
if (navigator.serviceWorker.controller.scriptURL === swUrl) { | ||
resolve(); | ||
} | ||
}); | ||
}); | ||
} | ||
}) | ||
.then(() => cb()) | ||
.catch((err) => cb(err)); | ||
}, swUrl); | ||
|
||
if (error) { | ||
throw error; | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.