Ember run tests in console


#1

Hi, When I create an component or a controller etc… ember also creates some tests file. It is possible to run tests in terminal as you do with phpunit?

Or, can I write my own tests that run in terminal? I do not want to open browser, I do not do that kind of tests. I want to do unit testing and very few integration tests.


#2

hey @ioanszabo there is indeed. Ember comes pre-configured to run tests with PhantomJS via command line (Phantom is a headless browser if you’re not familiar). All you need to do is install phantom (want to say it’s npm install -g phantomjs-prebuilt but maybe double check that) and then run ember test in your project. It will run the tests via command line instead of opening the browser (like if you run ember test --server). You can run any type of test in Phantom, unit, integration or acceptance. It fully simulates a browser. For a little more info, check out the ember-cli docs


#3

Hi, Thanks for the fast answer. Looks good, but I always get an error when run ember test command.

cleaning up...
Built project successfully. Stored in "C:\tracknamic-smb\tmp\class-tests_dist-XwbnTFtR.tmp".
not ok 1 PhantomJS 2.1 - Global error: Error: Could not find module ember-metal required by: ember-testing/support at ht
tp://localhost:7357/assets/test-support.js, line 58
    ---
        Log: |
            { type: 'error',
              text: 'Error: Could not find module ember-metal required by: ember-testing/support at http://localhost:735
7/assets/test-support.js, line 58\n' }
    ...
not ok 2 PhantomJS 2.1 - Global error: ReferenceError: Can't find variable: define at http://localhost:7357/assets/tests
.js, line 3
    ---
        Log: |
            { type: 'error',
              text: 'ReferenceError: Can\'t find variable: define at http://localhost:7357/assets/tests.js, line 3\n' }
    ...
not ok 3 PhantomJS 2.1 - Global error: ReferenceError: Can't find variable: EmberENV at http://localhost:7357/1261/tests
/index.html?hidepassed, line 39
    ---
        Log: |
            { type: 'error',
              text: 'ReferenceError: Can\'t find variable: EmberENV at http://localhost:7357/1261/tests/index.html?hidep
assed, line 39\n' }
    ...

How to publish addons and install them with ember install
#4

I’m taking a stab in the dark here but it kinda sounds like something is wrong with your ember-cli project setup. Is this a fresh project or has it been upgraded through several versions of Ember? One thing you could try is generating a fresh ember project and then comparing the test files like tests/index.html, or maybe you just need completely clean npm/bower install? Basically it sounds like it’s either not building everything properly or your dependency injection is messed up somewhere so it’s probably either a configuration problem, a dependency problem (your npm modules are messed up or something), or possibly there’s an issue with one of your tests that is causing the compiled test assets to puke.