1 | 'use strict';
|
2 |
|
3 | var Gaze = require('../lib/gaze.js').Gaze;
|
4 | var path = require('path');
|
5 | var fs = require('fs');
|
6 |
|
7 | exports.add = {
|
8 | setUp: function(done) {
|
9 | process.chdir(path.resolve(__dirname, 'fixtures'));
|
10 | done();
|
11 | },
|
12 | addToWatched: function(test) {
|
13 | test.expect(1);
|
14 | var files = [
|
15 | 'Project (LO)/',
|
16 | 'Project (LO)/one.js',
|
17 | 'nested/',
|
18 | 'nested/one.js',
|
19 | 'nested/three.js',
|
20 | 'nested/sub/',
|
21 | 'nested/sub/two.js',
|
22 | 'one.js'
|
23 | ];
|
24 | var expected = {
|
25 | 'Project (LO)/': ['one.js'],
|
26 | '.': ['Project (LO)/', 'nested/', 'one.js'],
|
27 | 'nested/': ['one.js', 'three.js', 'sub/'],
|
28 | 'nested/sub/': ['two.js']
|
29 | };
|
30 | var gaze = new Gaze('addnothingtowatch');
|
31 | gaze._addToWatched(files);
|
32 | test.deepEqual(gaze.relative(null, true), expected);
|
33 | test.done();
|
34 | },
|
35 | addLater: function(test) {
|
36 | test.expect(3);
|
37 | new Gaze('sub/one.js', function(err, watcher) {
|
38 | test.deepEqual(watcher.relative('sub'), ['one.js']);
|
39 | watcher.add('sub/*.js', function() {
|
40 | test.deepEqual(watcher.relative('sub'), ['one.js', 'two.js']);
|
41 | watcher.on('changed', function(filepath) {
|
42 | test.equal('two.js', path.basename(filepath));
|
43 | watcher.close();
|
44 | test.done();
|
45 | });
|
46 | fs.writeFileSync(path.resolve(__dirname, 'fixtures', 'sub', 'two.js'), 'var two = true;');
|
47 | });
|
48 | });
|
49 | }
|
50 | };
|