Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
aaa
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyfer committed Feb 23, 2017
1 parent a540f83 commit 731a73c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
4 changes: 4 additions & 0 deletions bin/node-sass
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ function watch(options, emitter) {
gaze.on('deleted', function() {
graph = buildGraph(options);
});

if (!options.quiet) {
console.log('Watching', options.directory || options.src);
}
}

/**
Expand Down
67 changes: 36 additions & 31 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,27 @@ describe('cli', function() {

it('should watch the full scss dep tree for a single file (scss)', function(done) {
var src = fixture('watching/index.scss');
var foo = fixture('watching/white.scss');
var child = fixture('watching/white.scss');

var bin = spawn(cli, [
'--output-style', 'compressed',
'--watch', src
]);

bin.stdout.setEncoding('utf8');
bin.stdout.on('data', function(data) {
assert.strictEqual(data.trim(), 'body{background:white}');
bin.kill();
bin.stdout.once('data', function() {
touch(child, function() {
bin.stdout.once('data', function(data) {
assert.strictEqual(data.trim(), 'body{background:white}');
bin.kill();
});
});
});
bin.on('error', function(err) {
assert.fail(err);
done();
});
bin.on('exit', done);

setTimeout(function() {
touch.sync(foo);
}, 500);
}).timeout(5000);

it('should watch the full sass dep tree for a single file (sass)', function(done) {
Expand All @@ -337,9 +337,13 @@ describe('cli', function() {
]);

bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) {
assert.strictEqual(data.trim(), 'body{background:white}');
bin.kill();
bin.stdout.once('data', function() {
touch(child, function() {
bin.stdout.once('data', function(data) {
assert.strictEqual(data.trim(), 'body{background:white}');
bin.kill();
});
});
});
bin.on('error', function(err) {
assert.fail(err);
Expand All @@ -358,6 +362,7 @@ describe('cli', function() {
var destDir = tmpDir({ create: true });
var srcDir = fixture('watching-dir-01/');
var srcFile = path.join(srcDir, 'index.scss');
var w;

var bin = spawn(cli, [
'--output-style', 'compressed',
Expand All @@ -366,24 +371,25 @@ describe('cli', function() {
]);

bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function() {
assert.fail('should not emit console output when watching a directory');
bin.stdout.once('data', function(data) {
assert.equal('Watching ' + srcDir, data.trim());
touch(srcFile, function() {
bin.stdout.once('data', function() {
assert.fail('should not emit console output when watching a directory');
});
});
});
bin.on('error', assert.fail);
bin.on('exit', w.close);


fs.watch(destDir, once(function() {
w = fs.watch(destDir, function() {
bin.kill();
fs.readdir(destDir, function(err, files) {
assert.deepEqual(files, ['index.css']);
rimraf(destDir, done);
});
}));

setTimeout(function() {
touch.sync(srcFile);
}, 500);
});
});
}).timeout(5000);

it('should compile all changed files in watched directory', function(done) {
var destDir = tmpDir({ create: true });
Expand All @@ -402,17 +408,16 @@ describe('cli', function() {
});
bin.on('error', assert.fail);


fs.watch(destDir, once(function() {
bin.kill();
fs.readdir(destDir, function(err, files) {
assert.deepEqual(files, ['foo.css', 'index.css']);
rimraf(destDir, done);
});
}));

setTimeout(function() {
touch.sync(srcFile);
setTimeout(function() {
bin.kill();
fs.readdir(destDir, function(err, files) {
assert.deepEqual(files, ['foo.css', 'index.css']);
rimraf(destDir, done);
});
}, 1000);

spawn('node', ['-e', 'require("touch").sync("' + srcFile + '")']);
}, 500);
});
});
Expand Down

0 comments on commit 731a73c

Please sign in to comment.