【问题标题】:Karma output duplicating test results业力输出重复测试结果
【发布时间】:2015-10-07 15:44:48
【问题描述】:

当运行测试 karma 似乎多次重复最后一个测试时,重复测试的次数似乎取决于测试的数量和用于运行的浏览器。

如果只使用一个浏览器(PhantomJS 或 Chrome)进行一次测试,测试会显示两次,当使用两种浏览器时,相同的单个测试最多显示 6 次。

我已将日志记录添加到测试中,日志在每个浏览器的每个测试中出现一次,因此推测测试运行的次数正确,但只是复制了显示的结果。

karma.conf.js

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

    // base path that will be used to resolve all patterns (eg. files, exclude)
    basePath: '',


    // frameworks to use
    // available frameworks: https://npmjs.org/browse/keyword/karma-adapter
    frameworks: ['jasmine'],


    // list of files / patterns to load in the browser
    files: [
        '_test/test.js'
    ],


    // list of files to exclude
    exclude: [
    ],


    // preprocess matching files before serving them to the browser
    // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
    preprocessors: {
    },


    // test results reporter to use
    // possible values: 'dots', 'progress'
    // available reporters: https://npmjs.org/browse/keyword/karma-reporter
    reporters: ['progress'],


    // web server port
    port: 9876,


    // 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_INFO,


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


    // start these browsers
    // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
    browsers: ['PhantomJS', 'Chrome'],


    // Continuous Integration mode
    // if true, Karma captures browsers, runs the tests and exits
    singleRun: false
  })
}

test.js

describe('karma testing', function () {
    it('tests karma is working', function () {
        expect(true).toBe(true);
        console.log('test1');
    });
});

输出 1 浏览器 (Chrome)

07 10 2015 16:41:14.890:INFO [karma]: Karma v0.13.10 server started at http://localhost:9876/
07 10 2015 16:41:14.897:INFO [launcher]: Starting browser Chrome
07 10 2015 16:41:16.364:INFO [Chrome 45.0.2454 (Windows 7 0.0.0)]: Connected on socket 0uvPocfSI0prGxwdAAAA with id 29520633
LOG: 'test1'
Chrome 45.0.2454 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0 secs / 0.003 secs
Chrome 45.0.2454 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.011 secs / 0.003 secs)

输出 2 个浏览器(PhantomJS、Chrome)

07 10 2015 16:27:31.399:INFO [karma]: Karma v0.13.10 server started at http://localhost:9876/
07 10 2015 16:27:31.407:INFO [launcher]: Starting browser PhantomJS
07 10 2015 16:27:31.420:INFO [launcher]: Starting browser Chrome
07 10 2015 16:27:32.886:INFO [PhantomJS 1.9.8 (Windows 7 0.0.0)]: Connected on socket P5focoe7004aPX1rAAAA with id 49258591
07 10 2015 16:27:33.077:INFO [Chrome 45.0.2454 (Windows 7 0.0.0)]: Connected on socket BGtRdqevRGGXZTA-AAAB with id 42323971
LOG: 'test1'
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0 secs / 0.003 secs)
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.007 secs / 0.003 s
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.007 secs / 0.003 s
Chrome 45.0.2454 (Windows 7 0.0.0) LOG: 'test1'
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.007 secs / 0.003 s
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.007 secs / 0.003 secs)
PhantomJS 1.9.8 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.007 secs / 0.003 secs)
Chrome 45.0.2454 (Windows 7 0.0.0): Executed 1 of 1 SUCCESS (0.028 secs / 0.002 secs)
TOTAL: 2 SUCCESS

我已经在安装和不安装 karma-cli 的情况下对此进行了测试,结果是相同的。

我查看了堆栈溢出和google,似乎有一些人遇到了类似的问题,但没有任何有意义的答案。

【问题讨论】:

  • 运气好可以解决这个问题吗?我们遇到了同样的问题。
  • 很遗憾没有,我现在一直在使用它,你运行的是相同的配置吗?

标签: karma-runner karma-jasmine


【解决方案1】:

我在尝试让美化器工作时遇到了类似的问题。

karma.conf 有几个选项,比如 autoWatch、浏览器、singleRun - 对吧?其中有一个名为 client 的属性。

客户端属性是一个具有自己的一些属性的对象。其目的是配置与测试客户端相关的设置,例如 Chrome。

客户端有一个名为 captureConsole 的属性。这默认为 true,这意味着浏览器中的任何控制台日志记录也会发送回您的 bash。因此,在默认情况下打开它,我可以看到 Chrome 的控制台日志记录和美化的点击输出。

试试你的这个设置,看看是否有帮助!

client: {
    captureConsole: false
},

【讨论】:

    【解决方案2】:

    我知道这是几年前问过的,但你有没有可能从 Windows 命令行运行 karma?我有同样的问题,浪费了几个小时的谷歌搜索,然后一时兴起从 powershell 运行它,它工作正常。还与 git bash 一起使用。

    【讨论】:

      猜你喜欢
      • 2014-01-09
      • 2014-07-12
      • 1970-01-01
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-30
      • 2017-04-01
      相关资源
      最近更新 更多