Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize test cases to follow a pattern when they can. #22

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions test/add_test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
'use strict';

var Gaze = require('../lib/gaze.js').Gaze;
var Gaze = require('../lib/gaze.js');
var path = require('path');
var fs = require('fs');
var gaze;

exports.add = {
setUp: function(done) {
process.chdir(path.resolve(__dirname, 'fixtures'));
done();
},
tearDown: function(done) {
gaze.close();
gaze = null;
done();
},
addToWatched: function(test) {
test.expect(1);
var files = [
Expand All @@ -27,20 +33,19 @@ exports.add = {
'nested/': ['one.js', 'three.js', 'sub/'],
'nested/sub/': ['two.js']
};
var gaze = new Gaze('addnothingtowatch');
gaze = Gaze('thiswillnevermatchanyfile');
gaze._addToWatched(files);
test.deepEqual(gaze.relative(null, true), expected);
test.done();
},
addLater: function(test) {
test.expect(3);
new Gaze('sub/one.js', function(err, watcher) {
gaze = Gaze('sub/one.js', function(err, watcher) {
test.deepEqual(watcher.relative('sub'), ['one.js']);
watcher.add('sub/*.js', function() {
test.deepEqual(watcher.relative('sub'), ['one.js', 'two.js']);
watcher.on('changed', function(filepath) {
test.equal('two.js', path.basename(filepath));
watcher.close();
test.done();
});
fs.writeFileSync(path.resolve(__dirname, 'fixtures', 'sub', 'two.js'), 'var two = true;');
Expand Down
19 changes: 11 additions & 8 deletions test/api_test.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,40 @@
'use strict';

var gaze = require('../lib/gaze.js');
var Gaze = require('../lib/gaze.js');
var path = require('path');
var gaze;

exports.api = {
setUp: function(done) {
process.chdir(path.resolve(__dirname, 'fixtures'));
done();
},
tearDown: function(done) {
gaze.close();
gaze = null;
done();
},
newGaze: function(test) {
test.expect(2);
new gaze.Gaze('**/*', {}, function() {
gaze = new Gaze.Gaze('**/*', {}, function() {
var result = this.relative(null, true);
test.deepEqual(result['.'], ['Project (LO)/', 'nested/', 'one.js', 'sub/']);
test.deepEqual(result['sub/'], ['one.js', 'two.js']);
this.close();
test.done();
});
},
func: function(test) {
test.expect(1);
var g = gaze('**/*', function(err, watcher) {
gaze = Gaze('**/*', function(err, watcher) {
test.deepEqual(watcher.relative('sub', true), ['one.js', 'two.js']);
g.close();
test.done();
});
},
ready: function(test) {
test.expect(1);
var g = new gaze.Gaze('**/*');
g.on('ready', function(watcher) {
gaze = new Gaze.Gaze('**/*');
gaze.on('ready', function(watcher) {
test.deepEqual(watcher.relative('sub', true), ['one.js', 'two.js']);
this.close();
test.done();
});
}
Expand Down
43 changes: 22 additions & 21 deletions test/matching_test.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,57 @@
'use strict';

var gaze = require('../lib/gaze.js');
var Gaze = require('../lib/gaze.js');
var path = require('path');
var gaze;

exports.matching = {
setUp: function(done) {
process.chdir(path.resolve(__dirname, 'fixtures'));
done();
},
tearDown: function(done) {
gaze.close();
gaze = null;
done();
},
globAll: function(test) {
test.expect(2);
gaze('**/*', function() {
var result = this.relative(null, true);
gaze = Gaze('**/*', function(err, watcher) {
var result = watcher.relative(null, true);
test.deepEqual(result['.'], ['Project (LO)/', 'nested/', 'one.js', 'sub/']);
test.deepEqual(result['sub/'], ['one.js', 'two.js']);
this.close();
test.done();
});
},
relativeDir: function(test) {
test.expect(1);
gaze('**/*', function() {
test.deepEqual(this.relative('sub', true), ['one.js', 'two.js']);
this.close();
gaze = Gaze('**/*', function(err, watcher) {
test.deepEqual(watcher.relative('sub', true), ['one.js', 'two.js']);
test.done();
});
},
globArray: function(test) {
test.expect(2);
gaze(['*.js', 'sub/*.js'], function() {
var result = this.relative(null, true);
gaze = Gaze(['*.js', 'sub/*.js'], function(err, watcher) {
var result = watcher.relative(null, true);
test.deepEqual(result['.'], ['one.js']);
test.deepEqual(result['sub/'], ['one.js', 'two.js']);
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.close();
test.done();
});
},
test.expect(1);
gaze = Gaze(['sub/*.js'], function(err, watcher) {
var result = watcher.relative(null, true);
test.deepEqual(result['sub/'], ['one.js', 'two.js']);
test.done();
});
},
oddName: function(test) {
test.expect(1);
gaze(['Project (LO)/*.js'], function() {
var result = this.relative(null, true);
gaze = Gaze(['Project (LO)/*.js'], function(err, watcher) {
var result = watcher.relative(null, true);
test.deepEqual(result['Project (LO)/'], ['one.js']);
this.close();
test.done();
});
}
Expand Down
32 changes: 17 additions & 15 deletions test/relative_test.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
'use strict';

var Gaze = require('../lib/gaze.js').Gaze;
var Gaze = require('../lib/gaze.js');
var path = require('path');
var gaze;

exports.relative = {
setUp: function(done) {
process.chdir(path.resolve(__dirname, 'fixtures'));
done();
},
tearDown: function(done) {
gaze.close();
gaze = null;
done();
},
relative: function(test) {
test.expect(1);
var files = [
'Project (LO)/',
'Project (LO)/one.js',
'nested/',
'nested/one.js',
'nested/three.js',
'nested/sub/',
'nested/sub/two.js',
'one.js'
];
var gaze = new Gaze('addnothingtowatch');
gaze._addToWatched(files);
test.deepEqual(gaze.relative('.', true), ['Project (LO)/', 'nested/', 'one.js']);
test.done();
gaze = Gaze(['**/*.js'], function(err, watcher) {
test.deepEqual(watcher.relative(null, true), {
'Project (LO)/': ['one.js'],
'nested/': ['one.js', 'three.js'],
'nested/sub/': ['two.js'],
'.': ['one.js'],
'sub/': ['one.js', 'two.js']
});
test.done();
});
}
};
22 changes: 14 additions & 8 deletions test/rename_test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
'use strict';

var gaze = require('../lib/gaze.js');
var Gaze = require('../lib/gaze.js');
var path = require('path');
var fs = require('fs');

var gaze;
// Node v0.6 compat
fs.existsSync = fs.existsSync || path.existsSync;

// Clean up helper to call in setUp and tearDown
function cleanUp(done) {
function deleteFiles(done) {
[
'sub/rename.js',
'sub/renamed.js'
Expand All @@ -22,22 +22,28 @@ function cleanUp(done) {
exports.watch = {
setUp: function(done) {
process.chdir(path.resolve(__dirname, 'fixtures'));
cleanUp(done);
deleteFiles(done);
},
tearDown: function(done) {
gaze.close();
gaze = null;
deleteFiles(done);
},
tearDown: cleanUp,
rename: function(test) {
test.expect(2);

var oldPath = path.join(__dirname, 'fixtures', 'sub', 'rename.js');
var newPath = path.join(__dirname, 'fixtures', 'sub', 'renamed.js');
fs.writeFileSync(oldPath, 'var rename = true;');
gaze('**/*', function(err, watcher) {

gaze = Gaze('**/*.js', function(err, watcher) {
watcher.on('renamed', function(newFile, oldFile) {
test.equal(newFile, newPath);
test.equal(oldFile, oldPath);
watcher.close();
test.done();
});
fs.renameSync(oldPath, newPath);
});

fs.writeFileSync(oldPath, 'var rename = true;');
}
};
19 changes: 11 additions & 8 deletions test/safewrite_test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
'use strict';

var gaze = require('../lib/gaze.js');
var Gaze = require('../lib/gaze.js');
var path = require('path');
var fs = require('fs');
var gaze;

// Node v0.6 compat
fs.existsSync = fs.existsSync || path.existsSync;

// Clean up helper to call in setUp and tearDown
function cleanUp(done) {
function deleteFiles(done) {
[
'safewrite.js'
].forEach(function(d) {
Expand All @@ -21,9 +22,13 @@ function cleanUp(done) {
exports.safewrite = {
setUp: function(done) {
process.chdir(path.resolve(__dirname, 'fixtures'));
cleanUp(done);
deleteFiles(done);
},
tearDown: function(done) {
gaze.close();
gaze = null;
deleteFiles(done);
},
tearDown: cleanUp,
safewrite: function(test) {
test.expect(4);

Expand All @@ -39,23 +44,21 @@ exports.safewrite = {
times++;
}

gaze('**/*', function() {
this.on('all', function(action, filepath) {
gaze = Gaze('**/*', function(err, watcher) {
watcher.on('all', function(action, filepath) {
test.equal(action, 'changed');
test.equal(path.basename(filepath), 'safewrite.js');

if (times < 2) {
setTimeout(simSafewrite, 1000);
} else {
this.close();
test.done();
}
});

setTimeout(function() {
simSafewrite();
}, 1000);

});
}
};
Loading