2015-10-29 30 views
5

我需要一些有關Karma和browserify覆蓋的幫助。我創建了我這裏運行測試回購:Karma覆蓋率未能顯示正確的結果

https://github.com/jotaoncode/web-istanbul

我覆蓋率結果如下: Results of coverage

測試只運行在性能指標。但正如你所看到的,結果是100%,並且只標記了綠色文件的第一行。

我見過伊斯坦布爾正確顯示覆蓋率值的情況,我改變了測試和源代碼,但沒有任何結果。

我也有這個因緣配置:

module.exports = function(config) { 
    config.set({ 
    //logLevel: 'LOG_DEBUG', 

    reporters: ['spec', 'coverage'], 

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

    autoWatch : false, 

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

    port: 9876, 

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

    files: [ 
     'src/**/*.js', 
     'test/*.js' 
    ], 

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

    preprocessors: { 
     'src/**/*.js': ['browserify', 'coverage'], 
     'test/**/*.js': ['browserify'] 

    }, 

    coverageReporter: { 
     reporters: [ 
     { type: 'html' }, 
     { type: 'text' }, 
     { type: 'lcovonly' } 
     ], 
     instrumenterOptions: { 
     istanbul: { 
      noCompact: true 
     } 
     }, 
     instrumenter: { 
     'test/**/*.js': 'istanbul' 
     }, 
     includeAllSources: true 
    }, 


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

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

    }); 
}; 

如果你運行測試,你會看到,它實際上工作正常,但覆蓋報告是不正確的。

+0

你是否在運行保險前進行縮小?這些結果看起來像你運行的代碼以外的其他東西。這可能是因爲源地圖並未完全通過。 – ssube

+0

@ssube不,我沒有縮小代碼,關於源地圖你是正確的,他們在哪裏活躍,因爲我已經在karma配置文件中瀏覽{debug:true},可能它正在創建源地圖。我刪除了它,並繼續以同樣的方式工作,沒有顯示源代碼的覆蓋範圍。 –

回答

相關問題