VtoCorleone
VtoCorleone

Reputation: 17203

grunt-karma not running the spec file when using shared config

I created a basic project to try and get Gruntjs, Karma and Jasmine to play together. When I setup the karma.conf.js file with all of the neccesary files, everything works and the tests pass.

When I try to split them up in Grunt though, I get problems.

Gruntfile.js

grunt.initConfig({
    pkg: grunt.file.readJSON('package.json'),

    karma: {
        options: {
            configFile: 'karma.conf.js'
        },
        basicController: {
            files: ['/basicController/scBasicControllerCtrl.js', '/basicController/test/ControllersSpec.js']
        },
        overworkedController: {
            src: ['overworkedController/scOverworkedControllerCtrl.js', 'overworkedController/test/ControllersSpec.js']
        }
    }

});

The documentation at grunt-karma show to use "files:" when splitting up the modules. I did that under the basicController module and when I try to run $ grunt karma:basicController --verbose, I get an error saying

Warning: Cannot use 'in' operator to search for 'src' in /basicController/scBasicControllerCtrl.js Use --force to continue 

Aborted due to warnings.

When I run $ grunt karma:overworkedControllers --verbose (using "src" instead of "files", it looks like everything is going to work and the Chrome browser launches but then is says it executed 0 of 0 ERROR.

There should be 3 tests.

Let me know if there's any more info I could post.

Upvotes: 1

Views: 2360

Answers (1)

VtoCorleone
VtoCorleone

Reputation: 17203

My understanding of grunt-karma was incorrect.

I thought I could have the base and source files in the karma.conf.js file. Then in each module, I'd just add the specific files needed for that module and test.

The way it actually works is that the files declared in each module completely overwrite the files property in the karma.conf.js file. Not append to them.

I ended up creating an array in Gruntfile.js that contains all of the source .js files and just concat the necessary files to it in each module.

Upvotes: 3

Related Questions