From 160c38b5ca9308dfa565dafedea43f3e4f44edfb Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Wed, 27 May 2015 18:26:28 -0700 Subject: [PATCH] build(broccoli): improve error messaging from TreeDiffer --- tools/broccoli/tree-differ.spec.ts | 11 +++++++++++ tools/broccoli/tree-differ.ts | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/broccoli/tree-differ.spec.ts b/tools/broccoli/tree-differ.spec.ts index b80fe0d01b..661036e26a 100644 --- a/tools/broccoli/tree-differ.spec.ts +++ b/tools/broccoli/tree-differ.spec.ts @@ -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': { diff --git a/tools/broccoli/tree-differ.ts b/tools/broccoli/tree-differ.ts index f83243cbc4..912fad9601 100644 --- a/tools/broccoli/tree-differ.ts +++ b/tools/broccoli/tree-differ.ts @@ -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;