From 8da6cefbfd0453915dd580f254272749cacd31ec Mon Sep 17 00:00:00 2001 From: Mat Scales Date: Thu, 30 Jul 2015 14:35:06 +0100 Subject: [PATCH] Flatten array of items to precache. Fixes #24 --- lib/sw-toolbox.js | 14 ++++++++++++-- sw-toolbox.js | 2 +- sw-toolbox.map.json | 2 +- tests/fixtures/a | 1 + tests/fixtures/b | 1 + tests/fixtures/c | 1 + tests/fixtures/d | 1 + tests/fixtures/e | 1 + tests/fixtures/f | 1 + tests/fixtures/g | 1 + tests/fixtures/h | 1 + tests/fixtures/i | 1 + tests/fixtures/j | 1 + tests/fixtures/k | 1 + tests/fixtures/l | 1 + tests/fixtures/m | 1 + tests/fixtures/n | 1 + tests/service-worker.js | 12 ++++++++++++ tests/tests.js | 19 ++++++++++++++++++- 19 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 tests/fixtures/a create mode 100644 tests/fixtures/b create mode 100644 tests/fixtures/c create mode 100644 tests/fixtures/d create mode 100644 tests/fixtures/e create mode 100644 tests/fixtures/f create mode 100644 tests/fixtures/g create mode 100644 tests/fixtures/h create mode 100644 tests/fixtures/i create mode 100644 tests/fixtures/j create mode 100644 tests/fixtures/k create mode 100644 tests/fixtures/l create mode 100644 tests/fixtures/m create mode 100644 tests/fixtures/n diff --git a/lib/sw-toolbox.js b/lib/sw-toolbox.js index dcff913..b9a8f99 100644 --- a/lib/sw-toolbox.js +++ b/lib/sw-toolbox.js @@ -25,14 +25,24 @@ helpers.debug('Service Worker Toolbox is loading'); // Install +var flatten = function(items) { + return items.reduce(function(a, b) { + return a.concat(b); + }, []); +}; + self.addEventListener('install', function(event) { var inactiveCache = options.cacheName + '$$$inactive$$$'; helpers.debug('install event fired'); helpers.debug('creating cache [' + inactiveCache + ']'); - helpers.debug('preCache list: ' + (options.preCacheItems.join(', ') || '(none)')); event.waitUntil( helpers.openCache({cacheName: inactiveCache}).then(function(cache) { - return Promise.all(options.preCacheItems).then(cache.addAll.bind(cache)); + return Promise.all(options.preCacheItems) + .then(flatten) + .then(function(preCacheItems) { + helpers.debug('preCache list: ' + (preCacheItems.join(', ') || '(none)')); + return cache.addAll(preCacheItems); + }); }) ); }); diff --git a/sw-toolbox.js b/sw-toolbox.js index ed37445..f6b7bec 100644 --- a/sw-toolbox.js +++ b/sw-toolbox.js @@ -15,7 +15,7 @@ */ !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o;"undefined"!=typeof window?o=window:"undefined"!=typeof global?o=global:"undefined"!=typeof self&&(o=self),o.toolbox=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o binding:\n var sequence = [];\n\n requests = requests.map(function(request) {\n if (request instanceof Request) {\n return request;\n }\n else {\n return String(request); // may throw TypeError\n }\n });\n\n return Promise.all(\n requests.map(function(request) {\n if (typeof request === 'string') {\n request = new Request(request);\n }\n\n var scheme = new URL(request.url).protocol;\n\n if (scheme !== 'http:' && scheme !== 'https:') {\n throw new NetworkError(\"Invalid scheme\");\n }\n\n return fetch(request.clone());\n })\n );\n }).then(function(responses) {\n // TODO: check that requests don't overwrite one another\n // (don't think this is possible to polyfill due to opaque responses)\n return Promise.all(\n responses.map(function(response, i) {\n return cache.put(requests[i], response);\n })\n );\n }).then(function() {\n return undefined;\n });\n };\n}\n","/*\n\tCopyright 2014 Google Inc. All Rights Reserved.\n\n\tLicensed under the Apache License, Version 2.0 (the \"License\");\n\tyou may not use this file except in compliance with the License.\n\tYou may obtain a copy of the License at\n\n\t http://www.apache.org/licenses/LICENSE-2.0\n\n\tUnless required by applicable law or agreed to in writing, software\n\tdistributed under the License is distributed on an \"AS IS\" BASIS,\n\tWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\tSee the License for the specific language governing permissions and\n\tlimitations under the License.\n*/\n'use strict';\nvar helpers = require('../helpers');\n\nfunction networkOnly(request, values, options) {\n helpers.debug('Strategy: network only [' + request.url + ']', options);\n return fetch(request);\n}\n\nmodule.exports = networkOnly;","/*\n Copyright 2014 Google Inc. All Rights Reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n'use strict';\nvar globalOptions = require('../options');\nvar helpers = require('../helpers');\n\nfunction networkFirst(request, values, options) {\n options = options || {};\n var successResponses = options.successResponses || globalOptions.successResponses;\n helpers.debug('Strategy: network first [' + request.url + ']', options);\n return helpers.openCache(options).then(function(cache) {\n return helpers.fetchAndCache(request, options).then(function(response) {\n if (successResponses.test(response.status)) {\n return response;\n }\n\n return cache.match(request).then(function(cacheResponse) {\n helpers.debug('Response was an HTTP error', options);\n if (cacheResponse) {\n helpers.debug('Resolving with cached response instead', options);\n return cacheResponse;\n } else {\n // If we didn't have anything in the cache, it's better to return the\n // error page than to return nothing\n helpers.debug('No cached result, resolving with HTTP error response from network', options);\n return response;\n }\n });\n }).catch(function(error) {\n helpers.debug('Network error, fallback to cache [' + request.url + ']', options);\n return cache.match(request);\n });\n });\n}\n\nmodule.exports = networkFirst;","/*\n\tCopyright 2014 Google Inc. All Rights Reserved.\n\n\tLicensed under the Apache License, Version 2.0 (the \"License\");\n\tyou may not use this file except in compliance with the License.\n\tYou may obtain a copy of the License at\n\n\t http://www.apache.org/licenses/LICENSE-2.0\n\n\tUnless required by applicable law or agreed to in writing, software\n\tdistributed under the License is distributed on an \"AS IS\" BASIS,\n\tWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\tSee the License for the specific language governing permissions and\n\tlimitations under the License.\n*/\n'use strict';\nvar helpers = require('../helpers');\n\nfunction cacheOnly(request, values, options) {\n helpers.debug('Strategy: cache only [' + request.url + ']', options);\n return helpers.openCache(options).then(function(cache) {\n return cache.match(request);\n });\n}\n\nmodule.exports = cacheOnly;\n","/*\n\tCopyright 2014 Google Inc. All Rights Reserved.\n\n\tLicensed under the Apache License, Version 2.0 (the \"License\");\n\tyou may not use this file except in compliance with the License.\n\tYou may obtain a copy of the License at\n\n\t http://www.apache.org/licenses/LICENSE-2.0\n\n\tUnless required by applicable law or agreed to in writing, software\n\tdistributed under the License is distributed on an \"AS IS\" BASIS,\n\tWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\tSee the License for the specific language governing permissions and\n\tlimitations under the License.\n*/\n'use strict';\nvar helpers = require('../helpers');\n\nfunction cacheFirst(request, values, options) {\n helpers.debug('Strategy: cache first [' + request.url + ']', options);\n return helpers.openCache(options).then(function(cache) {\n return cache.match(request).then(function (response) {\n if (response) {\n return response;\n }\n\n return helpers.fetchAndCache(request, options);\n });\n });\n}\n\nmodule.exports = cacheFirst;","/*\n Copyright 2014 Google Inc. All Rights Reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n'use strict';\nvar helpers = require('../helpers');\nvar cacheOnly = require('./cacheOnly');\n\nfunction fastest(request, values, options) {\n helpers.debug('Strategy: fastest [' + request.url + ']', options);\n\n return new Promise(function(resolve, reject) {\n var rejected = false;\n var reasons = [];\n\n var maybeReject = function(reason) {\n reasons.push(reason.toString());\n if (rejected) {\n reject(new Error('Both cache and network failed: \"' + reasons.join('\", \"') + '\"'));\n } else {\n rejected = true;\n }\n };\n\n var maybeResolve = function(result) {\n if (result instanceof Response) {\n resolve(result);\n } else {\n maybeReject('No result returned');\n }\n };\n\n helpers.fetchAndCache(request.clone(), options)\n .then(maybeResolve, maybeReject);\n\n cacheOnly(request, options)\n .then(maybeResolve, maybeReject);\n });\n}\n\nmodule.exports = fastest;\n","var isarray = require('isarray')\n\n/**\n * Expose `pathToRegexp`.\n */\nmodule.exports = pathToRegexp\nmodule.exports.parse = parse\nmodule.exports.compile = compile\nmodule.exports.tokensToFunction = tokensToFunction\nmodule.exports.tokensToRegExp = tokensToRegExp\n\n/**\n * The main path matching regexp utility.\n *\n * @type {RegExp}\n */\nvar PATH_REGEXP = new RegExp([\n // Match escaped characters that would otherwise appear in future matches.\n // This allows the user to escape special characters that won't transform.\n '(\\\\\\\\.)',\n // Match Express-style parameters and un-named parameters with a prefix\n // and optional suffixes. Matches appear as:\n //\n // \"/:test(\\\\d+)?\" => [\"/\", \"test\", \"\\d+\", undefined, \"?\", undefined]\n // \"/route(\\\\d+)\" => [undefined, undefined, undefined, \"\\d+\", undefined, undefined]\n // \"/*\" => [\"/\", undefined, undefined, undefined, undefined, \"*\"]\n '([\\\\/.])?(?:(?:\\\\:(\\\\w+)(?:\\\\(((?:\\\\\\\\.|[^()])+)\\\\))?|\\\\(((?:\\\\\\\\.|[^()])+)\\\\))([+*?])?|(\\\\*))'\n].join('|'), 'g')\n\n/**\n * Parse a string for the raw tokens.\n *\n * @param {String} str\n * @return {Array}\n */\nfunction parse (str) {\n var tokens = []\n var key = 0\n var index = 0\n var path = ''\n var res\n\n while ((res = PATH_REGEXP.exec(str)) != null) {\n var m = res[0]\n var escaped = res[1]\n var offset = res.index\n path += str.slice(index, offset)\n index = offset + m.length\n\n // Ignore already escaped sequences.\n if (escaped) {\n path += escaped[1]\n continue\n }\n\n // Push the current path onto the tokens.\n if (path) {\n tokens.push(path)\n path = ''\n }\n\n var prefix = res[2]\n var name = res[3]\n var capture = res[4]\n var group = res[5]\n var suffix = res[6]\n var asterisk = res[7]\n\n var repeat = suffix === '+' || suffix === '*'\n var optional = suffix === '?' || suffix === '*'\n var delimiter = prefix || '/'\n var pattern = capture || group || (asterisk ? '.*' : '[^' + delimiter + ']+?')\n\n tokens.push({\n name: name || key++,\n prefix: prefix || '',\n delimiter: delimiter,\n optional: optional,\n repeat: repeat,\n pattern: escapeGroup(pattern)\n })\n }\n\n // Match any characters still remaining.\n if (index < str.length) {\n path += str.substr(index)\n }\n\n // If the path exists, push it onto the end.\n if (path) {\n tokens.push(path)\n }\n\n return tokens\n}\n\n/**\n * Compile a string to a template function for the path.\n *\n * @param {String} str\n * @return {Function}\n */\nfunction compile (str) {\n return tokensToFunction(parse(str))\n}\n\n/**\n * Expose a method for transforming tokens into the path function.\n */\nfunction tokensToFunction (tokens) {\n // Compile all the tokens into regexps.\n var matches = new Array(tokens.length)\n\n // Compile all the patterns before compilation.\n for (var i = 0; i < tokens.length; i++) {\n if (typeof tokens[i] === 'object') {\n matches[i] = new RegExp('^' + tokens[i].pattern + '$')\n }\n }\n\n return function (obj) {\n var path = ''\n\n obj = obj || {}\n\n for (var i = 0; i < tokens.length; i++) {\n var key = tokens[i]\n\n if (typeof key === 'string') {\n path += key\n\n continue\n }\n\n var value = obj[key.name]\n\n if (value == null) {\n if (key.optional) {\n continue\n } else {\n throw new TypeError('Expected \"' + key.name + '\" to be defined')\n }\n }\n\n if (isarray(value)) {\n if (!key.repeat) {\n throw new TypeError('Expected \"' + key.name + '\" to not repeat')\n }\n\n if (value.length === 0) {\n if (key.optional) {\n continue\n } else {\n throw new TypeError('Expected \"' + key.name + '\" to not be empty')\n }\n }\n\n for (var j = 0; j < value.length; j++) {\n if (!matches[i].test(value[j])) {\n throw new TypeError('Expected all \"' + key.name + '\" to match \"' + key.pattern + '\"')\n }\n\n path += (j === 0 ? key.prefix : key.delimiter) + encodeURIComponent(value[j])\n }\n\n continue\n }\n\n if (!matches[i].test(value)) {\n throw new TypeError('Expected \"' + key.name + '\" to match \"' + key.pattern + '\"')\n }\n\n path += key.prefix + encodeURIComponent(value)\n }\n\n return path\n }\n}\n\n/**\n * Escape a regular expression string.\n *\n * @param {String} str\n * @return {String}\n */\nfunction escapeString (str) {\n return str.replace(/([.+*?=^!:${}()[\\]|\\/])/g, '\\\\$1')\n}\n\n/**\n * Escape the capturing group by escaping special characters and meaning.\n *\n * @param {String} group\n * @return {String}\n */\nfunction escapeGroup (group) {\n return group.replace(/([=!:$\\/()])/g, '\\\\$1')\n}\n\n/**\n * Attach the keys as a property of the regexp.\n *\n * @param {RegExp} re\n * @param {Array} keys\n * @return {RegExp}\n */\nfunction attachKeys (re, keys) {\n re.keys = keys\n return re\n}\n\n/**\n * Get the flags for a regexp from the options.\n *\n * @param {Object} options\n * @return {String}\n */\nfunction flags (options) {\n return options.sensitive ? '' : 'i'\n}\n\n/**\n * Pull out keys from a regexp.\n *\n * @param {RegExp} path\n * @param {Array} keys\n * @return {RegExp}\n */\nfunction regexpToRegexp (path, keys) {\n // Use a negative lookahead to match only capturing groups.\n var groups = path.source.match(/\\((?!\\?)/g)\n\n if (groups) {\n for (var i = 0; i < groups.length; i++) {\n keys.push({\n name: i,\n prefix: null,\n delimiter: null,\n optional: false,\n repeat: false,\n pattern: null\n })\n }\n }\n\n return attachKeys(path, keys)\n}\n\n/**\n * Transform an array into a regexp.\n *\n * @param {Array} path\n * @param {Array} keys\n * @param {Object} options\n * @return {RegExp}\n */\nfunction arrayToRegexp (path, keys, options) {\n var parts = []\n\n for (var i = 0; i < path.length; i++) {\n parts.push(pathToRegexp(path[i], keys, options).source)\n }\n\n var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options))\n\n return attachKeys(regexp, keys)\n}\n\n/**\n * Create a path regexp from string input.\n *\n * @param {String} path\n * @param {Array} keys\n * @param {Object} options\n * @return {RegExp}\n */\nfunction stringToRegexp (path, keys, options) {\n var tokens = parse(path)\n var re = tokensToRegExp(tokens, options)\n\n // Attach keys back to the regexp.\n for (var i = 0; i < tokens.length; i++) {\n if (typeof tokens[i] !== 'string') {\n keys.push(tokens[i])\n }\n }\n\n return attachKeys(re, keys)\n}\n\n/**\n * Expose a function for taking tokens and returning a RegExp.\n *\n * @param {Array} tokens\n * @param {Array} keys\n * @param {Object} options\n * @return {RegExp}\n */\nfunction tokensToRegExp (tokens, options) {\n options = options || {}\n\n var strict = options.strict\n var end = options.end !== false\n var route = ''\n var lastToken = tokens[tokens.length - 1]\n var endsWithSlash = typeof lastToken === 'string' && /\\/$/.test(lastToken)\n\n // Iterate over the tokens and create our regexp string.\n for (var i = 0; i < tokens.length; i++) {\n var token = tokens[i]\n\n if (typeof token === 'string') {\n route += escapeString(token)\n } else {\n var prefix = escapeString(token.prefix)\n var capture = token.pattern\n\n if (token.repeat) {\n capture += '(?:' + prefix + capture + ')*'\n }\n\n if (token.optional) {\n if (prefix) {\n capture = '(?:' + prefix + '(' + capture + '))?'\n } else {\n capture = '(' + capture + ')?'\n }\n } else {\n capture = prefix + '(' + capture + ')'\n }\n\n route += capture\n }\n }\n\n // In non-strict mode we allow a slash at the end of match. If the path to\n // match already ends with a slash, we remove it for consistency. The slash\n // is valid at the end of a path match, not in the middle. This is important\n // in non-ending mode, where \"/test/\" shouldn't match \"/test//route\".\n if (!strict) {\n route = (endsWithSlash ? route.slice(0, -2) : route) + '(?:\\\\/(?=$))?'\n }\n\n if (end) {\n route += '$'\n } else {\n // In non-ending mode, we need the capturing groups to match as much as\n // possible by using a positive lookahead to the end or next path segment.\n route += strict && endsWithSlash ? '' : '(?=\\\\/|$)'\n }\n\n return new RegExp('^' + route, flags(options))\n}\n\n/**\n * Normalize the given path string, returning a regular expression.\n *\n * An empty array can be passed in for the keys, which will hold the\n * placeholder key descriptions. For example, using `/user/:id`, `keys` will\n * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.\n *\n * @param {(String|RegExp|Array)} path\n * @param {Array} [keys]\n * @param {Object} [options]\n * @return {RegExp}\n */\nfunction pathToRegexp (path, keys, options) {\n keys = keys || []\n\n if (!isarray(keys)) {\n options = keys\n keys = []\n } else if (!options) {\n options = {}\n }\n\n if (path instanceof RegExp) {\n return regexpToRegexp(path, keys, options)\n }\n\n if (isarray(path)) {\n return arrayToRegexp(path, keys, options)\n }\n\n return stringToRegexp(path, keys, options)\n}\n","module.exports = Array.isArray || function (arr) {\n return Object.prototype.toString.call(arr) == '[object Array]';\n};\n"]} \ No newline at end of file +{"version":3,"sources":["node_modules/browserify/node_modules/browser-pack/_prelude.js","lib/router.js","lib/sw-toolbox.js","lib/options.js","lib/helpers.js","lib/strategies/index.js","lib/route.js","node_modules/serviceworker-cache-polyfill/index.js","lib/strategies/networkOnly.js","lib/strategies/networkFirst.js","lib/strategies/cacheFirst.js","lib/strategies/cacheOnly.js","lib/strategies/fastest.js","node_modules/path-to-regexp/index.js","node_modules/path-to-regexp/node_modules/isarray/index.js"],"names":["cache","url","options","helpers","openCache","then","add","uncache","precache","items","Array","isArray","preCacheItems","concat","require","router","strategies","debug","flatten","reduce","a","b","self","addEventListener","event","inactiveCache","cacheName","waitUntil","Promise","all","join","addAll","renameCache","handler","match","request","respondWith","module","exports","networkOnly","networkFirst","cacheOnly","cacheFirst","fastest","scope","registration","URL","location","href","successResponses","message","flag","globalOptions","console","log","caches","open","fetchAndCache","fetch","clone","response","method","test","status","put","source","destination","results","sourceCache","destCache","keys","requests","map","basePath","pathname","pathRegexp","Route","path","indexOf","this","regexp","prototype","makeHandler","exec","values","forEach","key","index","name","bind","Cache","NetworkError","code","Object","create","Error","resolve","arguments","length","TypeError","Request","String","scheme","protocol","responses","i","undefined","cacheResponse","error","reject","rejected","reasons","maybeReject","reason","push","toString","maybeResolve","result","Response","parse","str","res","tokens","PATH_REGEXP","m","escaped","offset","slice","prefix","capture","group","suffix","asterisk","repeat","optional","delimiter","pattern","escapeGroup","substr","compile","tokensToFunction","matches","RegExp","obj","value","isarray","j","encodeURIComponent","escapeString","replace","attachKeys","re","flags","sensitive","regexpToRegexp","groups","arrayToRegexp","parts","pathToRegexp","stringToRegexp","tokensToRegExp","strict","end","route","lastToken","endsWithSlash","token","arr","call"],"mappings":"AAAA;AEeA,YAwDA,SAASA,OAAMC,EAAKC,GAClB,MAAOC,SAAQC,UAAUF,GAASG,KAAK,SAASL,GAC9C,MAAOA,GAAMM,IAAIL,KAIrB,QAASM,SAAQN,EAAKC,GACpB,MAAOC,SAAQC,UAAUF,GAASG,KAAK,SAASL,GAC9C,MAAOA,GAAAA,UAAaC,KAIxB,QAASO,UAASC,GACXC,MAAMC,QAAQF,KACjBA,GAASA,IAEXP,QAAQU,cAAgBV,QAAQU,cAAcC,OAAOJ,GAtEvDK,QAAQ,+BACR,IAAIZ,SAAUY,QAAQ,aAClBC,OAASD,QAAQ,YACjBX,QAAUW,QAAQ,aAClBE,WAAaF,QAAQ,eAEzBX,SAAQc,MAAM,oCAId,IAAIC,SAAU,SAAST,GACrB,MAAOA,GAAMU,OAAO,SAASC,EAAGC,GAC9B,MAAOD,GAAEP,OAAOQ,QAIpBC,MAAKC,iBAAiB,UAAW,SAASC,GACxC,GAAIC,GAAgBvB,QAAQwB,UAAY,gBACxCvB,SAAQc,MAAM,uBACdd,QAAQc,MAAM,mBAAqBQ,EAAgB,KACnDD,EAAMG,UACJxB,QAAQC,WAAWsB,UAAWD,IAAgBpB,KAAK,SAASL,GAC1D,MAAO4B,SAAQC,IAAI3B,QAAQU,eACxBP,KAAKa,SACLb,KAAK,SAASO,GAEb,MADAT,SAAQc,MAAM,mBAAqBL,EAAckB,KAAK,OAAS,WACxD9B,EAAM+B,OAAOnB,UAQ9BU,KAAKC,iBAAiB,WAAY,SAASC,GACzCrB,QAAQc,MAAM,uBACd,IAAIQ,GAAgBvB,QAAQwB,UAAY,gBACxCF,GAAMG,UAAUxB,QAAQ6B,YAAYP,EAAevB,QAAQwB,cAK7DJ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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;ASpFA,YAGA,SAASlC,YAAWP,EAASiD,EAAQlF,GAEnC,MADAC,SAAQc,MAAM,0BAA4BkB,EAAQlC,IAAM,IAAKC,GACtDC,QAAQC,UAAUF,GAASG,KAAK,SAASL,GAC9C,MAAOA,GAAMkC,MAAMC,GAAS9B,KAAK,SAAUuD,GACzC,MAAIA,GACKA,EAGFzD,QAAQsD,cAActB,EAASjC,OAV5C,GAAIC,SAAUW,QAAQ,aAetBuB,QAAOC,QAAUI;;AChBjB,YAGA,SAASD,WAAUN,EAASiD,EAAQlF,GAElC,MADAC,SAAQc,MAAM,yBAA2BkB,EAAQlC,IAAM,IAAKC,GACrDC,QAAQC,UAAUF,GAASG,KAAK,SAASL,GAC9C,MAAOA,GAAMkC,MAAMC,KALvB,GAAIhC,SAAUW,QAAQ,aAStBuB,QAAOC,QAAUG;;ACVjB,YAIA,SAASE,SAAQR,EAASiD,EAAQlF,GAGhC,MAFAC,SAAQc,MAAM,sBAAwBkB,EAAQlC,IAAM,IAAKC,GAElD,GAAI0B,SAAQ,SAASoE,EAASa,GACnC,GAAIC,IAAW,EACXC,KAEAC,EAAc,SAASC,GACzBF,EAAQG,KAAKD,EAAOE,YAChBL,EACFD,EAAO,GAAId,OAAM,mCAAqCgB,EAAQjF,KAAK,QAAU,MAE7EgF,GAAW,GAI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ASrC,GAC/B,MAAIA,aAAmBiE,SACdjE,EAGAkE,OAAOlE,KAIXP,QAAQC,IACb0C,EAASC,IAAI,SAASrC,GACG,gBAAZA,KACTA,EAAU,GAAIiE,SAAQjE,GAGxB,IAAImE,GAAS,GAAIxD,KAAIX,EAAQlC,KAAKsG,QAElC,IAAe,UAAXD,GAAiC,WAAXA,EACxB,KAAM,IAAIX,GAAa,iBAGzB,OAAOjC,OAAMvB,EAAQwB,cAGxBtD,KAAK,SAASmG,GAGf,MAAO5E,SAAQC,IACb2E,EAAUhC,IAAI,SAASZ,EAAU6C,GAC/B,MAAOzG,GAAMgE,IAAIO,EAASkC,GAAI7C,QAGjCvD,KAAK,WACN,MAAOqG","file":"bundle.js","sourcesContent":["(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require==\"function\"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error(\"Cannot find module '\"+o+\"'\");throw f.code=\"MODULE_NOT_FOUND\",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require==\"function\"&&require;for(var o=0;o binding:\n var sequence = [];\n\n requests = requests.map(function(request) {\n if (request instanceof Request) {\n return request;\n }\n else {\n return String(request); // may throw TypeError\n }\n });\n\n return Promise.all(\n requests.map(function(request) {\n if (typeof request === 'string') {\n request = new Request(request);\n }\n\n var scheme = new URL(request.url).protocol;\n\n if (scheme !== 'http:' && scheme !== 'https:') {\n throw new NetworkError(\"Invalid scheme\");\n }\n\n return fetch(request.clone());\n })\n );\n }).then(function(responses) {\n // TODO: check that requests don't overwrite one another\n // (don't think this is possible to polyfill due to opaque responses)\n return Promise.all(\n responses.map(function(response, i) {\n return cache.put(requests[i], response);\n })\n );\n }).then(function() {\n return undefined;\n });\n };\n}\n","/*\n\tCopyright 2014 Google Inc. All Rights Reserved.\n\n\tLicensed under the Apache License, Version 2.0 (the \"License\");\n\tyou may not use this file except in compliance with the License.\n\tYou may obtain a copy of the License at\n\n\t http://www.apache.org/licenses/LICENSE-2.0\n\n\tUnless required by applicable law or agreed to in writing, software\n\tdistributed under the License is distributed on an \"AS IS\" BASIS,\n\tWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\tSee the License for the specific language governing permissions and\n\tlimitations under the License.\n*/\n'use strict';\nvar helpers = require('../helpers');\n\nfunction networkOnly(request, values, options) {\n helpers.debug('Strategy: network only [' + request.url + ']', options);\n return fetch(request);\n}\n\nmodule.exports = networkOnly;","/*\n Copyright 2014 Google Inc. All Rights Reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n'use strict';\nvar globalOptions = require('../options');\nvar helpers = require('../helpers');\n\nfunction networkFirst(request, values, options) {\n options = options || {};\n var successResponses = options.successResponses || globalOptions.successResponses;\n helpers.debug('Strategy: network first [' + request.url + ']', options);\n return helpers.openCache(options).then(function(cache) {\n return helpers.fetchAndCache(request, options).then(function(response) {\n if (successResponses.test(response.status)) {\n return response;\n }\n\n return cache.match(request).then(function(cacheResponse) {\n helpers.debug('Response was an HTTP error', options);\n if (cacheResponse) {\n helpers.debug('Resolving with cached response instead', options);\n return cacheResponse;\n } else {\n // If we didn't have anything in the cache, it's better to return the\n // error page than to return nothing\n helpers.debug('No cached result, resolving with HTTP error response from network', options);\n return response;\n }\n });\n }).catch(function(error) {\n helpers.debug('Network error, fallback to cache [' + request.url + ']', options);\n return cache.match(request);\n });\n });\n}\n\nmodule.exports = networkFirst;","/*\n\tCopyright 2014 Google Inc. All Rights Reserved.\n\n\tLicensed under the Apache License, Version 2.0 (the \"License\");\n\tyou may not use this file except in compliance with the License.\n\tYou may obtain a copy of the License at\n\n\t http://www.apache.org/licenses/LICENSE-2.0\n\n\tUnless required by applicable law or agreed to in writing, software\n\tdistributed under the License is distributed on an \"AS IS\" BASIS,\n\tWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\tSee the License for the specific language governing permissions and\n\tlimitations under the License.\n*/\n'use strict';\nvar helpers = require('../helpers');\n\nfunction cacheFirst(request, values, options) {\n helpers.debug('Strategy: cache first [' + request.url + ']', options);\n return helpers.openCache(options).then(function(cache) {\n return cache.match(request).then(function (response) {\n if (response) {\n return response;\n }\n\n return helpers.fetchAndCache(request, options);\n });\n });\n}\n\nmodule.exports = cacheFirst;","/*\n\tCopyright 2014 Google Inc. All Rights Reserved.\n\n\tLicensed under the Apache License, Version 2.0 (the \"License\");\n\tyou may not use this file except in compliance with the License.\n\tYou may obtain a copy of the License at\n\n\t http://www.apache.org/licenses/LICENSE-2.0\n\n\tUnless required by applicable law or agreed to in writing, software\n\tdistributed under the License is distributed on an \"AS IS\" BASIS,\n\tWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n\tSee the License for the specific language governing permissions and\n\tlimitations under the License.\n*/\n'use strict';\nvar helpers = require('../helpers');\n\nfunction cacheOnly(request, values, options) {\n helpers.debug('Strategy: cache only [' + request.url + ']', options);\n return helpers.openCache(options).then(function(cache) {\n return cache.match(request);\n });\n}\n\nmodule.exports = cacheOnly;\n","/*\n Copyright 2014 Google Inc. All Rights Reserved.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n'use strict';\nvar helpers = require('../helpers');\nvar cacheOnly = require('./cacheOnly');\n\nfunction fastest(request, values, options) {\n helpers.debug('Strategy: fastest [' + request.url + ']', options);\n\n return new Promise(function(resolve, reject) {\n var rejected = false;\n var reasons = [];\n\n var maybeReject = function(reason) {\n reasons.push(reason.toString());\n if (rejected) {\n reject(new Error('Both cache and network failed: \"' + reasons.join('\", \"') + '\"'));\n } else {\n rejected = true;\n }\n };\n\n var maybeResolve = function(result) {\n if (result instanceof Response) {\n resolve(result);\n } else {\n maybeReject('No result returned');\n }\n };\n\n helpers.fetchAndCache(request.clone(), options)\n .then(maybeResolve, maybeReject);\n\n cacheOnly(request, options)\n .then(maybeResolve, maybeReject);\n });\n}\n\nmodule.exports = fastest;\n","var isarray = require('isarray')\n\n/**\n * Expose `pathToRegexp`.\n */\nmodule.exports = pathToRegexp\nmodule.exports.parse = parse\nmodule.exports.compile = compile\nmodule.exports.tokensToFunction = tokensToFunction\nmodule.exports.tokensToRegExp = tokensToRegExp\n\n/**\n * The main path matching regexp utility.\n *\n * @type {RegExp}\n */\nvar PATH_REGEXP = new RegExp([\n // Match escaped characters that would otherwise appear in future matches.\n // This allows the user to escape special characters that won't transform.\n '(\\\\\\\\.)',\n // Match Express-style parameters and un-named parameters with a prefix\n // and optional suffixes. Matches appear as:\n //\n // \"/:test(\\\\d+)?\" => [\"/\", \"test\", \"\\d+\", undefined, \"?\", undefined]\n // \"/route(\\\\d+)\" => [undefined, undefined, undefined, \"\\d+\", undefined, undefined]\n // \"/*\" => [\"/\", undefined, undefined, undefined, undefined, \"*\"]\n '([\\\\/.])?(?:(?:\\\\:(\\\\w+)(?:\\\\(((?:\\\\\\\\.|[^()])+)\\\\))?|\\\\(((?:\\\\\\\\.|[^()])+)\\\\))([+*?])?|(\\\\*))'\n].join('|'), 'g')\n\n/**\n * Parse a string for the raw tokens.\n *\n * @param {String} str\n * @return {Array}\n */\nfunction parse (str) {\n var tokens = []\n var key = 0\n var index = 0\n var path = ''\n var res\n\n while ((res = PATH_REGEXP.exec(str)) != null) {\n var m = res[0]\n var escaped = res[1]\n var offset = res.index\n path += str.slice(index, offset)\n index = offset + m.length\n\n // Ignore already escaped sequences.\n if (escaped) {\n path += escaped[1]\n continue\n }\n\n // Push the current path onto the tokens.\n if (path) {\n tokens.push(path)\n path = ''\n }\n\n var prefix = res[2]\n var name = res[3]\n var capture = res[4]\n var group = res[5]\n var suffix = res[6]\n var asterisk = res[7]\n\n var repeat = suffix === '+' || suffix === '*'\n var optional = suffix === '?' || suffix === '*'\n var delimiter = prefix || '/'\n var pattern = capture || group || (asterisk ? '.*' : '[^' + delimiter + ']+?')\n\n tokens.push({\n name: name || key++,\n prefix: prefix || '',\n delimiter: delimiter,\n optional: optional,\n repeat: repeat,\n pattern: escapeGroup(pattern)\n })\n }\n\n // Match any characters still remaining.\n if (index < str.length) {\n path += str.substr(index)\n }\n\n // If the path exists, push it onto the end.\n if (path) {\n tokens.push(path)\n }\n\n return tokens\n}\n\n/**\n * Compile a string to a template function for the path.\n *\n * @param {String} str\n * @return {Function}\n */\nfunction compile (str) {\n return tokensToFunction(parse(str))\n}\n\n/**\n * Expose a method for transforming tokens into the path function.\n */\nfunction tokensToFunction (tokens) {\n // Compile all the tokens into regexps.\n var matches = new Array(tokens.length)\n\n // Compile all the patterns before compilation.\n for (var i = 0; i < tokens.length; i++) {\n if (typeof tokens[i] === 'object') {\n matches[i] = new RegExp('^' + tokens[i].pattern + '$')\n }\n }\n\n return function (obj) {\n var path = ''\n\n obj = obj || {}\n\n for (var i = 0; i < tokens.length; i++) {\n var key = tokens[i]\n\n if (typeof key === 'string') {\n path += key\n\n continue\n }\n\n var value = obj[key.name]\n\n if (value == null) {\n if (key.optional) {\n continue\n } else {\n throw new TypeError('Expected \"' + key.name + '\" to be defined')\n }\n }\n\n if (isarray(value)) {\n if (!key.repeat) {\n throw new TypeError('Expected \"' + key.name + '\" to not repeat')\n }\n\n if (value.length === 0) {\n if (key.optional) {\n continue\n } else {\n throw new TypeError('Expected \"' + key.name + '\" to not be empty')\n }\n }\n\n for (var j = 0; j < value.length; j++) {\n if (!matches[i].test(value[j])) {\n throw new TypeError('Expected all \"' + key.name + '\" to match \"' + key.pattern + '\"')\n }\n\n path += (j === 0 ? key.prefix : key.delimiter) + encodeURIComponent(value[j])\n }\n\n continue\n }\n\n if (!matches[i].test(value)) {\n throw new TypeError('Expected \"' + key.name + '\" to match \"' + key.pattern + '\"')\n }\n\n path += key.prefix + encodeURIComponent(value)\n }\n\n return path\n }\n}\n\n/**\n * Escape a regular expression string.\n *\n * @param {String} str\n * @return {String}\n */\nfunction escapeString (str) {\n return str.replace(/([.+*?=^!:${}()[\\]|\\/])/g, '\\\\$1')\n}\n\n/**\n * Escape the capturing group by escaping special characters and meaning.\n *\n * @param {String} group\n * @return {String}\n */\nfunction escapeGroup (group) {\n return group.replace(/([=!:$\\/()])/g, '\\\\$1')\n}\n\n/**\n * Attach the keys as a property of the regexp.\n *\n * @param {RegExp} re\n * @param {Array} keys\n * @return {RegExp}\n */\nfunction attachKeys (re, keys) {\n re.keys = keys\n return re\n}\n\n/**\n * Get the flags for a regexp from the options.\n *\n * @param {Object} options\n * @return {String}\n */\nfunction flags (options) {\n return options.sensitive ? '' : 'i'\n}\n\n/**\n * Pull out keys from a regexp.\n *\n * @param {RegExp} path\n * @param {Array} keys\n * @return {RegExp}\n */\nfunction regexpToRegexp (path, keys) {\n // Use a negative lookahead to match only capturing groups.\n var groups = path.source.match(/\\((?!\\?)/g)\n\n if (groups) {\n for (var i = 0; i < groups.length; i++) {\n keys.push({\n name: i,\n prefix: null,\n delimiter: null,\n optional: false,\n repeat: false,\n pattern: null\n })\n }\n }\n\n return attachKeys(path, keys)\n}\n\n/**\n * Transform an array into a regexp.\n *\n * @param {Array} path\n * @param {Array} keys\n * @param {Object} options\n * @return {RegExp}\n */\nfunction arrayToRegexp (path, keys, options) {\n var parts = []\n\n for (var i = 0; i < path.length; i++) {\n parts.push(pathToRegexp(path[i], keys, options).source)\n }\n\n var regexp = new RegExp('(?:' + parts.join('|') + ')', flags(options))\n\n return attachKeys(regexp, keys)\n}\n\n/**\n * Create a path regexp from string input.\n *\n * @param {String} path\n * @param {Array} keys\n * @param {Object} options\n * @return {RegExp}\n */\nfunction stringToRegexp (path, keys, options) {\n var tokens = parse(path)\n var re = tokensToRegExp(tokens, options)\n\n // Attach keys back to the regexp.\n for (var i = 0; i < tokens.length; i++) {\n if (typeof tokens[i] !== 'string') {\n keys.push(tokens[i])\n }\n }\n\n return attachKeys(re, keys)\n}\n\n/**\n * Expose a function for taking tokens and returning a RegExp.\n *\n * @param {Array} tokens\n * @param {Array} keys\n * @param {Object} options\n * @return {RegExp}\n */\nfunction tokensToRegExp (tokens, options) {\n options = options || {}\n\n var strict = options.strict\n var end = options.end !== false\n var route = ''\n var lastToken = tokens[tokens.length - 1]\n var endsWithSlash = typeof lastToken === 'string' && /\\/$/.test(lastToken)\n\n // Iterate over the tokens and create our regexp string.\n for (var i = 0; i < tokens.length; i++) {\n var token = tokens[i]\n\n if (typeof token === 'string') {\n route += escapeString(token)\n } else {\n var prefix = escapeString(token.prefix)\n var capture = token.pattern\n\n if (token.repeat) {\n capture += '(?:' + prefix + capture + ')*'\n }\n\n if (token.optional) {\n if (prefix) {\n capture = '(?:' + prefix + '(' + capture + '))?'\n } else {\n capture = '(' + capture + ')?'\n }\n } else {\n capture = prefix + '(' + capture + ')'\n }\n\n route += capture\n }\n }\n\n // In non-strict mode we allow a slash at the end of match. If the path to\n // match already ends with a slash, we remove it for consistency. The slash\n // is valid at the end of a path match, not in the middle. This is important\n // in non-ending mode, where \"/test/\" shouldn't match \"/test//route\".\n if (!strict) {\n route = (endsWithSlash ? route.slice(0, -2) : route) + '(?:\\\\/(?=$))?'\n }\n\n if (end) {\n route += '$'\n } else {\n // In non-ending mode, we need the capturing groups to match as much as\n // possible by using a positive lookahead to the end or next path segment.\n route += strict && endsWithSlash ? '' : '(?=\\\\/|$)'\n }\n\n return new RegExp('^' + route, flags(options))\n}\n\n/**\n * Normalize the given path string, returning a regular expression.\n *\n * An empty array can be passed in for the keys, which will hold the\n * placeholder key descriptions. For example, using `/user/:id`, `keys` will\n * contain `[{ name: 'id', delimiter: '/', optional: false, repeat: false }]`.\n *\n * @param {(String|RegExp|Array)} path\n * @param {Array} [keys]\n * @param {Object} [options]\n * @return {RegExp}\n */\nfunction pathToRegexp (path, keys, options) {\n keys = keys || []\n\n if (!isarray(keys)) {\n options = keys\n keys = []\n } else if (!options) {\n options = {}\n }\n\n if (path instanceof RegExp) {\n return regexpToRegexp(path, keys, options)\n }\n\n if (isarray(path)) {\n return arrayToRegexp(path, keys, options)\n }\n\n return stringToRegexp(path, keys, options)\n}\n","module.exports = Array.isArray || function (arr) {\n return Object.prototype.toString.call(arr) == '[object Array]';\n};\n"]} \ No newline at end of file diff --git a/tests/fixtures/a b/tests/fixtures/a new file mode 100644 index 0000000..2e65efe --- /dev/null +++ b/tests/fixtures/a @@ -0,0 +1 @@ +a \ No newline at end of file diff --git a/tests/fixtures/b b/tests/fixtures/b new file mode 100644 index 0000000..63d8dbd --- /dev/null +++ b/tests/fixtures/b @@ -0,0 +1 @@ +b \ No newline at end of file diff --git a/tests/fixtures/c b/tests/fixtures/c new file mode 100644 index 0000000..3410062 --- /dev/null +++ b/tests/fixtures/c @@ -0,0 +1 @@ +c \ No newline at end of file diff --git a/tests/fixtures/d b/tests/fixtures/d new file mode 100644 index 0000000..c59d9b6 --- /dev/null +++ b/tests/fixtures/d @@ -0,0 +1 @@ +d \ No newline at end of file diff --git a/tests/fixtures/e b/tests/fixtures/e new file mode 100644 index 0000000..9cbe6ea --- /dev/null +++ b/tests/fixtures/e @@ -0,0 +1 @@ +e \ No newline at end of file diff --git a/tests/fixtures/f b/tests/fixtures/f new file mode 100644 index 0000000..4d1ae35 --- /dev/null +++ b/tests/fixtures/f @@ -0,0 +1 @@ +f \ No newline at end of file diff --git a/tests/fixtures/g b/tests/fixtures/g new file mode 100644 index 0000000..7937c68 --- /dev/null +++ b/tests/fixtures/g @@ -0,0 +1 @@ +g \ No newline at end of file diff --git a/tests/fixtures/h b/tests/fixtures/h new file mode 100644 index 0000000..be54354 --- /dev/null +++ b/tests/fixtures/h @@ -0,0 +1 @@ +h \ No newline at end of file diff --git a/tests/fixtures/i b/tests/fixtures/i new file mode 100644 index 0000000..597a6db --- /dev/null +++ b/tests/fixtures/i @@ -0,0 +1 @@ +i \ No newline at end of file diff --git a/tests/fixtures/j b/tests/fixtures/j new file mode 100644 index 0000000..0fe2fa5 --- /dev/null +++ b/tests/fixtures/j @@ -0,0 +1 @@ +j \ No newline at end of file diff --git a/tests/fixtures/k b/tests/fixtures/k new file mode 100644 index 0000000..23fa7d3 --- /dev/null +++ b/tests/fixtures/k @@ -0,0 +1 @@ +k \ No newline at end of file diff --git a/tests/fixtures/l b/tests/fixtures/l new file mode 100644 index 0000000..baf72b1 --- /dev/null +++ b/tests/fixtures/l @@ -0,0 +1 @@ +l \ No newline at end of file diff --git a/tests/fixtures/m b/tests/fixtures/m new file mode 100644 index 0000000..08b9811 --- /dev/null +++ b/tests/fixtures/m @@ -0,0 +1 @@ +m \ No newline at end of file diff --git a/tests/fixtures/n b/tests/fixtures/n new file mode 100644 index 0000000..ef073cc --- /dev/null +++ b/tests/fixtures/n @@ -0,0 +1 @@ +n \ No newline at end of file diff --git a/tests/service-worker.js b/tests/service-worker.js index ad2dd08..f0853e6 100644 --- a/tests/service-worker.js +++ b/tests/service-worker.js @@ -70,3 +70,15 @@ toolbox.router.post('cache/:name', function(request) { toolbox.router.delete('cache/:name', function(request) { return toolbox.uncache(request.url).then(respondOK, respondError); }); + +toolbox.router.get('fixtures/:foo', toolbox.cacheOnly) +// Single item +toolbox.precache('fixtures/a'); +// Array of items +toolbox.precache(['fixtures/b', 'fixtures/c']); +// Array of Promises +toolbox.precache([Promise.resolve('fixtures/d'), Promise.resolve('fixtures/e')]); +// Array of Arrays +toolbox.precache(['fixtures/f', ['fixtures/g', 'fixtures/h'], ['fixtures/i', 'fixtures/j']]); +// Array of Promises for Arrays +toolbox.precache([Promise.resolve(['fixtures/k', 'fixtures/l']), Promise.resolve(['fixtures/m', 'fixtures/n'])]); diff --git a/tests/tests.js b/tests/tests.js index ef67c31..8909815 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -87,6 +87,23 @@ navigator.serviceWorker.ready.then(function() { // Catch-all error handler assert.ok(false, 'Failed: ' + reason); }).then(done);; - }) + }); + }); + + QUnit.test('Precaching', function(assert) { + checkValue('fixtures/a', 'a', assert); + checkValue('fixtures/b', 'b', assert); + checkValue('fixtures/c', 'c', assert); + checkValue('fixtures/d', 'd', assert); + checkValue('fixtures/e', 'e', assert); + checkValue('fixtures/f', 'f', assert); + checkValue('fixtures/g', 'g', assert); + checkValue('fixtures/h', 'h', assert); + checkValue('fixtures/i', 'i', assert); + checkValue('fixtures/j', 'j', assert); + checkValue('fixtures/k', 'k', assert); + checkValue('fixtures/l', 'l', assert); + checkValue('fixtures/m', 'm', assert); + checkValue('fixtures/n', 'n', assert); }); });