2017-01-17 6 views
1

После поиска основной части вопросов, связанных с stackoverflow. Похоже, что это довольно распространенная проблема, но никто не дал никаких ответов. Я не могу создать точный отчет о покрытии кода для моей среды Angular2.Angular2 Karma Code Coverage показывает только модели, модули и сервисы

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

Но мои файлы компонентов исключены из отчета. Включая те, которые имеют соответствующие файлы спецификаций.

Любые предложения были бы наиболее ценными.

karma.conf.js

module.exports = function(config) { 
    var testWebpackConfig = require('./webpack.test.js'); 

    config.set({ 
     // base path that will be used to resolve all patterns (e.g. files, exclude) 
     basePath: '', 

     /* 
     * Frameworks to use 
     * 
     * available frameworks: https://npmjs.org/browse/keyword/karma-adapter 
     */ 
     frameworks: ['jasmine'], 

     // list of files to exclude 
     exclude: [ ], 

     /* 
     * list of files/patterns to load in the browser 
     * 
     * we are building the test environment in ./spec-bundle.ts 
     */ 
     files: [ { pattern: './config/spec-bundle.ts', watched: false } ], 

     /* 
     * preprocess matching files before serving them to the browser 
     * available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 
     */ 
     preprocessors: { './config/spec-bundle.ts': ['coverage', 'webpack', 'sourcemap'] }, 

     // Webpack Config at ./webpack.test.js 
     webpack: testWebpackConfig, 

     coverageReporter: { 
     dir : 'coverage/', 
     reporters: [ 
      { type: 'text-summary' }, 
      { type: 'json' }, 
      { type: 'html' } 
     ] 
     }, 

     // Webpack please don't spam the console when running in karma! 
     webpackServer: { noInfo: true }, 

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

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

     /* 
     * start these browsers 
     * available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 
     */ 
     browsers: [ 
     //'Chrome', 
     //'PhantomJS' 
     'IE' 
     ], 

     trxReporter: { 
      outputFile: 'test/test-results.trx', 
      shortTestName: false 
     }, 

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

}; 

Spec-bundle.ts

/* 
* When testing with webpack and ES6, we have to do some extra 
* things get testing to work right. Because we are gonna write test 
* in ES6 to, we have to compile those as well. That's handled in 
* karma.conf.js with the karma-webpack plugin. This is the entry 
* file for webpack test. Just like webpack will create a bundle.js 
* file for our client, when we run test, it well compile and bundle them 
* all here! Crazy huh. So we need to do some setup 
*/ 
Error.stackTraceLimit = Infinity; 

require('phantomjs-polyfill'); 

require('core-js/es6'); 
require('core-js/es7/reflect'); 

// Typescript emit helpers polyfill 
require('ts-helpers'); 

// DO NOT REORDER: Dependency order needs to be strictly followed 
require('zone.js/dist/zone'); 
require('zone.js/dist/long-stack-trace-zone'); 
require('zone.js/dist/async-test'); 
require('zone.js/dist/fake-async-test'); 
require('zone.js/dist/sync-test'); 
require('zone.js/dist/proxy'); 
require('zone.js/dist/jasmine-patch'); 

// RxJS 
require('rxjs/Rx'); 

var testing = require('@angular/core/testing'); 
var browser = require('@angular/platform-browser-dynamic/testing'); 

testing.TestBed.initTestEnvironment(
    browser.BrowserDynamicTestingModule, 
    browser.platformBrowserDynamicTesting() 
); 

Object.assign(global, testing); 

if (window.__karma__) require('./karma-require'); 

karma.require.js

/* 
* Ok, this is kinda crazy. We can use the the context method on 
* require that webpack created in order to tell webpack 
* what files we actually want to require or import. 
* Below, context will be an function/object with file names as keys. 
* using that regex we are saying look in ./src/app and ./test then find 
* any file that ends with spec.js and get its path. By passing in true 
* we say do this recursively 
*/ 
var testContext = require.context('../src', true, /\.spec\.ts/); 

/* 
* get all the files, for each file, call the context function 
* that will require the file and load it up here. Context will 
* loop and require those spec files here 
*/ 
function requireAll(requireContext) { 
    return requireContext.keys().map(requireContext); 
} 

// requires and returns all modules that match 
var modules = requireAll(testContext); 

ответ