How to test an AngularJS/SocketStream/Node.js app using Karma -
i working on angularjs application delivered socketstream/node.js server. have angularjs service calls api functions on socketstream server , progress has been far.
but time has come start writing first tests , first testing framework came mind karma/jasmine, since recommend angularjs set up.
so far good, since angularjs modules imported using 'require' (socketstream's version, not require.js) , server api calls part of test, need configure karma load socketstream (at least client side).
i took @ 'https://github.com/yiwang/angular-phonecat-livescript-socketstream' when run example run time errors, possibly because have later versions of variuous dependencies installed.
i managed 'required' resolved packing socketstream app adding 'ss.client.packassets()' app.js , run 'ss_pack=1 node app.js', when start karma logs error message saying:
'chrome 23.0 (linux) error uncaught typeerror: undefined not function @ /the...path/client/static/assets/app/1368026081351.js:25'
'1368026081351.js' socketstream packed assets file. if don't load error message 'require undefined', best guess error happening somewhere inside socketstream require code. because run karma in debug mode , can see files being served.
i have been trying different approaches find out happening avail. questions are:
is else testing angularjs/socketstream using karma? have suggestions how can fix, or @ least debug problem? there alternatives/better solutions?
time answer, sort of, own question:
sort of, because came conclusion karma , node.js/socketstream have lot of overlap, decided see if can omit karma altogether , deliver jasmine testing platform through socketstream. turns out that possible , here's how did it:
i defined new socketstream route , client in 'app.js' file:
ss.client.define( 'test', { view: 'specrunner.html', css: ['libs/test'], code: ['libs', 'tests', 'app'], tmpl: 'none' }); ss.http.route( '/test', function(req, res) { res.serveclient( 'test' ); });
i downloaded jasmine-standalone-1.3.1.zip , copied 'specrunner.html' 'client/views' folder. edited make load angularjs , socketstream client files, other views:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script> <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular-resource.min.js"></script> <socketstream/>
i removed 'script' tags import sample source files ( 'player.js' , 'song.js' ) , specs let last 'script' block in place unmodified.
i created new folder inside 'client/css/libs' called 'test' , copied 'jasmine.css' in there unmodified.
then copied 'jasmine.js' , 'jasmine-html.js' renamed '01-jasmine.js' , '02-jasmine-html.js' otherwise unmodified, '/client/code/libs'.
now jasmine in place , invoked using '/test' route. unsatisfactory bit haven't found elegant place store spec files. work far if place them inside 'libs' folder. anywhere else , served socketstream modules , not run.
but can live now. can run jasmine tests without having configure special karma setup.
Comments
Post a Comment