build(broccoli): improve error messaging from TreeDiffer
This commit is contained in:
parent
9b0fa0dedc
commit
160c38b5ca
|
@ -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': {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue