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

≡放荡痞女 提交于 2019-12-13 01:11:58

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/21467715/grunt-karma-not-running-the-spec-file-when-using-shared-config

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!