diff options
author | samdbeckham <sbeckham@gitlab.com> | 2019-03-29 18:40:40 +0000 |
---|---|---|
committer | samdbeckham <sbeckham@gitlab.com> | 2019-03-29 18:40:40 +0000 |
commit | b9f3eff14e51364d65735b9400b81d23b20fddea (patch) | |
tree | 2c3756c96bd950ca8053182154c8c532c0b53f15 /spec/frontend/service_worker_spec.js | |
parent | 90b74f61ecd6311b9c2629cde7181224230201ca (diff) | |
download | gitlab-ce-pwa.tar.gz |
Adds service worker testspwa
They're very basic at the moment because service workers a re
notoriously hard to test.
I've made sure the cache busting is tested though as this is what has
the potential to cause the most problems if it fails.
Diffstat (limited to 'spec/frontend/service_worker_spec.js')
-rw-r--r-- | spec/frontend/service_worker_spec.js | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/frontend/service_worker_spec.js b/spec/frontend/service_worker_spec.js new file mode 100644 index 00000000000..09e05691342 --- /dev/null +++ b/spec/frontend/service_worker_spec.js @@ -0,0 +1,23 @@ +const makeServiceWorkerEnv = require('service-worker-mock'); +const SERVICE_WORKER_PATH = '~/sw.js'; + +describe('Service worker', () => { + beforeEach(() => { + Object.assign(global, makeServiceWorkerEnv()); + jest.resetModules(); + }); + + it('should delete old caches on activate', () => { + require(SERVICE_WORKER_PATH); + + // Create old cache + self.caches.open('OLD_CACHE').then(() => { + expect(self.snapshot().caches.OLD_CACHE).toBeDefined(); + }); + + // Activate and verify old cache is removed + self.trigger('activate').then(() => { + expect(self.snapshot().caches.OLD_CACHE).toBeUndefined(); + }); + }); +}); |