Skip to content

Commit

Permalink
Prefer tests alongside source
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabriskie committed Jun 19, 2015
1 parent 14e720d commit 49489e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
28 changes: 24 additions & 4 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
var fs = require('fs');
var path = require('path');
var test = path.join(process.cwd(), 'specs/main.js');
var REGEX_TEST = /\-test\.js$/;

function findTests(dir) {
var tests = [];
fs.readdirSync(dir).forEach(function (file) {
file = path.resolve(dir, file);
var stat = fs.statSync(file);
if (stat && stat.isDirectory()) {
tests = tests.concat(findTests(file));
} else if (REGEX_TEST.test(file)) {
tests.push(file);
}
});
return tests;
}

var tests = findTests(path.resolve(process.cwd(), 'lib'));

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

frameworks: ['mocha'],

files: [test],
files: tests,

preprocessors: {},

reporters: ['progress'],
reporters: ['dots'],

port: 9876,

Expand All @@ -29,6 +46,7 @@ module.exports = function(config) {

webpack: {
cache: true,
devtool: 'inline-source-map',
module: {
loaders: [
{
Expand All @@ -47,7 +65,9 @@ module.exports = function(config) {
}
};

conf.preprocessors[test] = ['webpack'];
tests.forEach(function (test) {
conf.preprocessors[test] = ['webpack', 'sourcemap'];
});

config.set(conf);
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"karma-opera-launcher": "^0.1.0",
"karma-phantomjs-launcher": "^0.2.0",
"karma-safari-launcher": "^0.1.1",
"karma-sourcemap-loader": "^0.3.5",
"karma-webpack": "^1.5.1",
"minimist": "^1.1.1",
"mocha": "^2.2.5",
Expand Down

0 comments on commit 49489e3

Please sign in to comment.