matching_test.js
2.7 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
'use strict';
var gaze = require('../lib/gaze.js');
var grunt = require('grunt');
var path = require('path');
var helper = require('./helper');
var fixtures = path.resolve(__dirname, 'fixtures');
var sortobj = helper.sortobj;
function cleanUp(done) {
[
'newfolder',
].forEach(function(d) {
var p = path.join(fixtures, d);
if (grunt.file.exists(p)) {
grunt.file.delete(p);
}
});
done();
}
exports.matching = {
setUp: function(done) {
process.chdir(fixtures);
cleanUp(done);
},
tearDown: cleanUp,
globAll: function(test) {
test.expect(2);
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();
});
},
relativeDir: function(test) {
test.expect(1);
gaze('**/*', function() {
test.deepEqual(this.relative('sub', true), ['one.js', 'two.js']);
this.close();
test.done();
});
},
globArray: function(test) {
test.expect(2);
gaze(['*.js', 'sub/*.js'], function() {
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.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();
});
},
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.close();
test.done();
});
},
addedLater: function(test) {
test.expect(2);
var times = 0;
gaze('**/*.js', function(err, watcher) {
watcher.on('all', function(status, filepath) {
times++;
var result = watcher.relative(null, true);
test.deepEqual(result['newfolder/'], ['added.js']);
if (times > 1) { watcher.close(); }
});
grunt.file.write(path.join(fixtures, 'newfolder', 'added.js'), 'var added = true;');
setTimeout(function() {
grunt.file.write(path.join(fixtures, 'newfolder', 'added.js'), 'var added = true;');
}, 1000);
watcher.on('end', function() {
// TODO: Figure out why this test is finicky leaking it's newfolder into the other tests
setTimeout(test.done, 2000);
});
});
},
};