Skip to content

Commit

Permalink
Builder throws an error when a watched input directory is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
joliss committed Dec 1, 2016
1 parent 7cc793f commit 4a19947
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# master

* Builder throws an error when a watched input directory is missing
* Rework watcher
* Pull broccoli-sane-watcher functionality into core
* Update findup-sync dependency
Expand Down
19 changes: 19 additions & 0 deletions lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ function Builder(outputNode, options) {
// This populates this.nodeWrappers as a side effect
this.outputNodeWrapper = this.makeNodeWrapper(this.outputNode)

// Catching missing directories here helps prevent later errors when we set
// up the watcher.
this.checkInputPathsExist()

this.setupTmpDirs()

// Now that temporary directories are set up, we need to run the rest of the
Expand Down Expand Up @@ -210,6 +214,21 @@ Builder.prototype.makeNodeWrapper = function(node, _stack) {

Builder.prototype.features = broccoliNodeInfo.features

Builder.prototype.checkInputPathsExist = function() {
// We might consider checking this.unwatchedPaths as well.
for (var i = 0; i < this.watchedPaths.length; i++) {
var isDirectory
try {
isDirectory = fs.statSync(this.watchedPaths[i]).isDirectory()
} catch (err) {
throw new Builder.BuilderError('Directory not found: ' + this.watchedPaths[i])
}
if (!isDirectory) {
throw new Builder.BuilderError('Not a directory: ' + this.watchedPaths[i])
}
}
};

Builder.prototype.setupTmpDirs = function() {
// Create temporary directories for each node:
//
Expand Down
16 changes: 14 additions & 2 deletions test/builder_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,26 @@ describe('Builder', function() {
expect(builder.watchedPaths).to.deep.equal(['test/fixtures/basic'])
})

it('fails when a source directory doesn\'t exist', function() {
it('fails construction when a watched source directory doesn\'t exist', function() {
expect(function() {
new Builder(new broccoliSource.WatchedDir('test/fixtures/doesnotexist'))
}).to.throw(Builder.BuilderError, 'Directory not found: test/fixtures/doesnotexist')
})

it('fails construction when a watched source directory is a file', function() {
expect(function() {
new Builder(new broccoliSource.WatchedDir('test/fixtures/basic/foo.txt'))
}).to.throw(Builder.BuilderError, 'Not a directory: test/fixtures/basic/foo.txt')
})

it('fails when an unwatched source directory doesn\'t exist', function() {
builder = new Builder(new broccoliSource.UnwatchedDir('test/fixtures/doesnotexist'))
// Note: `ENOENT:` or `ENOENT,` depending on Node version
return expect(builder.build()).to.be.eventually.rejectedWith(Builder.BuildError,
/test\/fixtures\/doesnotexist: ENOENT. no such file or directory/)
})

it('fails when a source directory is a file', function() {
it('fails when an unwatched source directory is a file', function() {
builder = new Builder(new broccoliSource.UnwatchedDir('test/fixtures/basic/foo.txt'))
return expect(builder.build()).to.be.eventually.rejectedWith(Builder.BuildError,
/test\/fixtures\/basic\/foo\.txt: Not a directory/)
Expand Down

0 comments on commit 4a19947

Please sign in to comment.