2014-06-26 128 views
1

我有喜欢噶覆盖文件路径

项目
文件夹结构工程| --Web
| ----脚本
| ------应用
| - ------- feature.js
| ------利布斯
| ------测试
| --------规格
| ----- ----- spec.js
| -------- karma-conf.js

在我的karma-conf.js中,我将覆盖预处理器指向../App/feature.js,但是这给了我一个空白的覆盖率报告,指出'没有要显示的数据'。

我试过一些其他的路径配置没有运气。 Karma文档指出路径应该相对于基本路径。出于传统原因,我无法移动测试文件夹。

下面是我的人缘,conf.js

的重复我对任何见解非常感谢到路径如何为卡玛覆盖工作。

module.exports = function (config) { 
    config.set({ 
     hostname: 'localhost', 

     // 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: [ 
      { 
       pattern: '../App/feature.js', 
       watched: true, 
       served: true, 
       included: true 
      }, 
      { 
       pattern: 'Specs/spec/*.js', 
       watched: true, 
       served: true, 
       included: true 
      } 
     ], 

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

     // web server port 
     port: 6789, 

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

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

     preprocessors: { 
      '**/.html': [], 
      '**/*.coffee': [], 
      "../App/feature.js": "coverage" 
     } 
    }); 
}; 
+0

我也有一些问题路径的因果报应。 ..你尝试追加'base /'到路径。它在规格内对我有用 – Sergio

回答

0

使用以下过程:

  • 直接将karma.conf.js文件Scripts目录下
  • 确保它是在同一水平App,因此基本路径相匹配
  • 变化映射到:

    'App/feature.js': 'coverage' 
    
+0

感谢您的回复。我目前正在努力让grunt-karma因为类似的原因而工作。我认为是时候重构该文件夹结构。 – moefinley

0

使用此链接作为参考:https://jaredtong.com/2016/01/08/how-to-set-up-mocha-chai-sinon-karma-browserify-istanbul-codecov/

我知道了这个配置工作:

// Karma configuration 
// Generated on Tue Apr 25 2017 13:33:19 GMT-0400 (Eastern Daylight Time) 

// Required by Browserify 
var istanbul = require('browserify-istanbul'); 

module.exports = function(config) { 
    'use strict'; 
    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 
// Include Browserify first. https://www.npmjs.com/package/karma-browserify 
frameworks: [ 'browserify', 'jasmine'], 


// list of files/patterns to load in the browser 
files: [ 
    'src/**/*.js', 
    'spec/**/*.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: { 
    'src/**/*.js': ['browserify'], 
    'spec/**/*.js': ['browserify'] 
}, 

browserify: { 
     debug: true, 
     transform: [ 
      'brfs', 
      istanbul({ 
       ignore: ['**/node_modules/**'] 
      }) 
     ] 
    }, 

// 
plugins: ['karma-chrome-launcher', 'karma-jasmine', 'karma-coverage', 'karma-firefox-launcher', 'karma-browserify'], 

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

// optionally, configure the reporter 
coverageReporter: { 
    type : 'html', 
    dir : 'coverage/', 
    includeAllSources: true 
}, 


// 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: ['Chrome'], 


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

// Concurrency level 
// how many browser should be started simultaneous 
concurrency: Infinity 

}) }