patterns_test.js
1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
var gaze = require('../lib/gaze.js');
var path = require('path');
var fs = require('fs');
// Clean up helper to call in setUp and tearDown
function cleanUp(done) {
[
'added.js',
'nested/added.js',
].forEach(function(d) {
var p = path.resolve(__dirname, 'fixtures', d);
if (fs.existsSync(p)) { fs.unlinkSync(p); }
});
done();
}
exports.patterns = {
setUp: function(done) {
process.chdir(path.resolve(__dirname, 'fixtures'));
cleanUp(done);
},
tearDown: cleanUp,
negate: function(test) {
test.expect(1);
gaze(['**/*.js', '!nested/**/*.js'], function(err, watcher) {
watcher.on('added', function(filepath) {
var expected = path.relative(process.cwd(), filepath);
test.equal(path.join('added.js'), expected);
watcher.close();
});
// dont add
fs.writeFileSync(path.resolve(__dirname, 'fixtures', 'nested', 'added.js'), 'var added = true;');
setTimeout(function() {
// should add
fs.writeFileSync(path.resolve(__dirname, 'fixtures', 'added.js'), 'var added = true;');
}, 1000);
watcher.on('end', test.done);
});
}
};