In the previous post, we got karma running on your local systems, as part of grails unit test plans, enabling continual test against Chrome. How do you ensure your unit tests are running in a build server like Jenkins or Bamboo?
PhantomJS is a headless webkit, ie a browser with no browser UI. Make these changes in your karma.conf.js
browsers: ['Chrome', 'PhantomJS'], plugins: [ 'karma-jasmine', 'karma-chrome-launcher', 'karma-phantomjs-launcher', 'karma-remote-reporter' ]
Now run the karma test again:
Warning: Native modules not compiled. XOR performance will be degraded.
Warning: Native modules not compiled. UTF-8 validation disabled.
INFO [karma]: Karma v0.10.9 server started at http://localhost:8001/
INFO [launcher]: Starting browser Chrome
INFO [launcher]: Starting browser PhantomJS
INFO [Chrome 33.0.1750 (Windows 7)]: Connected on socket Tsk76f8qRWk84nVP6jlC
INFO [PhantomJS 1.9.2 (Windows 7)]: Connected on socket oMQSWXNcCW6hNOoH6jlD
PhantomJS 1.9.2 (Windows 7) LOG: ‘angrails manifest load complete.’
PhantomJS 1.9.2 (Windows 7) LOG: ‘calling’
Chrome 33.0.1750 (Windows 7) LOG: ‘angrails manifest load complete.’
Chrome 33.0.1750 (Windows 7) LOG: ‘calling’
Chrome 33.0.1750 (Windows 7): Executed 1 of 1 SUCCESS (0.352 secs / 0.029 secs)
PhantomJS 1.9.2 (Windows 7): Executed 1 of 1 SUCCESS (0.273 secs / 0.018 secs)
TOTAL: 2 SUCCESS
But for your build server you need to test just against PhantomJS and not other browsers. One way to do this, is to create a copy of karma.conf.js as karma.local-conf.js. Use the local copy for your local unit tests and the default karma.conf.js for the builds (ie only PhantomJS). This way grails test-app runs against the karma.conf.js in your build server.
Remember you need to install node.js, karma and other components in the build server too.
In Part 5, we shall see how to invoke grails urls/services from AngularJS.