使用共享配置时,grunt-karma不运行spec文件 [英] grunt-karma not running the spec file when using shared config

查看:159
本文介绍了使用共享配置时,grunt-karma不运行spec文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个基本项目,试图让Gruntjs,Karma和Jasmine一起玩。当我将karma.conf.js文件与所有必要文件一起设置时,一切正常并且测试通过。



当我尝试在Grunt中分割它们时,出现问题。

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']
}
}

});

grunt-karma的文档显示在分割模块时使用files:。我在basicController模块下执行了这个操作,当我尝试运行$ grunt karma时:basicController --verbose,我得到一个错误消息:

 警告:无法使用'in'运算符搜索/basicController/scBasicControllerCtrl.js中的'src'使用--force继续

由于警告而中止。

当我运行$ grunt karma时:overworkedControllers --verbose(使用src而不是files ,它看起来像一切都会工作,Chrome浏览器启动,但后来说它执行0的0错误。



应该有3个测试。



让我知道是否有更多信息可以发布。

我的理解grunt-karma是不正确的。



我以为我可以在karma.conf.js文件中拥有基本和源文件,然后在每个模块中,我只是添加该模块所需的特定文件并进行测试。

实际上,每个模块中声明的文件完全覆盖了karma.conf中的文件属性。 js文件。不附加到它们。

我最终在Gruntfile.js中创建了一个包含所有源代码.js文件的数组,并将必要的文件连接到它在每个模块中。

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.

解决方案

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.

这篇关于使用共享配置时,grunt-karma不运行spec文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆