vendredi 20 février 2015

confused with karma for testing an angularjs application

I've been planning to study how to test my AngularJS app for more than 6 months now. Unfortunately, since I'm the only frontend developer, I've been so swamped with feature request. I'm unable to put time to doing unit-testing. However, I told the team during this Agile Sprint, I should really add codes for unit-testing. I was able to request 3 days dedicated for learning unit-testing.


I actually have already done research before. I found Karma. I remember installing it. Today, I installed it again. Now I've very confused. When I executed unix find, this is what I got.



19:29 ~/repos/baam/baam-ui $ find ~/.npm -name 'karma*'

/Users/admin/.npm/chai/1.9.1/package/karma.conf.js
/Users/admin/.npm/chai/1.9.1/package/karma.sauce.js
/Users/admin/.npm/deep-eql/0.1.3/package/karma.conf.js
/Users/admin/.npm/karma
/Users/admin/.npm/karma/0.12.12/package/bin/karma
/Users/admin/.npm/karma/0.12.12/package/integration-tests/coffee/karma.conf.coffee
/Users/admin/.npm/karma/0.12.12/package/integration-tests/coverage-coffee/karma.conf.coffee
/Users/admin/.npm/karma/0.12.12/package/integration-tests/coverage-jasmine/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/coverage-mocha-requirejs/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/coverage-qunit/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/dojo/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/html2js/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/jasmine/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/jasmine_2/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/junit/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/live-script/karma.conf.ls
/Users/admin/.npm/karma/0.12.12/package/integration-tests/mocha/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/qunit/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/requirejs/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/integration-tests/saucelabs/karma.conf.js
/Users/admin/.npm/karma/0.12.12/package/karma-0.12.11.tgz
/Users/admin/.npm/karma/0.12.12/package/karma-completion.sh
/Users/admin/.npm/karma/0.12.12/package/lib/middleware/karma.js
/Users/admin/.npm/karma/0.12.12/package/static/karma.js
/Users/admin/.npm/karma/0.12.14/package/bin/karma
/Users/admin/.npm/karma/0.12.14/package/integration-tests/coffee/karma.conf.coffee
/Users/admin/.npm/karma/0.12.14/package/integration-tests/coverage-coffee/karma.conf.coffee
/Users/admin/.npm/karma/0.12.14/package/integration-tests/coverage-jasmine/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/coverage-mocha-requirejs/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/coverage-qunit/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/dojo/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/html2js/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/jasmine/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/jasmine_2/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/junit/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/live-script/karma.conf.ls
/Users/admin/.npm/karma/0.12.14/package/integration-tests/mocha/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/qunit/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/requirejs/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/integration-tests/saucelabs/karma.conf.js
/Users/admin/.npm/karma/0.12.14/package/karma-0.12.13.tgz
/Users/admin/.npm/karma/0.12.14/package/karma-completion.sh
/Users/admin/.npm/karma/0.12.14/package/lib/middleware/karma.js
/Users/admin/.npm/karma/0.12.14/package/static/karma.js
/Users/admin/.npm/karma/0.12.16/package/bin/karma
/Users/admin/.npm/karma/0.12.16/package/karma-completion.sh
/Users/admin/.npm/karma/0.12.16/package/lib/middleware/karma.js
/Users/admin/.npm/karma/0.12.16/package/static/karma.js
/Users/admin/.npm/karma-chai
/Users/admin/.npm/karma-chrome-launcher
/Users/admin/.npm/karma-coverage
/Users/admin/.npm/karma-firefox-launcher
/Users/admin/.npm/karma-jasmine
/Users/admin/.npm/karma-mocha
/Users/admin/.npm/karma-ng-html2js-preprocessor
/Users/admin/.npm/karma-ng-scenario
/Users/admin/.npm/karma-phantomjs-launcher
/Users/admin/.npm/karma-requirejs
/Users/admin/.npm/http://ift.tt/1hIC91J
/Users/admin/.npm/http://ift.tt/1zUABpw
/Users/admin/.npm/http://ift.tt/18ag4rJ
/Users/admin/.npm/http://ift.tt/1zUAzOD
/Users/admin/.npm/http://ift.tt/18ag4rL
/Users/admin/.npm/http://ift.tt/1zUAzOH
/Users/admin/.npm/http://ift.tt/18ag4rN
/Users/admin/.npm/http://ift.tt/1zUABpz
/Users/admin/.npm/http://ift.tt/18ag4rR


Looks like I've got multiple versions now. I manually executed the karma binaries, and I got this output.



module.js:340
throw err;
^
Error: Cannot find module 'optimist'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/admin/.npm/karma/0.12.14/package/lib/cli.js:2:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)


I couldn't recall which tutorials I've followed before so I'm not sure which commands I've executed. I also saw karma.conf.js on my Angular project. I'm not sure why I have one there. File is dated July 12, 2014.


I'm not sure how to restart my karma installation without affecting my project. I would like to have a clean and working karma. I also want to learn how to test my application.


Oh, I remember reading protractor too but I don't know if I installed it. I would like to use the best unit-testing for angular. So far, I read it's karma.


Aucun commentaire:

Enregistrer un commentaire