angularjs - How to split code coverage by separate files for Angular, Karma and Webpack? -


how can split coverage separate files? right working fine bundle file. using angular, webpack bundling , karma/mocha/chai testing.

i have following webpack.config:

module.exports = {     entry: {         public: "./application/src/public.js",         office: "./application/src/office.js"     },     output: {         path: "./client/javascripts/",         filename: "[name].js",         sourcemapfilename: "[name].js.map"     } }; 

and following karma.conf.js:

module.exports = function(config) { config.set({     basepath: "",     frameworks: ["mocha", "chai"],     reporters: ["mocha", "coverage"],     files: [         "./client/libs/angular/angular.js",         "./client/libs/angular-route/angular-route.js",         "./client/libs/angular-animate/angular-animate.js",         "./client/libs/angular-cookies/angular-cookies.js",         "./client/libs/angular-mocks/angular-mocks.js",         "./client/libs/angular-messages/angular-messages.js",         "./client/javascripts/office.js", /* bundle */         "./application/**/*_tests.js"     ],     preprocessors: {         "./client/javascripts/office.js": ["coverage"]     },     coveragereporter: {         type: "html",         dir: "coverage/"     },     exclude: [],     port: 9876,     colors: true,     loglevel: config.log_info,     autowatch: true,     browsers: ["phantomjs"],     singlerun: false }); }; 

sample test file:

describe("accountloginctrl", function() {         beforeeach(angular.mock.module("staccount"));          var $controller;         var accountloginctrl;         var $scope;          beforeeach(angular.mock.inject(function(_$controller_) {             $controller = _$controller_;             $scope = {};             accountloginctrl = $controller("accountloginctrl", {                 $scope: $scope             });         }));          it("should exist", function() {             expect(accountloginctrl).to.exist;         });     }); 

settup folder structure:

karma.conf.js ./application     ./src         ./components         entry.js     ./tests         index.js         ./components     ./coverage 

add index.js in tests folder entry point tests.

// adds test files bundle. var testscontext = require.context("./components", true, /\.js$/); testscontext.keys().foreach(testscontext);  // adds application bundle. var componentscontext = require("../src/entry");  

karma.conf.js

var path = require("path"); module.exports = function(config) {     config.set({         basepath: "",         frameworks: ["mocha"],         reporters: ["mocha", "coverage"],         files: [             "./client/libs/angular/angular.js",             "./client/libs/angular-route/angular-route.js",             "./client/libs/angular-animate/angular-animate.js",             "./client/libs/angular-cookies/angular-cookies.js",             "./client/libs/angular-mocks/angular-mocks.js",             "./client/libs/angular-messages/angular-messages.js",             "./application/tests/index.js",         ],         preprocessors: {             "./application/tests/index.js": ["webpack"]         },         webpack: {             module: {                 preloaders: [                     {                         test: /\.js$/,                         include: path.resolve("./application/src/"),                         loader: "isparta"                     }                 ]             }          },         webpackmiddleware: {             noinfo: true         },         coveragereporter: {             type: "html",             dir: "./application/coverage/"         },         exclude: [],         port: 9876,         colors: true,         loglevel: config.log_info,         autowatch: true,         browsers: ["phantomjs"],         singlerun: false     }); }; 

package.json

{ "devdependencies": {     "chai": "^3.4.0",      "isparta-loader": "^1.0.0",     "karma": "^0.13.12",     "karma-coverage": "^0.5.3",     "karma-mocha": "^0.2.0",     "karma-mocha-reporter": "^1.1.1",     "karma-phantomjs-launcher": "^0.2.1",     "karma-webpack": "^1.7.0",     "mocha": "^2.3.3",     "phantomjs": "^1.9.18",     "webpack": "^1.12.2"   } } 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -