Karma / Istanbul Code Coverage не находит функций и всегда возвращает 100%

Я пытаюсь добавить Code Coverage для моих тестов Karma, однако, хотя он находит правильный файл JS, который я тестирую, он не находит функции внутри этих файлов.

Из того, что я прочитал до сих пор, я полагаю, что это связано с тем, что файлы не были правильно просмотрены, прежде чем они были переданы в Стамбул для освещения, но по общему признанию, я новичок в этом, поэтому я надеюсь на некоторые предложения.

Вот мой файл JS (common.js):

var applicationSettings = require('./settings');

var common = {
    getAjaxBaseUrl: function () {
        var strVirtualDirectory = applicationSettings.VirtualDirectory;
        if (strVirtualDirectory.length > 1) {
            if (!strVirtualDirectory.startsWith("/")) {
                strVirtualDirectory = "/" + strVirtualDirectory;
            }
        }
    return strVirtualDirectory;
   }
}
module.exports = common;

И вот тесты, которые я написал:

it('Client - Should get correct AjaxBaseUrl with /', function () {
    var clientSettings = require('./../client/scripts/settings');
    var clientCommon = require('./../client/scripts/common');

    clientSettings.VirtualDirectory = '/VD';
    expect(clientCommon.getAjaxBaseUrl()).to.equal('/VD');

});

it('Client - Should get correct AjaxBaseUrl without /', function () {
    var clientSettings = require('./../client/scripts/settings');
    var clientCommon = require('./../client/scripts/common');

    clientSettings.VirtualDirectory = 'VD';
    expect(clientCommon.getAjaxBaseUrl()).to.equal('/VD');
});

Мой Karma.conf ниже:

// Karma configuration
// Generated on Mon Jan 11 2016 09:43:00 GMT+0000 (GMT Standard Time)

module.exports = function (config) {
    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
        frameworks: ['phantomjs-shim', 'browserify', 'mocha'],

        // list of files / patterns to load in the browser
        files: [
            'https://code.jquery.com/jquery-2.2.0.min.js',
            'http://cdn.kendostatic.com/2015.3.1111/js/kendo.all.min.js',
            'test_unit/*Spec.js',
            'client/scripts/*.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: {
            'test_unit/*Spec.js': ['browserify'],
            'client/scripts/*.js': ['browserify', 'coverage']    
        },

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

        // Configure jUnit reporter
        junitReporter: {
            outputDir: '', // results will be saved as $outputDir/$browserName.xml 
            outputFile: undefined, // if included, results will be saved as $outputDir/$browserName/$outputFile 
            suite: '', // suite will become the package name attribute in xml testsuite element 
            useBrowserName: true // add browser name to report and classes names 
        },

        // Configure coverage reporter
        coverageReporter: {
            type: 'html',
            dir: 'test_coverage',
            subdir: '.',
            file: 'coverage.htm'
        },

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

        browserify: {
            configure: function (bundle) {
                bundle.transform('reactify', { extensions: ['.jsx'] });
            }        
        },        

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

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

    })
}

Это создает отчет, но показывает 100%, и единственная строка, найденная в файле common.js:

require("C:\\Source\\ProjectName\\client\\scripts\\common.js");

Я попытался добавить Browerify-Istanbul в микс, добавив для него в верхней части Karma.conf дополнительное преобразование в разделе browserify.

bundle.transform(istanbul)

Однако это просто проваливает мои тесты и выдает несколько ошибок:

undefined не является объектом (оценивает '__cov_qQLFhXEMt7fatxiMx0_vQQ.b [' 1 '] [0]') getAjaxBaseUrl @ C: /Users/CHARLE~1.WIC/AppData/Local/Temp/0d61da722d2838c9 600b4648: cbb098: cd: /Users/CHARLE~1.WIC/AppData/Local/Temp/0d61da722d2838c9600d83d1cbb4c0b 8.browserify: 51742: 1849

16 02 2016 09: 14: 08.515: ОШИБКА [покрытие]: [Ошибка типа: Не удается прочитать свойство 'звезда t' из неопределенного] Ошибка типа: Ошибка чтения свойства 'начало' из неопределенного в C: \ Source \ ProjectName \ node_modules \ istanbul \ lib \ o bject-utils.js: 59: 44 в Array.forEach (нативный) в Object.addDerivedInfoForFile (C: \ Source \ ProjectName \ node_modules \ istanbul \ lib \ object-utils.js: 58: 37) в Object.Collector .fileCoverageFor (C: \ Source \ ProjectName \ node_modules \ istanbul \ lib \ collector.js: 94: 15) в C: \ Source \ ProjectName \ node_modules \ istanbul \ lib \ r eport \ html.js: 558: 90 в массиве .forEach (собственный) в HtmlReport.Report.mix.writeReport (C: \ Source \ ProjectName \ node_modules \ istanbul \ lib \ report \ html.js: 557: 27) в writeReport (C: \ Source \ ProjectName \ node_modules \ k arma-покрытие \ lib \ reporter.js: 62: 16) в C: \ Source \ ProjectName \ node_modules \ karma-покрытие \ lib \ reporter.js: 288: 11 в C: \ Source \ ProjectName \ node_modules \ karma \ lib \ help er.js: 82: 7 на FSReqWrap.oncomplete (fs.js: 82: 15)

Я что-то упустил или поступаю неправильно?

Ответы на вопрос(2)

Ваш ответ на вопрос