Skip to content

Commit

Permalink
Add some more tests for Watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
albe committed Sep 26, 2019
1 parent a0d52bf commit f0fec22
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class DirectoryWatcher extends EventEmitter {
*/
constructor(directory, options = {}) {
directory = path.normalize(directory);
/* istanbul ignore if */
if (!fs.existsSync(directory)) {
throw new Error('Can not watch a non-existing directory.');
}
Expand Down
15 changes: 15 additions & 0 deletions test/Watcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,21 @@ describe('Watcher', function() {
expect(() => createWatcher('.file')).to.throwError();
});

it('throws if directory doesnt exist', function(){
expect(() => createWatcher('foo/')).to.throwError();
});

it('can be closed multiple times safely', function(){
const watcher = createWatcher('');
watcher.close();
expect(() => watcher.close()).to.not.throwError();
});

it('throws when trying to bind to invalid event', function(){
const watcher = createWatcher('');
expect(() => watcher.on('foo', () => null)).to.throwError();
});

it('detects changes to files inside a directory', function(done){
const fd = fs.openSync(dataDirectory + '/.file', 'w');
const watcher = createWatcher('');
Expand Down

0 comments on commit f0fec22

Please sign in to comment.