Skip to content

Instantly share code, notes, and snippets.

@begedin
Created July 6, 2015 10:22
Show Gist options
  • Save begedin/d7b1568c6dd9e65e64ad to your computer and use it in GitHub Desktop.
Save begedin/d7b1568c6dd9e65e64ad to your computer and use it in GitHub Desktop.
Testing micro-addons

What we have right now

We have a simple, flat file structure with the scripts that need testing named component.js, library.js and helper.js depending on the type of micro-addon. A micro-component additionally has a style.css and a template.hbs, but those are not really tested directly, and would only be tested indirectly, via component.js.

What happens with those files right now is that, when the addon is being consumed in a parent app, there are hooks in the addon's index.js script which cause the files during build time, to get renamed and copied to their proper, ember addon defined locations within the app\ folder of the parent app.

What we would want

I think ideally, we would want a tests.js file within the existing flat file structure. Depending on the type of micro-addon, this file would contain a unit test module either for a component, or a general unit test in case of a library and/or helper.

There would again be hooks in index.js which would cause the tests.js file to also be moved and renamed to their proper location during build time. In this case, it would not happen (but technically could) during build time of the parent app. Instead, it would happen during build time which occurs when the ember test command is being executed from within the micro-addon folder.

Depending on the type of micro addon, tests.js would be renamed and moved to tests\unit\addon-type\addon-name-test.js.

What Ember-CLI provides

The way an ember-addon is usually tested is via a dummy app.

In a proper ember addon folder, we have a test folder just like we would in an ember-CLI app. The difference is, there is a dummy app structure within that folder. The intetion is to use the dummy app to consume the addon and test it that way.

Since our micro-addon has a flat file structure, it's an issue to create this test folder.

There are also addon hooks in place, which we can use to move, rename and copy addon files around during the application build process. We're already using these hooks to transform the flat file structure into a proper addon structure during parent app runtime. This is how we made micro-addons work out of the box form within an ember application, instead of having to convert them to a proper ember-addon first.

However, there are no hooks which would allow us to do this for tests. The following hooks are available:

hook folder it merges into
treeForApp app\
treeForStyles app\styles
treeForTemplates app\templates
treeForAddon addon\
treeForAddonTemplates addon\templates
treeForVendor vendor\
treeForTestSupport test-support\
treeForPublic public\

There is also a treeForAddonStyles, but there seems to be no exposed hook for it.

In any case, none of these hooks allows us to copy something into the test\ folder. The closest is treeForTestSupport but it doesn't help us in any way.

There are more basic hooks, such as treeFor, preBuild, etc., which would likely make the process we need a possibility.

However, even if we did all that, and it should be possible even without the specific hooks, we are still missing the dummy app, which is something the user needs to create depending on the purpose of their addon and is not something that's identicall across all addons.

Due to that, I think looking into this further isn't worth the time investment at the moment. If Ember ends up supporting the concept of micro-addons, it would be more easily enabled from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment