Component-test blueprint creates files under app?

I have an ember-cli addon which includes a few components. When I execute ember generate component-test foo, I get two files:

  • tests/unit/components/foo-test.js
  • app/component-tests/foo.js

The contents of the file under app are simply:

export { default } from 'my-addon/component-tests/foo';

What’s the point of the file under app? I don’t get why I would ever need or want this file. Removing this file doesn’t seem to impact the running of my tests, plus it seems like it’s not something I’d want to publish as part of the addon package.

What am I missing?

The addon/ namespace is for your addon’s code. Because the app/ namespace of addons is directly integrated into the app, and those files simply re-export your addon code, that’s what gives your consuming application access to your addon code. So you want to keep them!

Your tests pass because they reference the addon/ code directly.

So, a couple of things:

  1. What I don’t understand is the file which it’s exporting (my-addon/component-tests/foo) doesn’t exist. So what’s the point of exporting it?
  2. Why would I want to export my unit tests? A consuming application shouldn’t care about them because it’s essentially third party code (just like ember itself) from the application’s perspective.
  3. I think my tests run because they’re under tests/unit and ember-cli loads all tests under there. They pass because they use moduleForComponent in conjunction with the test resolver.

I’m still unclear as to why this blueprint behaves in this fashion and why I need those files under app.

To be honest, I think I totally misunderstood your initial post. If the generator is trying to export a file that doesn’t exist, that seems like a bug. I personally don’t use that generator, but instead let the test be generated by the component generator itself.

Compare the output – specifically of the directories:

user@box:~/code/apps/ember-addon-simple(master+)$ ember g component foo-bar
version: 0.2.5
installing
  create addon/components/foo-bar.js
  create addon/templates/components/foo-bar.hbs
installing
  create tests/unit/components/foo-bar-test.js
installing
  create app/components/foo-bar.js

The generated folder in your case doesn’t make any sense either. I think your expected output would just be a test file, correct?

Exactly. I’m at a loss as to why the second file is even showing up. Perhaps this is not the situation for which that blueprint was designed? (Although, it seems to be exactly the situation based on the name of the blueprint?)

I think I’m going to delete those files.