7
votes

I have an ember-cli project with some addons created with ember generate in-repo-addon foo

When I run ember serve, ember-cli serves up my addon assets by combining /app and /lib/foo/app into /dist/assets/app.js.

I expected something similar to happen with tests. When I run ember test or browse to http://localhost:4200/tests, I only see generated JSHint tests for the main app. Anything I create in /lib/foo/tests is ignored.

Where do I create tests for the addon, and how do I run them?

2
This Ember CLI RFC is interesting, regarding that matter: github.com/ember-cli/rfcs/pull/60 - MonsieurDart

2 Answers

6
votes

There is a feature of Ember-CLI that isn't well documented (good luck finding it) that I used for our in-repo-addon which involves adding a 'test-support' folder to your addon.

In your case you could do something like this in your addon

foo
|-- test-support
    |-- helpers
    |   |-- common-helper.js
    |   |-- anther-common-helper.js
    |-- unit
        |-- models
            |-- user-test.js

I'm using something very similar with no issues at all. This has save a bunch of time for us, hope this helps

1
votes

If you use the ember generator to create your tests in the addon you'll see where the files get created - it's the same file-structure as in a regular ember-cli project:

my-addon
|-- tests
    |-- integration
        |-- my-integration-test

You also run the tests for the addon the same way you would for a regular ember-cli project using ember test or starting an ember server within your addon's root directory and navigating to http://localhost:4200/tests.

The addon creates a dummy app to host your addon for tests. You can find out more on the official Ember-cli documentation: http://www.ember-cli.com/extending/#testing-the-addon-with-qunit