Skip to content

Commit

Permalink
fix(preprocessor): resolve relative patterns to basePath
Browse files Browse the repository at this point in the history
Closes #382
  • Loading branch information
vojtajina committed Mar 13, 2013
1 parent 4dde160 commit c608a9e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
10 changes: 7 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 17 additions & 4 deletions test/unit/config.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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', ->
Expand Down

0 comments on commit c608a9e

Please sign in to comment.