summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsamdbeckham <sbeckham@gitlab.com>2019-03-29 18:40:40 +0000
committersamdbeckham <sbeckham@gitlab.com>2019-03-29 18:40:40 +0000
commitb9f3eff14e51364d65735b9400b81d23b20fddea (patch)
tree2c3756c96bd950ca8053182154c8c532c0b53f15
parent90b74f61ecd6311b9c2629cde7181224230201ca (diff)
downloadgitlab-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.
-rw-r--r--package.json1
-rw-r--r--spec/frontend/service_worker_spec.js23
-rw-r--r--yarn.lock38
3 files changed, 62 insertions, 0 deletions
diff --git a/package.json b/package.json
index 8dadb7fe4a2..3e476cfc7d2 100644
--- a/package.json
+++ b/package.json
@@ -180,6 +180,7 @@
"pixelmatch": "^4.0.2",
"postcss": "^7.0.14",
"prettier": "1.16.4",
+ "service-worker-mock": "^2.0.0",
"stylelint": "^9.10.1",
"stylelint-config-recommended": "^2.1.0",
"stylelint-scss": "^3.5.4",
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();
+ });
+ });
+});
diff --git a/yarn.lock b/yarn.lock
index 0241363d34d..71fbafe09f3 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3360,6 +3360,13 @@ dom-serializer@0:
domelementtype "~1.1.1"
entities "~1.1.1"
+dom-urls@^1.1.0:
+ version "1.1.0"
+ resolved "https://registry.yarnpkg.com/dom-urls/-/dom-urls-1.1.0.tgz#001ddf81628cd1e706125c7176f53ccec55d918e"
+ integrity sha1-AB3fgWKM0ecGElxxdvU8zsVdkY4=
+ dependencies:
+ urijs "^1.16.1"
+
domain-browser@^1.1.1:
version "1.1.7"
resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.1.7.tgz#867aa4b093faa05f1de08c06f4d7b21fdf8698bc"
@@ -9410,6 +9417,16 @@ serve-static@1.13.2:
parseurl "~1.3.2"
send "0.16.2"
+service-worker-mock@^2.0.0:
+ version "2.0.0"
+ resolved "https://registry.yarnpkg.com/service-worker-mock/-/service-worker-mock-2.0.0.tgz#6a2305a81e74cd5a086d36f49c869830ffbd7554"
+ integrity sha512-78AENCPDpdU6wkrSEAcMV4hSOPdZHSEZmyWV5WfLEw8sg2oT8mbkDaDRkYPCJ60Invw3nsM4YoYIToF32JbBFg==
+ dependencies:
+ dom-urls "^1.1.0"
+ shelving-mock-indexeddb "github:philipwalton/shelving-mock-indexeddb#621b7a275568051846d20e3e557fa1101418b1d1"
+ url-search-params "^0.10.0"
+ w3c-hr-time "^1.0.1"
+
set-blocking@^2.0.0, set-blocking@~2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"
@@ -9495,6 +9512,17 @@ shellwords@^0.1.1:
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==
+shelving-mock-event@^1.0.8:
+ version "1.0.12"
+ resolved "https://registry.yarnpkg.com/shelving-mock-event/-/shelving-mock-event-1.0.12.tgz#401dc90b3b49cbf2a817ecf2dd5a83eff4de2e14"
+ integrity sha512-2F+IZ010rwV3sA/Kd2hnC1vGNycsxeBJmjkXR8+4IOlv5e+Wvj+xH+A8Cv8/Z0lUyCut/HcxSpeDccYTVtnuaQ==
+
+"shelving-mock-indexeddb@github:philipwalton/shelving-mock-indexeddb#621b7a275568051846d20e3e557fa1101418b1d1":
+ version "1.0.5"
+ resolved "https://codeload.github.com/philipwalton/shelving-mock-indexeddb/tar.gz/621b7a275568051846d20e3e557fa1101418b1d1"
+ dependencies:
+ shelving-mock-event "^1.0.8"
+
sigmund@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590"
@@ -10768,6 +10796,11 @@ uri-js@^4.2.2:
dependencies:
punycode "^2.1.0"
+urijs@^1.16.1:
+ version "1.19.1"
+ resolved "https://registry.yarnpkg.com/urijs/-/urijs-1.19.1.tgz#5b0ff530c0cbde8386f6342235ba5ca6e995d25a"
+ integrity sha512-xVrGVi94ueCJNrBSTjWqjvtgvl3cyOTThp2zaMaFNGp3F542TR6sM3f2o8RqZl+AwteClSVmoCyt0ka4RjQOQg==
+
urix@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/urix/-/urix-0.1.0.tgz#da937f7a62e21fec1fd18d49b35c2935067a6c72"
@@ -10809,6 +10842,11 @@ url-search-params-polyfill@^5.0.0:
resolved "https://registry.yarnpkg.com/url-search-params-polyfill/-/url-search-params-polyfill-5.0.0.tgz#09b98337c89dcf6c6a6a0bfeb096f6ba83b7526b"
integrity sha512-+SCD22QJp4UnqPOI5UTTR0Ljuh8cHbjEf1lIiZrZ8nHTlTixqwVsVQTSfk5vrmDz7N09/Y+ka5jQr0ff35FnQQ==
+url-search-params@^0.10.0:
+ version "0.10.2"
+ resolved "https://registry.yarnpkg.com/url-search-params/-/url-search-params-0.10.2.tgz#e9da69646e48c6140c6732e1f07fb669525f5a4e"
+ integrity sha512-d6GYsr992Bo9rzTZFc9BUw3UFAAg3prE9JGVBgW2TLTbI3rSvg4VDa0BFXHMzKkWbAuhrmaFWpucpRJl+3W7Jg==
+
url-to-options@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/url-to-options/-/url-to-options-1.0.1.tgz#1505a03a289a48cbd7a434efbaeec5055f5633a9"