UNPKG

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