From c608a9e5a34a49da2971add8759a9422b74fa6fd Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Tue, 12 Mar 2013 20:17:31 -0700 Subject: [PATCH] fix(preprocessor): resolve relative patterns to basePath Closes #382 --- lib/config.js | 10 +++++++--- test/unit/config.spec.coffee | 21 +++++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/config.js b/lib/config.js index aaaf91078..49d60fbf4 100644 --- a/lib/config.js +++ b/lib/config.js @@ -104,11 +104,15 @@ var normalizeConfig = function(config) { log.warn('"reporter" is deprecated, use "reporters" instead'); } + // normalize preprocessors var preprocessors = config.preprocessors || {}; + var normalizedPreprocessors = config.preprocessors = Object.create(null); + Object.keys(preprocessors).forEach(function(pattern) { - if (helper.isString(preprocessors[pattern])) { - preprocessors[pattern] = [preprocessors[pattern]]; - } + var normalizedPattern = helper.normalizeWinPath(basePathResolve(pattern)); + + normalizedPreprocessors[normalizedPattern] = helper.isString(preprocessors[pattern]) ? + [preprocessors[pattern]] : preprocessors[pattern]; }); return config; diff --git a/test/unit/config.spec.coffee b/test/unit/config.spec.coffee index c6b75b625..e98e477b2 100644 --- a/test/unit/config.spec.coffee +++ b/test/unit/config.spec.coffee @@ -272,12 +272,25 @@ describe 'config', -> it 'should normalize preprocessors to an array', -> config = normalizeConfigWithDefaults + basePath: '' preprocessors: - '**/*.coffee': 'coffee' - '**/*.html': 'html2js' + '/*.coffee': 'coffee' + '/*.html': 'html2js' - expect(config.preprocessors['**/*.coffee']).to.deep.equal ['coffee'] - expect(config.preprocessors['**/*.html']).to.deep.equal ['html2js'] + expect(config.preprocessors['/*.coffee']).to.deep.equal ['coffee'] + expect(config.preprocessors['/*.html']).to.deep.equal ['html2js'] + + + it 'should resolve relative preprocessor patterns', -> + config = normalizeConfigWithDefaults + basePath: '/some/base' + preprocessors: + '*.coffee': 'coffee' + '/**/*.html': 'html2js' + + expect(config.preprocessors).to.have.property '/some/base/*.coffee' + expect(config.preprocessors).not.to.have.property '*.coffee' + expect(config.preprocessors).to.have.property '/**/*.html' describe 'createPatternObject', ->