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

Error: Cannot re-register: service:store, as it has already been resolved. #80

Closed
spinlock99 opened this issue Sep 1, 2015 · 17 comments

Comments

@spinlock99
Copy link

First: sorry if this is the wrong place for this question. Just point me to the right resources if this isn't an issue with ember-cli-mocha

I'm getting the error: Error: Cannot re-register:service:store, as it has already been resolved. when I try to run this acceptance test:

# jshint expr:true
`import Ember from 'ember'`
`import startApp from '../../helpers/start-app'`

describe "Acceptance: AccountProfile", ->
  before ->
    @App = startApp()
    return

  after ->
    Ember.run(@App, "destroy")


  it "can visit /account/profile", (done) ->
    visit "/account/profile"
    andThen ->
      expect(currentPath()).to.equal "account/profile"
    done()

The error is happening in the "after all" hook so I assume that is when the @App is being destroyed. I'm at a loss here. I assume the error is EmberData trying to reregister itself but I don't know why I'm getting that when I try to destroy the app.

Any help would be greatly appreciated.

Thanks!

@rwjblue
Copy link
Member

rwjblue commented Sep 1, 2015

My guess is that it is related to emberjs/data#3690

@spinlock99
Copy link
Author

Thanks!

I've got a hacky work-around to rebuild the registry before calling destroy in the after block:

  after ->
    @App.registry = @App.buildRegistry()
    Ember.run(@App, "destroy")

That gives me the same results as the ember-data patch you linked to but I don't have to maintain a patched version of ember-data.

But, now I'm getting this error:

Acceptance: AccountProfile
can visit /account/profile ‣
"after all" hook ‣
TypeError: app.testHelpers.wait is not a function
    at visit (assets/vendor.js:53338:28)
    at assets/vendor.js:54152:19
    at isolate (assets/vendor.js:54353:13)
    at assets/vendor.js:54337:14
    at tryCatch (assets/vendor.js:67511:14)
    at Object.invokeCallback (assets/vendor.js:67526:15)
    at assets/vendor.js:69338:21
    at assets/vendor.js:43933:7
    at Queue.invoke (assets/vendor.js:11464:16)
    at Object.Queue.flush (assets/vendor.js:11528:11)

This looks like I'm probably not requiring in a necessary package. Any idea what package testHelpers.wait is defined in?

@paulelliott
Copy link

I'm seeing this exact same thing on a project, fwiw. Also at a loss.

@rwjblue
Copy link
Member

rwjblue commented Sep 2, 2015

@paulelliott - See emberjs/data#3690 for an upstream fix, and emberjs/ember.js#10310 (comment) for a work around you can use in your apps for now.

App.initializer({
  name: 'clear-service-store',
  before: ['ember-data'],
  initialize(registry) {
    registry.unregister('service:store');
  }
});

@paulelliott
Copy link

@rwjblue That is a cleaner way to handle the title error of this issue, for sure. 👍

I am still seeing TypeError: app.testHelpers.wait is not a function just like @spinlock99 though.

@rwjblue
Copy link
Member

rwjblue commented Sep 2, 2015

@paulelliott - Are you saying that you are getting this error without the patch that @spinlock99 mentioned (clobbering this.app.registry)? If you are using that patch: I do not think that clobbering the whole registry will result in good times, so I would definitely suggest using the initializer approach that I linked above. If you are not using that patch, and you are getting this error on an out of the box setup please open a new issue so we can try to diagnose it.

@paulelliott
Copy link

I tried @spinlock99's suggestion before you posted the initializer. It worked but left me with the error about app.testHelpers.wait.

When you posted the initializer I took that hack out and used that, which yielded the same result. The initializer approach is a much better workaround and that is what I am going with.

The app.testHelpers.wait issue is likely related to ember-cli-mocha, which both @spinlock99 and I are using.

@spinlock99
Copy link
Author

@rwjblue thanks for posting that initializer. Much nicer solution until ember-data is patched. I am still getting the app.testHelpers.wait issue. Would you prefer if I closed this issue and opened a new one for that or just continue this thread?

@paulelliott What does your setup look like? Here's the debug from my app (with ember-cli-mocha @ 0.7.0)

DEBUG: -------------------------------
DEBUG: Ember      : 1.13.9
DEBUG: Ember Data : 1.13.11
DEBUG: jQuery     : 1.11.3
DEBUG: -------------------------------

@paulelliott
Copy link

I'm using ember-cli-mocha 0.9.2 with ember-mocha 0.8.0 and:

DEBUG: -------------------------------
DEBUG: Ember      : 1.13.7
DEBUG: Ember Data : 1.13.8
DEBUG: jQuery     : 1.11.3
DEBUG: -------------------------------

@rwjblue
Copy link
Member

rwjblue commented Sep 2, 2015

Can someone make a repro to demo this? I just made http://emberjs.jsbin.com/genolo/edit?html,js that you can use as a base.

@spinlock99
Copy link
Author

This is very odd. I can't recreate the error using @rwjblue 's jsbin. So, I tried creating a fresh app with ember-cli to see if I could recreate the error there: nope. Then, I compared my package.json and bower.json to the new, clean, ember-cli app and make sure all the packages were in parity.

This is where is gets interesting: I did not get the service:store error with the fresh ember-cli app but I do still get it with my app. This makes me suspect that the testHelpers.wait has the same root cause as the service:store issue.

@NullVoxPopuli
Copy link

I'm getting this error with ember 2.5

image

@spinlock99
Copy link
Author

@NullVoxPopuli can you post an example using the jsbin or a fresh github repo?

I suspect we haven't closed this issue yet because no one has been able to show an example yet.

Thanks!

@NullVoxPopuli
Copy link

NullVoxPopuli commented May 18, 2016

Here is a repo: https://github.com/NullVoxPopuli/aeonvera-ui/tree/mocha-test

This is the first error that shows up

@NullVoxPopuli
Copy link

here is a travis log, if that helps https://travis-ci.org/NullVoxPopuli/aeonvera-ui/jobs/131395768
(first error)

@NullVoxPopuli
Copy link

Ok, I added the registry hack:

  afterEach(() => {
    // tear down
    application.registry.unregister('session:main');
    application.registry.unregister('session-store:test');

    destroyApp(application);
    server.shutdown();
  });

but, now I'm also getting the

TypeError: app.testHelpers.wait is not a function

problem.

:-(

Does this mean that the test helpers aren't being loaded properly?

I think there is something funky with acceptance testing and mocha right now. :-\

Any ideas?

@Turbo87
Copy link
Member

Turbo87 commented Jul 3, 2017

emberjs/data#3690 seems to have fixed the original issue. if there are still issues in this area please open a new issue.

@Turbo87 Turbo87 closed this as completed Jul 3, 2017
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

5 participants