Reputation: 91
I create a simple project to try run a simple test case in Karma under require js. Something goes wrong but no error message. Here is my configuration files.
Gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
karma: {
frontend: {
configFile: 'test/karma.conf.js'
}
}
});
grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('test', ['karma:frontend']);
};
karma.conf.js
module.exports = function (config) {
config.set({
basePath: '../',
autoWatch: true,
// web server port
port: 9876,
frameworks: ['mocha', 'requirejs', 'chai', 'sinon'],
files: [
'test/main.js',
'test/*Spec.js'
],
exclude: [],
browsers: ['PhantomJS'], //'Chrome',
logLevel: config.LOG_DEBUG,
plugins: ['karma-mocha', 'karma-chai', 'karma-sinon', 'karma-requirejs', 'karma-chrome-launcher', 'karma-phantomjs-launcher'],
singleRun: true
});
};
main.js //test-main
(function (window, require) {
'use strict';
var tests = [];
for (var file in window.__karma__.files) {
if (window.__karma__.files.hasOwnProperty(file)) {
if (/Spec\.js$/.test(file)) {
console.log('add file = '+file);
tests.push(file);
}
}
}
require({
deps: tests,
callback: window.__karma__.start
});
}(window, require));
//define('helloSpec', function(){//if uncomment this line, this spec will not run at all
'use strict';
describe('helloSpec',
function () {
console.log('helloSpec');
before(function () {
});
it('Say hello', function () {
});
});
//});
If I wrap describe function in define function, the test won't run any more.
Upvotes: 0
Views: 465
Reputation: 91
It works after one change made to karma.conf.js from:
files: [
'test/main.js',
'test/*Spec.js'
],
to:
files: [
'test/test-main.js',
{pattern: 'test/*Spec.js', included: false}
],
Upvotes: 2