From 49489e35676ed1d567def41ca431112d52d86389 Mon Sep 17 00:00:00 2001 From: mzabriskie Date: Thu, 18 Jun 2015 18:03:05 -0600 Subject: [PATCH] Prefer tests alongside source --- karma.conf.js | 28 ++++++++++++++++++++++++---- package.json | 1 + 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/karma.conf.js b/karma.conf.js index 829e398..afc5b5f 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -1,5 +1,22 @@ +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 = { @@ -7,11 +24,11 @@ module.exports = function(config) { frameworks: ['mocha'], - files: [test], + files: tests, preprocessors: {}, - reporters: ['progress'], + reporters: ['dots'], port: 9876, @@ -29,6 +46,7 @@ module.exports = function(config) { webpack: { cache: true, + devtool: 'inline-source-map', module: { loaders: [ { @@ -47,7 +65,9 @@ module.exports = function(config) { } }; - conf.preprocessors[test] = ['webpack']; + tests.forEach(function (test) { + conf.preprocessors[test] = ['webpack', 'sourcemap']; + }); config.set(conf); }; diff --git a/package.json b/package.json index cecb3ea..3c2e545 100644 --- a/package.json +++ b/package.json @@ -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",