2016-02-01 55 views
0

使用karma-browserify與Jasmine進行單元測試。測試正確運行,但覆蓋率報告顯示文件包含路徑而不是源代碼。您可以通過安裝下列項目重現此並運行「一飲而盡單位」:karma-browserify覆蓋率報告包含文件包含路徑而不是源代碼

https://github.com/bshack/shackstack

這裏是覆蓋報告內容的例子:

typeof require === "function" && require("/xxx/xxx/xxx/shackstack/app/media/script/service/utilities.js"); 

這裏是我的karma.config:

module.exports = function(karma) { 
    'use strict'; 
    karma.set({ 
     basePath: '', 
     frameworks: [ 
      'jasmine', 
      'browserify' 
     ], 
     files: [{ 
      pattern: 'app/media/script/service/*.js', 
      included: true 
     }, 
     { 
      pattern: 'app/media/test/spec/*Spec.js', 
      included: true 

     }], 
     reporters: [ 
      'progress', 
      'coverage' 
     ], 
     preprocessors: { 
      'app/media/script/service/*.js': [ 
       'browserify', 
       'coverage' 
      ], 
      'app/media/test/spec/*Spec.js': [ 
       'browserify' 
      ] 
     }, 
     browsers: [ 
      //'Chrome', 
      //'Firefox', 
      //'Safari', 
      'PhantomJS' 
     ], 
     singleRun: false, 
     autoWatch: false, 
     // browserify configuration 
     browserify: { 
      debug: true, 
      transform: [ 
       'brfs', 
       'browserify-shim' 
      ] 
     }, 
     coverageReporter: { 
      type: 'html', 
      dir: 'app/report/istanbul/', 
      subdir: '.' 
     }, 
     // If browser does not capture in given timeout [ms], kill it 
     captureTimeout: 60000 
    }); 
}; 

有什麼想法?

+0

如果這是一個你能夠重現的bug,你應該把它作爲正確的回購問題。 – YPCrumble

+0

提交了karma-browserify錯誤:https://github.com/nikku/karma-browserify/issues/166 – bshack

回答

1

修正後,基本上不會像通常那樣使用業力報道,而必須使用istanbul作爲browserify轉換。

var istanbul = require('browserify-istanbul'); 
module.exports = function(karma) { 
    'use strict'; 
    karma.set({ 
     basePath: '', 
     frameworks: [ 
      'jasmine', 
      'browserify' 
     ], 
     files: [{ 
      pattern: 'app/media/script/service/*.js' 
     }, 
     { 
      pattern: 'app/media/test/spec/*Spec.js' 
     }], 
     reporters: [ 
      'progress', 
      'coverage' 
     ], 
     preprocessors: { 
      'app/media/script/service/*.js': [ 
       'browserify' 
      ], 
      'app/media/test/spec/*Spec.js': [ 
       'browserify' 
      ] 
     }, 
     browsers: [ 
      //'Chrome', 
      //'Firefox', 
      //'Safari', 
      'PhantomJS' 
     ], 
     singleRun: false, 
     autoWatch: false, 
     browserify: { 
      debug: true, 
      transform: [ 
       'brfs', 
       'browserify-shim', 
       istanbul({ 
        ignore: ['**/node_modules/**'] 
       }) 
      ] 
     }, 
     coverageReporter: { 
      type: 'html', 
      dir: 'app/report/istanbul/', 
      subdir: '.' 
     }, 
     // If browser does not capture in given timeout [ms], kill it 
     captureTimeout: 60000 
    }); 
}; 
+0

我按照「browserify-istanbul」的方法處理,但收到以下錯誤: 「TypeError: (options.instrumenter || require(...))。Instrumenter不是構造函數「 有什麼想法@bshack? –