【问题标题】:grunt-karma not running the spec file when using shared config使用共享配置时 grunt-karma 未运行规范文件
【发布时间】:2014-01-30 21:25:57
【问题描述】:

我创建了一个基本项目来尝试让 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 的文档显示在拆分模块时使用“文件:”。我是在 basicController 模块下完成的,当我尝试运行 $ grunt karma:basicController --verbose 时,我收到一条错误消息

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

Aborted due to warnings.

当我运行 $ grunt karma:overworkedControllers --verbose(使用“src”而不是“files”时,看起来一切正常,Chrome 浏览器启动,但据说它执行了 0 of 0 错误。

应该有 3 个测试。

如果我可以发布更多信息,请告诉我。

【问题讨论】:

  • 为什么overworkedControllers下有一个“src”属性?两个子任务下的属性名称应该是“文件”。你用的是什么版本的 grunt-karma?

标签: unit-testing gruntjs jasmine karma-runner


【解决方案1】:

我对 grunt-karma 的理解是错误的。

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

它的实际工作方式是每个模块中声明的文件完全覆盖 karma.conf.js 文件中的 files 属性。不附加到它们。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-17
    • 1970-01-01
    • 2014-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多