karma-browserify覆盖率报告包含文件包含路径而不是源代码

时间:2016-02-01 03:27:43

标签: node.js karma-runner browserify browserify-shim

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

来重现这一点

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

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

修正了,基本上你不像往常一样使用业力覆盖,而是必须使用istanbul作为浏览器变换。

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