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
.

Conflicts:

	test/add_test.js
	test/relative_test.js
	test/safewrite_test.js
  • Loading branch information
tschaub authored and shama committed Feb 17, 2014
1 parent 2468d17 commit 45954ea
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions test/add_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,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 @@ -34,8 +34,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', '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
2 changes: 1 addition & 1 deletion test/rename_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,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
1 change: 1 addition & 0 deletions test/safewrite_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports.safewrite = {
}

gaze('**/*', function(err, watcher) {
this.on('end', test.done);
this.on('all', function(action, filepath) {
test.equal(action, 'changed');
test.equal(path.basename(filepath), 'safewrite.js');
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 @@ -164,7 +164,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 45954ea

Please sign in to comment.