2016-09-15 27 views
8

के साथ कर्म वेबपैक के लिए कवरेज कॉन्फ़िगर करें मैं कोणीय 2 + वेबपैक के साथ कर्म-कवरेज कैसे स्थापित करूं?कोणीय 2

मैंने कोणीय से क्विकस्टार्ट वेबपैक मार्गदर्शिका का पालन किया। लेकिन कवरेज टूल खाली है और मेरे परीक्षण प्रदर्शित नहीं करता है। धन्यवाद!

मेरी फ़ोल्डर संरचना

project 
|--src (project files) 
|--tests (all my testfiles) 

मेरी webpack.test.js इस

var helpers = require('./helpers'); 

module.exports = { 
    devtool: 'inline-source-map', 

    resolve: { 
     extensions: ['', '.ts', '.js'] 
    }, 

    module: { 
     loaders: [ 
      { 
       test: /\.ts$/, 
       loaders: ['ts'] 
      }, 
      { 
       test: /\.html$/, 
       loader: 'null' 

      }, 
      { 
       test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/, 
       loader: 'null' 
      }, 
      { 
       test: /\.css$/, 
       exclude: helpers.root('src', 'app'), 
       loader: 'null' 
      }, 
      { 
       test: /\.css$/, 
       include: helpers.root('src', 'app'), 
       loader: 'null' 
      } 
     ] 
    } 
} 

तरह लग रहा है मेरी Karma.conf.js

var webpackConfig = require('./webpack.test'); 

module.exports = function (config) { 
    var _config = { 
     basePath: '', 

     frameworks: ['jasmine', 'sinon'], 

     files: [ 
      {pattern: './config/karma-test-shim.js', watched: false} 
     ], 
     preprocessors: { 
      './config/karma-test-shim.js': ['webpack', 'sourcemap'] 
     }, 
     plugins:[ 
      require('karma-jasmine'), 
      require('karma-coverage'), 
      require('karma-webpack'), 
      require('karma-phantomjs-launcher'), 
      require('karma-sourcemap-loader'), 
      require('karma-mocha-reporter'), 
      require('karma-sinon') 
     ], 

     coverageReporter: { 
      type : 'html', 
      dir : 'coverage/' 
     }, 

     webpack: webpackConfig, 

     webpackMiddleware: { 
      stats: 'errors-only' 
     }, 

     webpackServer: { 
      noInfo: true 
     }, 

     reporters: ['mocha','coverage'], 
     port: 9876, 
     colors: true, 
     logLevel: config.LOG_INFO, 
     autoWatch: true, 
     browsers: ['PhantomJS'], 
     singleRun: false 
    }; 

    config.set(_config); 
}; 

और कर्म-परीक्षण है shim.js

Error.stackTraceLimit = Infinity; 

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

require('zone.js/dist/zone'); 
require('zone.js/dist/long-stack-trace-zone'); 
require('zone.js/dist/proxy'); 
require('zone.js/dist/sync-test'); 
require('zone.js/dist/jasmine-patch'); 
require('zone.js/dist/async-test'); 
require('zone.js/dist/fake-async-test'); 

var testContext = require.context('../tests', true, /\.spec\.ts/); 

testContext.keys().forEach(testContext); 

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

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

हां, उदाहरण मेरे लिए भी काम नहीं कर रहा है। मुझे इसके बारे में एक त्रुटि मिली: 0 त्रुटि 0 को निष्पादित किया गया। लेकिन मैंने आधिकारिक दस्तावेज में सबकुछ किया। – Velidan

+0

क्या आपने डाउनलोड करने का प्रयास किया? https://angular.io/generated/zips/webpack/webpack.zip फिर npm इंस्टॉल करें, फिर npm रन बिल्ड करें, फिर npm test? यह काम मेरे लिए ठीक काम किया। मैं मतभेदों के लिए काम निकालने वाले ज़िप को मिटा दूंगा। – JGFMK

उत्तर

0

Yuu प्लगइन्स

require('karma-coverage-istanbul-reporter'), 

इसके अलावा में कोड कवरेज प्लगइन नीचे आयात करने की आवश्यकता, कोड के नीचे उपयोग के रूप में

coverageIstanbulReporter: { 
     reports: ['html', 'lcovonly'], 
     fixWebpackSourcePaths: true, 
     // enforce percentage thresholds 
     // anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode 
     thresholds: { 
      emitWarning: false, // set to `true` to not fail the test command when thresholds are not met 
      global: { // thresholds for all files 
       statements: 80, 
       lines: 80, 
       branches: 80, 
       functions: 80 
      }, 
      each: { // thresholds per file 
       statements: 80, 
       lines: 80, 
       branches: 80, 
       functions: 80, 
       overrides: {} 
      } 
     } 
    }, 

नीचे karma.config.js के लिए पूर्ण config होना चाहिए इस्तांबुल संवाददाता संपत्ति जोड़ने के लिए नीचे:

// Karma configuration file, see link for more information 
// https://karma-runner.github.io/0.13/config/configuration-file.html 

module.exports = function(config) { 
    config.set({ 
     basePath: '', 
     frameworks: ['jasmine', '@angular/cli'], 
     plugins: [ 
      require('karma-jasmine'), 
      require('karma-chrome-launcher'), 
      require('karma-jasmine-html-reporter'), 
      require('karma-coverage-istanbul-reporter'), 
      require('@angular/cli/plugins/karma'), 
      require('karma-htmlfile-reporter'), 
     ], 
     client: { 
      clearContext: false // leave Jasmine Spec Runner output visible in browser 
     }, 
     coverageIstanbulReporter: { 
      reports: ['html', 'lcovonly'], 
      fixWebpackSourcePaths: true, 
      // enforce percentage thresholds 
      // anything under these percentages will cause karma to fail with an exit code of 1 if not running in watch mode 
      thresholds: { 
       emitWarning: false, // set to `true` to not fail the test command when thresholds are not met 
       global: { // thresholds for all files 
        statements: 80, 
        lines: 80, 
        branches: 80, 
        functions: 80 
       }, 
       each: { // thresholds per file 
        statements: 80, 
        lines: 80, 
        branches: 80, 
        functions: 80, 
        overrides: {} 
       } 
      } 
     }, 
     angularCli: { 
      environment: 'dev' 
     }, 
     // reporters: config.angularCli && config.angularCli.codeCoverage ? ['spec', 'karma-remap-istanbul'] : ['spec'], 
     // reporters: ['mocha'], 
     reporters: ['progress', 'html', 'kjhtml'], 
     htmlReporter: { 
      outputFile: 'testreports/report.html', 
      // Optional 
      pageTitle: 'Rest Reports', 
      subPageTitle: 'Suite-wise report ', 
      groupSuites: true, 
      useCompactStyle: true, 
      useLegacyStyle: false 
     }, 
     port: 9876, 
     colors: true, 
     logLevel: config.LOG_INFO, 
     autoWatch: true, 
     browsers: ['Chrome'], 
     singleRun: false 
    }); 
};