This file contains hidden or 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
| const fakePushEvent = new PushEvent('push', { | |
| data: JSON.stringify(pushData), | |
| }); |
This file contains hidden or 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
| self.addEventListener('message', (event) => { | |
| if (event.data !== 'run-tests') { | |
| return; | |
| } | |
| const runResults = mocha.run(); | |
| runResults.on('end', () => { | |
| event.ports[0].postMessage({ | |
| failures: runResults.failures, | |
| total: runResults.total, |
This file contains hidden or 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
| it('should run sw-unit-tests.js unit tests', function() { | |
| return navigator.serviceWorker.register('/test/sw/sw-unit-tests.js') | |
| .then((reg) => { | |
| return window.__waitForSWState(reg, 'activated'); | |
| }) | |
| .then((serviceWorker) => { | |
| return sendMessage(serviceWorker, 'run-tests'); | |
| }) | |
| .then((results) => { | |
| if (results.failures > 0) { |
This file contains hidden or 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
| const sendMessage = (serviceWorker, message) => { | |
| return new Promise(function(resolve, reject) { | |
| const messageChannel = new MessageChannel(); | |
| messageChannel.port1.onmessage = function(event) { | |
| if (event.data.error) { | |
| reject(event.data.error); | |
| } else { | |
| resolve(event.data); | |
| } | |
| }; |
This file contains hidden or 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
| importScripts('/node_modules/mocha/mocha.js'); | |
| mocha.setup({ | |
| ui: 'bdd', | |
| reporter: null, | |
| }); | |
| describe('First SW Test Suite', function() { | |
| it('should test something', function() { | |
| ... |
This file contains hidden or 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
| describe('Run SW Unit Tests', function() { | |
| beforeEach(function() { | |
| return window.__testCleanup(); | |
| }); | |
| after(function() { | |
| return window.__testCleanup(); | |
| }); | |
| it('should run sw-unit-tests.js unit tests', function() { |
This file contains hidden or 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
| <script src="/test/browser/run-sw-tests.js"></script> |
This file contains hidden or 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
| beforeEach(function() { | |
| return window.__testCleanup(); | |
| }); | |
| after(function() { | |
| return window.__testCleanup(); | |
| }); |
This file contains hidden or 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
| <script src="/test/utils/sw-test-cleanup.js"></script> |
This file contains hidden or 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
| window.__testCleanup = () => { | |
| const unregisterSW = () => { | |
| return navigator.serviceWorker.getRegistrations() | |
| .then((registrations) => { | |
| const unregisterPromise = registrations.map((registration) => { | |
| return registration.unregister(); | |
| }); | |
| return Promise.all(unregisterPromise); | |
| }); | |
| }; |