karma-browserify覆盖率报告包含文件包含路径而不是源代码 [英] karma-browserify coverage reports contain file include paths instead of source code

查看:128
本文介绍了karma-browserify覆盖率报告包含文件包含路径而不是源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用karma-browserify与Jasmine进行单元测试.测试可以正确运行,但是覆盖率报告显示文件包含路径而不是源代码.您可以通过安装以下项目并运行"gulp unit"来重现此内容:

Using karma-browserify to do unit tests with Jasmine. The tests correctly run but the coverage reports show file include paths instead of source code. You can reproduce this by installing the following project and run 'gulp unit':

https://github.com/bshack/shackstack

以下是覆盖率报告内容的示例:

Here is an example of the coverage report contents:

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

这是我的karma.config:

Here is my 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
    });
};

有什么想法吗?

推荐答案

固定,基本上,您不像通常那样使用业力覆盖,而是必须将伊斯坦布尔用作浏览器转换.

Fixed, basically you don't use karma coverage as you would normally, instead you have to use istanbul as a browserify transform.

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

这篇关于karma-browserify覆盖率报告包含文件包含路径而不是源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆