【问题标题】:Karma not running testsKarma 没有运行测试
【发布时间】:2013-08-24 09:07:57
【问题描述】:

我在我的应用程序上使用 grunt 运行了业力,但由于某种原因,事情停止了工作。我通过重新安装更新了业力,这改变了很多,并改变了我的配置文件。我的所有文件都被添加和服务,但它没有执行我的任何测试。

暂时(只是为了让事情再次运行),我正在使用命令karma start <pathtomyconfigfile> 在 grunt 之外运行。使用 LOG_DEBUG 选项,我可以看到添加和服务的所有内容。

这是我的配置文件:

module.exports = function(config) {
config.set({

    // base path, that will be used to resolve files and exclude
    basePath: '',


    // frameworks to use
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
        '../build/angular/angular.js',
        '../build/angular/angular-mocks.js',
        '../build/angular/angular-resource.js',
        '../build/angular/angular-cookies.js',
        '../build/angular/angular-scenario.js',
        '../src/**/*.js',
        '../dist/tmp/**/*.js',
        '../vendor/angular-bootstrap/*.js',
        '../vendor/angular-ui-utils/modules/route/*.js',
        '../vendor/angular-ui-utils/modules/mask/*.js'
    ],


    // list of files to exclude
    exclude: [

    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    reporters: ['progress'],


    // web server port
    port: 9018,


    // enable / disable colors in the output (reporters and logs)
    colors: true,


    // level of logging
    // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
    logLevel: config.LOG_DEBUG,


    // enable / disable watching file and executing tests whenever any file changes
    autoWatch: true,


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera
    // - Safari (only Mac)
    // - PhantomJS
    // - IE (only Windows)
    browsers: ['Chrome'],//nothing so we can start it on our own


    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
});
};

我在这里不知所措,在不同的浏览器上运行,更改了观看的文件,在文件变量中加载框架的旧方法与框架变量之间切换......任何帮助将不胜感激。谢谢!

其他信息

我的业力似乎也出错了,除了错误之外没有任何信息:

INFO [karma]: Karma v0.10.1 server started at http://localhost:9018/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 28.0.1500 (Mac OS X 10.7.4)]: Connected on socket id sidUjYbbZINjGB_6wS6M
Chrome 28.0.1500 (Mac OS X 10.7.4): Executed 0 of 0 ERROR (0.777 secs / 0 secs)

【问题讨论】:

  • 您的测试在哪里?它们是否嵌套在“../src/**/*.js”中的某个地方?
  • 是的,它们都被提供到浏览器中(通过观察调试行注意到)。
  • 只是为了隔离事物,您是否能够对单个“保证通过”测试进行 iit 并让它运行? expect(true).toBe(true) 或类似的东西?
  • 你在使用角度场景吗?我隐约记得在我的配置文件中包含 angular-scenario.js 时遇到了类似的问题。尝试删除它,看看是否有帮助。
  • 不,它实际上只用于 e2e 场景测试。如果你是 e2e 测试,你可能会有一个单独的配置文件。你不需要它来进行单元测试。

标签: unit-testing angularjs karma-runner


【解决方案1】:

如果您使用 angular-scenario,请从您的配置文件中删除 angular-scenario.js,看看是否有帮助。

【讨论】:

  • (+1) 因为这是此类问题的常见解决方案。
【解决方案2】:

我自己在这个问题上花了几个小时。原来我使用的是 karma 0.10.3 并切换到 0.10.2 解决了这个问题。

试试npm install karma@0.10.2,看看能不能解决问题!

还要确保在您的配置中将autoWatch 设置为true

【讨论】:

  • 将 autoWatch 设置为 'true' 为我解决了这个问题。如果 autoWatch 设置为 false,你如何运行测试?每次我启动 Karma 时不应该执行测试吗?
  • 对于任何在这里绊倒的人的迟到评论:在业力开始时执行一次测试,使用singleRun: true。在这种情况下,autoWatch 可能为假。
  • 问题是 0.10.3 中添加了什么使 karma 停止运行测试?
  • 奇怪的是这个答案适用于我的案例!我在 0.13.22 上,我不相信降级会改变任何东西,但猜猜它做了什么!我去了 0.13.0 和 ta-da 它的工作原理!
猜你喜欢
  • 2019-06-17
  • 1970-01-01
  • 1970-01-01
  • 2019-01-08
  • 2020-08-26
  • 1970-01-01
  • 1970-01-01
  • 2014-12-20
  • 1970-01-01
相关资源
最近更新 更多