dwyl / learn-offline-first

:floppy_disk: You won't always have access to the internet ... Learn how to build web apps that can be used offline!
GNU General Public License v2.0
10 stars 1 forks source link

Testing appcache #17

Open finnhodgkin opened 7 years ago

finnhodgkin commented 7 years ago

While writing the rest of our tests (:100:) we commented out the sections of the code relating to appcache because as far as we know JSDOM doesn't have access:

// Store application cache as a handy short variable
var appCache = window.applicationCache;
// Only run if the appCache isn't busy
if (appCache.status === appCache.IDLE) {
  // Force check for an update
  appCache.update();
}
// Check for an available cache update
if (appCache.status === appCache.UPDATEREADY) {
  // Save the new content to the cache
  appCache.swapCache();
}
// Listen for updates
appCache.addEventListener('updateready', function(e) {
  // Reload the page when the cache is updated
  window.location.reload();
});

We have two reasonable choices for the direction we go with testing this:

  1. We fake the applicationCache status, mock the function calls and updateready event in our tests.
  2. We add a headless browser like phantomjs to our test suite so we can check the application cache related code is actually working.
finnhodgkin commented 7 years ago

For the moment we're going with option number 1.

Option number 2 definitely makes more sense in the long run, but I'm not sure how or what we would test even with a headless browser. Currently our tests basically just check that if works... :flushed: :1st_place_medal: