Reputation: 5228
I'm working on creation my own bootstrap project which includes RequireJS for modules structure, Backbone for routing and simple static views, ReactJS for components. The project works fine, but I want to add unit-testing support to cover my units of code in future projects. I'm trying to add Karma as a test runner with Jasmine and RequireJS support in unit tests (then I'll add TestUtils for components testing).
At the moment I have some troubles with Karma... it not works for me... I created Gruntfile.js with configuration for karma:
karma: {
unit: {
configFile: 'karma.config.js'
}
}
Also I added karma.config.js
file with configurations. And also I added the file with RequireJS configurations for tests test-main.js
But I'm got the troubels when trying to run tests with command grunt test
:
grunt test Running "karma:unit" (karma) task 14 12 2015 15:06:17.594:WARN [karma]: No captured browser, open http://localhost:9876/ 14 12 2015 15:06:17.634:INFO [karma]: Karma v0.13.15 server started at http://localhost:9876/ 14 12 2015 15:06:17.644:INFO [launcher]: Starting browser PhantomJS 14 12 2015 15:06:18.849:INFO [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Connected on socket Gvi8xqI0lfbPEEOGAAAA with id 60807377 PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 0 of 0 ERROR (0.013 secs / 0 secs)
And on this message programm is stuck... Have someone useful advices???
PS: I used this tutorial to use RequireJS with Karma tests: http://karma-runner.github.io/0.8/plus/RequireJS.html
Upvotes: 1
Views: 1202
Reputation: 10680
Add to karma.config.js
files: [
{pattern: 'bower_components/**/*.js', included: false},
{pattern: 'scripts/**/*.js', included: false},
{pattern: 'spec/**/*Spec.js', included: false},
'spec/test-main.js'
],
exclude: [
'scripts/main.js'
],
frameworks: ['jasmine', 'requirejs'],
plugins: ['karma-phantomjs-launcher', 'karma-requirejs', 'karma-jasmine'],
Run from command line:
npm install requirejs --save-dev
In spec/test-main.js
var pathToModule = function (path) {
console.log(path);
return path.replace(/^spec\//, '../spec/').replace(/\.(js)$/, '');
};
...
allTestFiles.push(pathToModule(normalizedTestModule));
...
baseUrl: '/base/scripts',
and remove
urlArgs: ...
Upvotes: 1