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

Can't resolve components for integration tests #113

Closed
caseklim opened this issue May 13, 2016 · 5 comments
Closed

Can't resolve components for integration tests #113

caseklim opened this issue May 13, 2016 · 5 comments

Comments

@caseklim
Copy link
Contributor

When I run ember g component foo-component, it generates a file within the addon and app directories. When I try to run the generated test, it fails, saying it can't find the module. When I delete the component from the app directory (since it's my understanding an engine shouldn't have an app directory in the first place), the test interprets the component as a helper and says it can't be found.

I've only encountered this issue with components so far, not sure if the same thing happens with routes, models, etc.

Are there issues with tests at this point, or is there something I'm missing? Thank you!

[npm 05/13/16 2:49:44] not ok 40 PhantomJS 2.0 - Integration | Component | foo component: it renders
[npm 05/13/16 2:49:44]     ---
[npm 05/13/16 2:49:44]         actual: >
[npm 05/13/16 2:49:44]             null
[npm 05/13/16 2:49:44]         stack: >
[npm 05/13/16 2:49:44]              at missingModule (http://localhost:7357/assets/vendor.js:180:93)
[npm 05/13/16 2:49:44]              at findModule (http://localhost:7357/assets/vendor.js:194:30)
[npm 05/13/16 2:49:44]              at reify (http://localhost:7357/assets/vendor.js:124:32)
[npm 05/13/16 2:49:44]              at build (http://localhost:7357/assets/vendor.js:144:15)
                                    ...
[npm 05/13/16 2:49:44]         message: >
[npm 05/13/16 2:49:44]             Died on test #1  at testWrapper (http://localhost:7357/assets/test-support.js:6645:16)
[npm 05/13/16 2:49:44]              at test (http://localhost:7357/assets/test-support.js:6658:44)
[npm 05/13/16 2:49:44]              at http://localhost:7357/assets/tests.js:111:24
[npm 05/13/16 2:49:44]              at exports (http://localhost:7357/assets/vendor.js:93:39)
[npm 05/13/16 2:49:44]              at build (http://localhost:7357/assets/vendor.js:145:17)
[npm 05/13/16 2:49:44]              at findModule (http://localhost:7357/assets/vendor.js:196:14)
[npm 05/13/16 2:49:44]              at requireModule (http://localhost:7357/assets/vendor.js:184:22)
[npm 05/13/16 2:49:44]              at require (http://localhost:7357/assets/test-loader.js:67:16)
[npm 05/13/16 2:49:44]              at loadModules (http://localhost:7357/assets/test-loader.js:58:25)
[npm 05/13/16 2:49:44]              at load (http://localhost:7357/assets/test-loader.js:89:35)
[npm 05/13/16 2:49:44]              at http://localhost:7357/assets/test-support.js:6477:20: Could not find module `testmanager-engine/components/foo-component` imported from `dummy/components/foo-component`
[npm 05/13/16 2:57:23] not ok 40 PhantomJS 2.0 - Integration | Component | foo component: it renders
[npm 05/13/16 2:57:23]     ---
[npm 05/13/16 2:57:23]         actual: >
[npm 05/13/16 2:57:23]             null
[npm 05/13/16 2:57:23]         stack: >
[npm 05/13/16 2:57:23]             http://localhost:7357/assets/vendor.js:16524
[npm 05/13/16 2:57:23]         message: >
[npm 05/13/16 2:57:23]             Died on test #2  at testWrapper (http://localhost:7357/assets/test-support.js:6645:16)
[npm 05/13/16 2:57:23]              at test (http://localhost:7357/assets/test-support.js:6658:44)
[npm 05/13/16 2:57:23]              at http://localhost:7357/assets/tests.js:111:24
[npm 05/13/16 2:57:23]              at exports (http://localhost:7357/assets/vendor.js:93:39)
[npm 05/13/16 2:57:23]              at build (http://localhost:7357/assets/vendor.js:145:17)
[npm 05/13/16 2:57:23]              at findModule (http://localhost:7357/assets/vendor.js:196:14)
[npm 05/13/16 2:57:23]              at requireModule (http://localhost:7357/assets/vendor.js:184:22)
[npm 05/13/16 2:57:23]              at require (http://localhost:7357/assets/test-loader.js:67:16)
[npm 05/13/16 2:57:23]              at loadModules (http://localhost:7357/assets/test-loader.js:58:25)
[npm 05/13/16 2:57:23]              at load (http://localhost:7357/assets/test-loader.js:89:35)
[npm 05/13/16 2:57:23]              at http://localhost:7357/assets/test-support.js:6477:20: Assertion Failed: A helper named 'foo-component' could not be found

@Kaceykaso

@trentmwillis
Copy link
Member

Sounds like an issue with how the test's Resolver is set up. In tests/test-helper.js you should see a call to setResolver, this sets the Resolver instance that is used by Integration/Unit tests, by default it pulls in a resolver from tests/helpers/resolver.js that looks something like:

import Resolver from '../../resolver';
import config from '../../config/environment';

const resolver = Resolver.create();

resolver.namespace = {
  modulePrefix: config.modulePrefix,
  podModulePrefix: config.podModulePrefix
};

export default resolver;

You'll want to make sure the Resolver class it is importing is extended from ember-engines/resolver (or, more ideally, is the same Resolver used by your Engine). Additionally, you'll probably need to update modulePrefix to be the same as whatever your Engine's modulePrefix is (looks like testmanager-engine) otherwise it'll likely be the dummy namespace (assuming this is an Addon).

So in other words, make sure the Resolver is looking in the proper namespace for your component.

Bonus tip: the reason you see A helper named 'foo-component' could not be found. is that during rendering of templates, Ember first attempts to resolve Handlebars constructs as Components and then Helpers. So, if a Component is not found (as in this case) it tries to resolve it as a Helper, but if no Helper is found it'll throw the error you are seeing.

@caseklim
Copy link
Contributor Author

For anyone else encountering this issue:

  1. tests/dummy/app/resolver.js should be extended from ember-engines/resolver
  2. modulePrefix in tests/helpers/resolver.js should be set to the same modulePrefix as your engine

We haven't thought of a way to avoid hard-coding modulePrefix inside of tests/helpers/resolver.js, but the above steps resolve this issue at least

@Kaceykaso

@dgeb
Copy link
Member

dgeb commented Jun 10, 2016

Thanks for the update @cklimkowsky

We haven't thought of a way to avoid hard-coding modulePrefix inside of tests/helpers/resolver.js, but the above steps resolve this issue at least

As of ember-engines v0.2.5 (from the v0.2 branch), you should be able to import the same config/environment into both your addon/engine.js and your tests/helpers/resolver.js, and then access its value as config.modulePrefix. In other words, you should no longer need to hard-code modulePrefix in multiple places. Note: if you're using Ember Canary, you can also have this same benefit by using the ember-engines clean branch, which is soon to merge with master.

@Kaceykaso
Copy link

@dgeb we can import it everywhere without issues EXCEPT in tests/helpers/resolver.js; that is still throwing errors on the vanilla unit test Ember generates with a route:
Promise rejected before it exists: Attempting to register an unknown factory: 'route:plans/new'

We are using Ember 2.7.0-canary :-/

@pfmmfp
Copy link

pfmmfp commented Jun 29, 2017

How would this be fixed with ember@2.12 and ember-engines@0.5.4? It seems that the problem is still present and ember-engines/resolver has been removed. Which deprecates the fix proposed above.

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