genkgo / ember-localforage-adapter

Offline usage for Ember Data, based on localstorage adapter, but now uses Mozilla's localforage as data source
Other
133 stars 26 forks source link

Disabling cache in testing or clearing the cache between tests? #77

Closed NullVoxPopuli closed 5 years ago

NullVoxPopuli commented 5 years ago

I ran in to an issue between tests when I upgraded today (to beta.4), where having the cache no by default (previous version I was using didn't have cache), records were mistakenly being kept between tests.

I have this at the moment

import localforage from 'localforage';

async function cleanEverything() {
  // specifically, offline storage
  await localforage.clear();
  await localStorage.clear();
}

export function clearLocalStorage(hooks: NestedHooks) {
  hooks.beforeEach(async function() {
    await cleanEverything();
  });

  hooks.afterEach(async function() {
    await cleanEverything();
  });
}

with

export default LFAdapter.extend({
  namespace: 'emberclear',
  caching: 'none',
  // ...

and that gets all my tests passing! :tada:

but for having cache, (cause I assume this would make overall app usage slightly quicker?), I need a way to clear the cache between tests such that the same behavior as my cleanEverything function will still work -- is there a way to do this? (or is this a coming feature?)

frederikbosch commented 5 years ago

The way I did it yesterday.

  1. call setupTest(hooks).
  2. in each test, lookup the adapter in the container.
  3. in each test, clear the cache.

Maybe wrap in a function.