mikkopaderes / ember-cloud-firestore-adapter

Unofficial Ember Data Adapter and Serializer for Cloud Firestore
MIT License
69 stars 17 forks source link

Failing tests somehow related to `CloudFirestoreModularAdapter.isFastBoot` #230

Closed roomman closed 2 years ago

roomman commented 2 years ago

Hi, I'm refactoring a project to use the latest version of this addon. My test suite is failing when the isFastBoot getter in the adapter is called, though I can't work out why.

Here is an example of a test that fails, when run in isolation:

import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { render, settled } from '@ember/test-helpers';
import { hbs } from 'ember-cli-htmlbars';

import { signInWithEmailAndPassword } from 'ember-cloud-firestore-adapter/firebase/auth';

module('Integration | Component | video-list', function (hooks) {
  setupRenderingTest(hooks);

  hooks.beforeEach(async function () {
    const session = this.owner.lookup('service:session');
    await session.authenticate('authenticator:oneday-firebase', (auth) => {
      return signInWithEmailAndPassword(auth, 'email@email.com, '123456');
    });
    await settled();
  });

  hooks.afterEach(async function () {
    const session = this.owner.lookup('service:session');
    if (session && session.isAuthenticated) {
      await session.invalidate();
    }
    await settled();
  });

  test.only('it renders', async function (assert) {
    let store = this.owner.lookup('service:store');
    store.generateStackTracesForTrackedRequests = true;
    const videos = await store.findAll('video', {});
    this.set('videos', videos);
    await render(hbs`<VideoList @videos={{this.videos}} />`);
    assert.dom('[data-test-video-list]').exists();
  });
});

Here is the error:

index.js:135 Uncaught (in promise) Error: Can not call `.lookup` after the owner has been destroyed
    at Container.lookup (index.js:135:1)
    at Class.lookup (container_proxy.js:81:1)
    at Class.get isFastBoot [as isFastBoot] (cloud-firestore-modular.js:101:99)
    at Array.eval (cloud-firestore-modular.js:211:54)
    at next (index.esm2017.js:6943:985)
    at eval (index.esm2017.js:5400:271)

Any thoughts on why this is destroyed by the time it gets into the adapter?

mikkopaderes commented 2 years ago

Can you point out in which part of the adapter code it's failing? And maybe a snippet of VideoList template as well.

My hunch is that you may be trying to render some relationships which isn't being waited for by the tests so while it's doing those, the test gets destroyed already.

roomman commented 2 years ago

Hi @mikkopaderes and thanks for your response. I had the same instinct and went about eliminating async behaviours related to the adapter. After a painful few days it turns out it has nothing to do with this addon, and everything to do with Embroider's code splitting option. With code splitting on, my tests are unable to lookup routes and controllers that are being split. Sorry for the distraction.