Getting Karma code coverage for pre-transpilation source code

前端 未结 1 1838
情深已故
情深已故 2021-02-04 15:41

I\'m using Karma to run tests, webpack to bundle files, and babel for es6 -> es5 transpilation. I\'ve got the tests running and code coverage being generated, but the code cove

1条回答
  •  既然无缘
    2021-02-04 16:08

    The following configuration works fine:

    karma.conf.js

    var path = require('path');
    
    module.exports = function(config) {
      config.set({
        browsers: [ 'Chrome' ], //run in Chrome
    
        files: [
          'src/**/*-test.js'
        ],
    
        frameworks: [ 'mocha' ], //use the mocha test framework
    
        preprocessors: {
          'src/**/*-test.js': [ 'webpack' ]
        },
    
        reporters: [ 'dots', 'coverage' ], //report results in this format
    
        coverageReporter: {
          reporters: [
            {
              type: 'text-summary'
            },
            {
              type: 'html',
              dir: 'build/reports/coverage'
            }
          ]
        },
    
        singleRun: true, //just run once by default
    
        webpack: {
          node : {
            fs: 'empty'
          },
    
          // Instrument code that isn't test or vendor code.
          module: {
            preLoaders: [
              { test: /\.js$/, loader: 'isparta', include: path.join(__dirname, 'src/js') }
            ],
            loaders: [
              {
                test: /\.js$/,
                include: path.join(__dirname, 'src/js'),
                loader: 'babel?stage=0'
              }
            ]
          }
        },
    
        webpackMiddleware: {
          noInfo: true //please don't spam the console when running in karma!
        }
      });
    };
    

    package.json

    {
      "devDependencies": {
        "babel-core": "^5.8.22",
        "babel-loader": "^5.3.2",
        "chai": "^3.2.0",
        "isparta-loader": "^0.2.0",
        "karma": "^0.13.9",
        "karma-chrome-launcher": "^0.2.0",
        "karma-coverage": "^0.5.0",
        "karma-mocha": "^0.2.0",
        "karma-webpack": "^1.7.0",
        "mocha": "^2.2.5",
        "webpack": "^1.11.0"
      }
    }
    

    0 讨论(0)
提交回复
热议问题