build(broccoli): improve error messaging from TreeDiffer

This commit is contained in:
Igor Minar 2015-05-27 18:26:28 -07:00
parent 9b0fa0dedc
commit 160c38b5ca
2 changed files with 14 additions and 1 deletions

View File

@ -177,6 +177,17 @@ describe('TreeDiffer', () => {
});
it("should throw an error if an extension isn't prefixed with doc", () => {
// includeExtensions
expect(() => new TreeDiffer('testLabel', 'dir1', ['js']))
.toThrowError("Extension must begin with '.'. Was: 'js'");
// excludeExtentions
expect(() => new TreeDiffer('testLabel', 'dir1', [], ['js']))
.toThrowError("Extension must begin with '.'. Was: 'js'");
});
it('should ignore files with extensions not listed in includeExtensions', () => {
let testDir = {
'dir1': {

View File

@ -31,7 +31,9 @@ export class TreeDiffer {
this.exclude = (excludeExtensions || []).length ? buildRegexp(excludeExtensions) : null;
function combine(prev, curr) {
if (curr.charAt(0) !== ".") throw new TypeError("Extension must begin with '.'");
if (curr.charAt(0) !== ".") {
throw new Error(`Extension must begin with '.'. Was: '${curr}'`);
}
let kSpecialRegexpChars = /[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g;
curr = '(' + curr.replace(kSpecialRegexpChars, '\\$&') + ')';
return prev ? (prev + '|' + curr) : curr;