Sets the structure of your folder:
karma.conf.js
./application
./src
./components
entry.js
./tests
index.js
./components
./coverage
Add index.js
to the folder tests
as an entry point for tests.
var testsContext = require.context("./components", true, /\.js$/);
testsContext.keys().forEach(testsContext);
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"
}
}