Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty store after tests #217

Open
0000marcell opened this issue Mar 2, 2018 · 4 comments
Open

Empty store after tests #217

0000marcell opened this issue Mar 2, 2018 · 4 comments

Comments

@0000marcell
Copy link

How can i empty the stores after performing a test, I'm getting some async errors like this

pushedData` on <post:F8489E9E-4FD4-FA5A-8BDB-10381B0400B5> while in state root.deleted.inFlight

I'm deleting the models like this

for(let post of posts){
   await run(async ()=> {
      await post.destroyRecord();
   });
}
@Matt-Jensen
Copy link

The stack traces on these errors are incredibly frustrating; in my case I believe the issue was an unhandled rejection in a promise chain saving a pouch record.

Almost all rejections related to ember-pouch, in my limited experience, are 409 conflicts.

Can you add a catch to your destroyRecord requests and see if the error is status 409?

@0000marcell
Copy link
Author

Hi @Matt-Jensen, i've tried that but the catch never runs, i've tried everything that i could think of, even creating a new db for each test, the worse part is that sometimes the tests run fine and sometimes the error occurs 😩, i don't even know how to reproduce it reliably, the records are always deleted so the code works anyway

@jlami
Copy link
Collaborator

jlami commented Jul 6, 2018

Can you try with the new ember-pouch version 5.1.0? This one has some new behavior for deletes.

Otherwise I think the best way is to use a memory adapter for tests. If you then make sure that each test will create a separate app you should be set.

To be able to use the memory adapter you'll have to load the file, as it is not added by default. If you are not using ember-auto-import you can use ember-cli-build.js to add the file to the vendorTree and import it.

...

module.exports = function(defaults) {
  var app = new EmberApp(defaults, {
    trees: {
      vendor: stew.find(path.join(path.dirname(require.resolve('pouchdb')), '..', 'dist'), {
          destDir: 'pouchdb',
          files: ['pouchdb.memory.js']
        })
    },
    ...
  });

  ...

  app.import('vendor/pouchdb/pouchdb.memory.js', { type: 'test' });
  return app.toTree([]);
};

Then setup your PouchDB instance in the adapter with an extra parameter: new Pouch('dbname', {adapter: 'memory'}). Best is to setup some localDBOptions in your environment and set that to that value for the test environment.

@jacobq jacobq mentioned this issue Nov 10, 2018
@jacobq
Copy link
Contributor

jacobq commented Nov 12, 2018

@jlami I am trying to work around this problem too (using ember-pouch v6.0.0). I installed pouchdb-adapter-memory via npm and am using ember-auto-import so was able to do:

// app/adapters/application.ts
import PouchDB from 'pouchdb'; // Note: this is actually provided by ember-pouch
import pouchInMemoryPlugin from 'pouchdb-adapter-memory';
// ...
  if (config.emberPouch.options && config.emberPouch.options.adapter === "memory") {
      PouchDB.plugin(pouchInMemoryPlugin);
  }
  const db = new PouchDB(localDb, config.emberPouch.options);
// ...

Although switching to the in-memory DB seems to have made the first error disappear

Error: Attempted to handle event deleteRecord on <...> while in state root.loaded.updated.inFlight.

it has created a new one that is popping up all over the place now:

Error: Attempted to handle event becameError on <...> while in state root.loaded.saved.

How do I "make sure that each test will create a separate app"? (Perhaps that is why this is happening?) I am using ember-cli 3.5.0 and the qunit testing convention that it ships with by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants