【问题标题】:Karma-coverage file paths业力覆盖文件路径
【发布时间】:2014-08-17 15:10:12
【问题描述】:

我有一个文件夹结构类似的项目

项目
|--网络
|----脚本
|--------应用
|--------feature.js
|------库
|--------测试
|--------规格
|---------spec.js
|--------karma-conf.js

在我的 karma-conf.js 中,我将覆盖预处理器指向 ../App/feature.js 但这给了我一个空白的覆盖报告,说明“没有数据可显示”。

我尝试了其他一些路径配置,但没有成功。 Karma 文档指出路径应该相对于基本路径。由于遗留原因,我无法移动测试文件夹。

下面是我的 karma-conf.js 的副本

如果您能深入了解这些路径如何用于 karma-coverage,我将不胜感激。

    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"
        }
    });
};

【问题讨论】:

  • 我在 Karma 中的路径也遇到了一些问题...您是否尝试将 base/ 附加到路径中。它从规范内部对我有用

标签: javascript karma-runner


【解决方案1】:

使用以下流程:

  • karma.conf.js文件直接移动到Scripts目录下
  • 确保它与App处于同一级别,以便基本路径匹配
  • 将映射更改为:

    'App/feature.js': 'coverage'
    

【讨论】:

  • 感谢您的回复。由于类似的原因,我目前正在努力让 grunt-karma 工作。我认为是时候重构该文件夹结构了。
【解决方案2】:

使用此链接作为参考: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

}) }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-08
    • 2015-12-27
    • 2019-02-08
    • 1970-01-01
    • 2017-01-07
    • 2015-10-06
    • 1970-01-01
    • 2018-02-15
    相关资源
    最近更新 更多