Angular2 Karma Code Coverage仅显示模型,模块和服务

时间:2017-01-17 21:54:23

标签: angular karma-coverage

搜索了大量的stackoverflow问题。看起来这是一个相当普遍的问题,但没有人提供任何答案。我无法为Angular2环境生成准确的代码覆盖率报告。

目前,我的报告仅显示模块,模型和服务的结果。即使是那些没有spec文件的人。

但是我的组件文件被排除在报告之外。包括具有相应spec文件的那些。

任何建议都会受到最高的赞赏。

karma.conf.js

cli::array<int, 3>^ arrimg(System::Drawing::Bitmap^ image)
{
    const int w = image->Width;
    const int h = image->Height;
    const int z = 3;
    auto dtab = gcnew cli::array<int, 3>(w, h, z);
    for (int x = 0; x<image->Width; x++)
    {
        for (int y = 0; y<image->Height; y++)
        {
            dtab[x, y, 0] = image->GetPixel(x, y).R;
            dtab[x, y, 1] = image->GetPixel(x, y).G;
            dtab[x, y, 2] = image->GetPixel(x, y).B;
        }
    }
    return dtab;
}

SPEC-bundle.ts

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

};

karma.require.js

/*
 * 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');

1 个答案:

答案 0 :(得分:0)

也许它可以提供帮助,我的预处理器看起来像这样:

preprocessors: {
  'dist/dev/app/!(frameworks)/**/!(*spec|*module|*routes).js': 'coverage'
},

另请查看https://github.com/karma-runner/karma-coverage/blob/master/docs/configuration.md#includeallsources