L
L
Leshrac2014-04-14 22:39:41
JavaScript
Leshrac, 2014-04-14 22:39:41

How to properly set up unit tests (jasmine js) on travis?

I got into a chrome extension for personal purposes, but I thought that maybe someone else would find it useful. I decided to be puzzled by the organization of Continuous Integration . Standard set - GitHub , Travis . For direct tests, I chose jasmine .
In practice, I encountered CI for the first time (as well as with extensions for chrome and js testing).
So my steps are:

  1. created .travis.yml
  2. in it - I put bower (through it I pull the necessary packages, for example, jasmine )
  3. in it, in the downloaded directory with jasmine , I put my SpecRunner.html , where my sources and specs are indicated
  4. loading SpecRunner.html in phantomjs
.travis.yml :
language: node_js
node_js:
  - "0.10"
install:
  - npm install -g bower
  - bower install
  - cd $TRAVIS_BUILD_DIR
script:
  - mv -f ./test/SpecRunner.html ./vendor/components-jasmine
  - phantomjs ./test/runTests.js

runTests.js :
var page = require('webpage').create();
page.open('../vendor/components-jasmine/SpecRunner.html', function(){
  phantom.exit();
});

The tests should have failed, but the status on travis is passed . How to properly configure test execution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Leshrac, 2014-04-15
@Leshrac

Travis behaves correctly in this case - in phantomjs he executes runTests.js , respectively, returns 0 and the build is marked as passed .
The results of the test after execution appear on the most loaded SpecRunner.html page . Therefore, in the phantom, you need to print its contents in order to see the results.
Also, I use local html as a url, and in the phantom, in this case, the path must be specified accordingly:

file:///c:/path/to/the%20file.txt #win
file:///etc/fstab #unix

Well, in order to get passed or failed on travis as a result, you need to either parse the page received from the phantom in after_script in .travis.yml, or use jasmine itself (although I’m not sure about this) to get the result, and depending on this, from the phantom to travis return 0 if all tests passed, or another value if something failed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question