Skip to content

Commit

Permalink
Wait until all listeners are removed before finishing test. Closes GH-71
Browse files Browse the repository at this point in the history
.
  • Loading branch information
tschaub authored and shama committed Feb 6, 2014
1 parent 623c7fa commit dbe8964
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
7 changes: 4 additions & 3 deletions test/add_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ exports.add = {
gaze._addToWatched(files);
var result = gaze.relative(null, true);
test.deepEqual(sortobj(result), sortobj(expected));
test.done();
gaze.on('end', test.done);
gaze.close();
},
addLater: function(test) {
test.expect(3);
Expand All @@ -45,8 +46,8 @@ exports.add = {
test.deepEqual(watcher.relative('sub'), ['one.js', 'two.js']);
watcher.on('changed', function(filepath) {
test.equal('two.js', path.basename(filepath));
watcher.on('end', test.done);
watcher.close();
test.done();
});
fs.writeFileSync(path.resolve(__dirname, 'fixtures', 'sub', 'two.js'), 'var two = true;');
});
Expand All @@ -58,8 +59,8 @@ exports.add = {
this.add('sub/two.js');
this.on('changed', function(filepath) {
test.equal('two.js', path.basename(filepath));
watcher.on('end', test.done);
watcher.close();
test.done();
});
setTimeout(function() {
fs.writeFileSync(path.resolve(__dirname, 'fixtures', 'sub', 'two.js'), 'var two = true;');
Expand Down
6 changes: 3 additions & 3 deletions test/api_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ exports.api = {
var result = this.relative(null, true);
test.deepEqual(result['.'], ['Project (LO)/', 'nested/', 'one.js', 'sub/']);
test.deepEqual(result['sub/'], ['one.js', 'two.js']);
this.on('end', test.done);
this.close();
test.done();
});
},
func: function(test) {
test.expect(1);
var g = gaze('**/*', function(err, watcher) {
test.deepEqual(watcher.relative('sub', true), ['one.js', 'two.js']);
g.on('end', test.done);
g.close();
test.done();
});
},
ready: function(test) {
test.expect(1);
var g = new gaze.Gaze('**/*');
g.on('ready', function(watcher) {
test.deepEqual(watcher.relative('sub', true), ['one.js', 'two.js']);
this.on('end', test.done);
this.close();
test.done();
});
},
nomatch: function(test) {
Expand Down
10 changes: 5 additions & 5 deletions test/matching_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ exports.matching = {
var result = this.relative(null, true);
test.deepEqual(result['.'], ['Project (LO)/', 'nested/', 'one.js', 'sub/']);
test.deepEqual(result['sub/'], ['one.js', 'two.js']);
this.on('end', test.done);
this.close();
test.done();
});
},
relativeDir: function(test) {
test.expect(1);
gaze('**/*', function() {
test.deepEqual(this.relative('sub', true), ['one.js', 'two.js']);
this.on('end', test.done);
this.close();
test.done();
});
},
globArray: function(test) {
Expand All @@ -50,26 +50,26 @@ exports.matching = {
var result = this.relative(null, true);
test.deepEqual(sortobj(result['.']), sortobj(['one.js', 'Project (LO)/', 'nested/', 'sub/']));
test.deepEqual(sortobj(result['sub/']), sortobj(['one.js', 'two.js']));
this.on('end', test.done);
this.close();
test.done();
});
},
globArrayDot: function(test) {
test.expect(1);
gaze(['./sub/*.js'], function() {
var result = this.relative(null, true);
test.deepEqual(result['sub/'], ['one.js', 'two.js']);
this.on('end', test.done);
this.close();
test.done();
});
},
oddName: function(test) {
test.expect(1);
gaze(['Project (LO)/*.js'], function() {
var result = this.relative(null, true);
test.deepEqual(result['Project (LO)/'], ['one.js']);
this.on('end', test.done);
this.close();
test.done();
});
},
addedLater: function(test) {
Expand Down
3 changes: 2 additions & 1 deletion test/relative_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ exports.relative = {
var gaze = new Gaze('addnothingtowatch');
gaze._addToWatched(files);
test.deepEqual(gaze.relative('.', true), ['Project (LO)/', 'nested/', 'one.js', 'sub/']);
test.done();
gaze.on('end', test.done);
gaze.close();
}
};
2 changes: 1 addition & 1 deletion test/rename_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ exports.watch = {
watcher.on('renamed', function(newFile, oldFile) {
test.equal(newFile, newPath);
test.equal(oldFile, oldPath);
watcher.on('end', test.done);
watcher.close();
test.done();
});
fs.renameSync(oldPath, newPath);
});
Expand Down
2 changes: 1 addition & 1 deletion test/safewrite_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ exports.safewrite = {
if (times < 2) {
setTimeout(simSafewrite, 1000);
} else {
this.on('end', test.done);
this.close();
test.done();
}
});

Expand Down
5 changes: 3 additions & 2 deletions test/watch_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ exports.watch = {
var result = this.relative(null, true);
test.deepEqual(result['sub/'], ['one.js']);
test.notDeepEqual(result['.'], ['one.js']);
this.on('end', test.done);
this.close();
test.done();
});
},
changed: function(test) {
Expand Down Expand Up @@ -163,7 +163,8 @@ exports.watch = {
test.expect(1);
gaze('non/existent/**/*', function(err, watcher) {
test.ok(true);
test.done();
watcher.on('end', test.done);
watcher.close();
});
},
differentCWD: function(test) {
Expand Down

0 comments on commit dbe8964

Please sign in to comment.