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

Breaks tests #235

Closed
jacobq opened this issue Nov 10, 2018 · 5 comments
Closed

Breaks tests #235

jacobq opened this issue Nov 10, 2018 · 5 comments

Comments

@jacobq
Copy link
Contributor

jacobq commented Nov 10, 2018

Ref #200 #217, #23, #24

I just switched from ember-localstorage-adapter and suddenly lots of tests that were passing now blow up during their tear-down with errors like:

Error: Assertion Failed: You can only unload a record which is not inFlight.

Does this addon not support use in testing? Is there a way to easily band-aid this? (e.g. have all the tests run a hook that does something magic?)

@jacobq
Copy link
Contributor Author

jacobq commented Nov 12, 2018

Also #188

I was able to get past this first problem by installing pouchdb-adapter-memory and using it for the test environment:

// config/environment.js
    // ...
    if (environment === 'test') {
        ENV.emberPouch.options = {
            adapter: 'memory'
        };
        // ...
    }
    // ...
// app/adapters/application.js
import { Adapter } from 'ember-pouch';
import PouchDB from 'pouchdb';
import pouchInMemoryPlugin from 'pouchdb-adapter-memory'; // Note: using ember-auto-import to get this from npm
import config from 'my-app/config/environment';
import { isEmpty } from '@ember/utils';
import { assert } from '@ember/debug';

function createDb() {
  const localDb = config.emberPouch.localDb;

  assert('emberPouch.localDb must be set', !isEmpty(localDb));

  if (config.emberPouch.options && config.emberPouch.options.adapter === "memory") {
      PouchDB.plugin(pouchInMemoryPlugin);
  }
  const db = new PouchDB(localDb, config.emberPouch.options);

  if (config.emberPouch.remoteDb) {
    let remoteDb = new PouchDB(config.emberPouch.remoteDb);

    db.sync(remoteDb, {
      live: true,
      retry: true
    });
  }

  return db;
}

export default Adapter.extend({
  init() {
    this._super(...arguments);
    this.set('db', createDb());
  }
});

However, I now see another problem. Some tests (not the same ones with the previously mentioned problem either) now show this error after they run:

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

@backspace
Copy link
Collaborator

This inFlight problem has been happening to me too; I’m also finding that a test I have where it saves a model and tries to click a link on the post-save-forwarded index page is failing because it’s unable to find the link. My theory is that the acceptance test is terminating before the route transition, maybe because the promise being returned from Relational Pouch is non-Ember? But I tried wrapping in an RSVP promise to no avail, so my theory isn’t too promising 😐

@jacobq
Copy link
Contributor Author

jacobq commented May 22, 2019

@backspace I was able to reproduce the problem by manually using the dev tools console, so there must be more to it than just test waiters/synchronization.

@backspace
Copy link
Collaborator

ah, okay. I was able to use the waiter technique discussed in this thread to get rid of the inFlight error but the test still fails for the other reason. If I pauseTest and then manually resumeTest, the test passes 😞

@jacobq
Copy link
Contributor Author

jacobq commented Dec 9, 2019

Closing since this is mostly a duplicate of #237 #239 (once I worked around those the only problems I had were related to my own app code)

@jacobq jacobq closed this as completed Dec 9, 2019
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

2 participants