i set grunt run node.js jasmine tests. reason, config, results show double tests.
here config:
i'm using jasmine-node plugs grunt.
/spec/some-spec.js:
var mymodule = require('../src/mymodule.js'); describe('test', function(){ it('works', function(done){ settimeout(function(){ expect(1).tobe(1); done(); }, 100); }); });
gruntfile.js:
module.exports = function(grunt) { grunt.initconfig({ jasmine_node: { options: { forceexit: true }, all: ['spec/'] } }); grunt.loadnpmtasks('grunt-jasmine-node'); grunt.registertask('default', ['jasmine_node']); };
this results in two tests running rather one.
> grunt running "jasmine_node:all" (jasmine_node) task .. finished in 0.216 seconds 2 tests, 2 assertions, 0 failures, 0 skipped
the jasmine-node project pretty old. latest commit july of 2014. grunt-jasmine-node plugin appears active, running against going stale seems little pointless imho.
to test commonjs modules using jasmine i'd recommend using karma along karma-jasmine , karma-commonjs plugins. got example working following files:
package.json
{ "private": "true", "devdependencies": { "grunt": "^0.4.5", "grunt-jasmine-node": "^0.3.1", "grunt-karma": "^0.10.1", "jasmine-core": "^2.3.4", "karma": "^0.12.31", "karma-commonjs": "0.0.13", "karma-jasmine": "^0.3.5", "karma-phantomjs-launcher": "^0.1.4" } }
karma.conf.js
module.exports = function(config) { config.set({ basepath: '.', frameworks: ['jasmine', 'commonjs'], files: [{ pattern: 'src/**/*.js' }, { pattern: 'spec/**/*.js' }], preprocessors: { 'src/**/*.js': ['commonjs'], 'spec/**/*.js': ['commonjs'] }, reporters: ['progress'], browsers: ['phantomjs'] }); };
gruntfile.js (optional if still want use grunt)
module.exports = function(grunt) { grunt.initconfig({ karma: { unit: { configfile: 'karma.conf.js', options: { singlerun: true } } } }); grunt.loadnpmtasks('grunt-karma'); grunt.registertask('default', ['karma:unit']); };
you should install karma command line runner globally, did grunt. npm install -g karma-cli
from command line can start karma typing karma start
. run tests , watch files , re-run them on every save. (very nice)
alternatively can run karma start --single-run
have run tests once , exit. if updated gruntfile can run grunt
run tests once.
Comments
Post a Comment