add_test.js
2.0 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
'use strict';
var Gaze = require('../lib/gaze.js').Gaze;
var path = require('path');
var fs = require('fs');
var helper = require('./helper');
var fixtures = path.resolve(__dirname, 'fixtures');
var sortobj = helper.sortobj;
exports.add = {
setUp: function(done) {
process.chdir(fixtures);
done();
},
addToWatched: 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 expected = {
'Project (LO)/': ['one.js'],
'.': ['Project (LO)/', 'nested/', 'one.js', 'sub/'],
'nested/': ['sub/', 'sub2/', 'one.js', 'three.js'],
'nested/sub/': ['two.js'],
};
var gaze = new Gaze('addnothingtowatch');
gaze._addToWatched(files);
var result = gaze.relative(null, true);
test.deepEqual(sortobj(result), sortobj(expected));
test.done();
},
addLater: function(test) {
test.expect(3);
new 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;');
});
});
},
addNoCallback: function(test) {
test.expect(1);
new Gaze('sub/one.js', function(err, watcher) {
this.add('sub/two.js');
this.on('changed', function(filepath) {
test.equal('two.js', path.basename(filepath));
watcher.close();
test.done();
});
setTimeout(function() {
fs.writeFileSync(path.resolve(__dirname, 'fixtures', 'sub', 'two.js'), 'var two = true;');
}, 500);
});
},
};