Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ember-cli run tests from in-repo addons

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?

like image 943
dwickern Avatar asked Jul 15 '15 20:07

dwickern


People also ask

How do I run a test in Ember?

First, you can run the test suite by entering the command ember test , or ember t , in your terminal. This will run the suite just once. Suppose, instead, you want the suite to run after every file change. You can enter ember test --server , or ember t -s .

What is addons in Ember?

We call such packages "addons." Ember developers are also free to use regular npm packages in their apps. Addons can include JavaScript code, reusable UI components, compiling tools, data visualization tools, deployment pipelines, templates, stylesheets, and more. Think of addons as node libraries with superpowers.

How do I pause ember test?

Visit http://localhost:4200/tests in your browser. When the execution of the test come upon await pauseTest() , the test will be paused, allowing you to inspect the state of your application. You can now type resumeTest() in the console of your browser to continue the test execution.


2 Answers

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

like image 131
tomoguisuru Avatar answered Sep 19 '22 10:09

tomoguisuru


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

like image 38
SeanK Avatar answered Sep 18 '22 10:09

SeanK