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

Commit

Permalink
Reenable watcher tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xzyfer committed Feb 14, 2017
1 parent a11a3a8 commit 68d52b3
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 66 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
"object-merge": "^2.5.1",
"read-yaml": "^1.0.0",
"rimraf": "^2.5.2",
"sass-spec": "3.5.0-1"
"sass-spec": "3.5.0-1",
"touch": "^1.0.0",
"unique-temp-dir": "^1.0.0"
}
}
157 changes: 92 additions & 65 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var assert = require('assert'),
stream = require('stream'),
spawn = require('cross-spawn'),
cli = path.join(__dirname, '..', 'bin', 'node-sass'),
touch = require('touch'),
tmpDir = require('unique-temp-dir'),
fixture = path.join.bind(null, __dirname, 'fixtures');

describe('cli', function() {
Expand Down Expand Up @@ -226,53 +228,57 @@ describe('cli', function() {
}, 100);
});

it.skip('should emit `warn` on file change when using --watch option', function(done) {
var src = fixture('simple/tmp.scss');

fs.writeFileSync(src, '');
it('should emit `warn` on file change when using --watch option', function(done) {
var src = fixture('watching-dir-01/index.scss');

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

bin.stderr.setEncoding('utf8');
bin.stderr.once('data', function(data) {
assert.strictEqual(data.trim(), '=> changed: ' + src);
fs.unlinkSync(src);
bin.kill();
});
bin.on('error', function(err) {
assert.fail(err);
done();
});
bin.on('exit', done);

setTimeout(function() {
fs.appendFileSync(src, 'body {}');
touch.sync(src);
}, 500);
});
}).timeout(5000);

it.skip('should emit nothing on file change when using --watch and --quiet options', function(done) {
var src = fixture('simple/tmp.scss');
var didEmit = false;
fs.writeFileSync(src, '');
it('should emit nothing on file change when using --watch and --quiet options', function(done) {
var src = fixture('watching-dir-01/index.scss');

var bin = spawn(cli, ['--watch', '--quiet', src]);

bin.stderr.setEncoding('utf8');
bin.stderr.once('data', function() {
didEmit = true;
assert.fail('should not emit console output with --quiet flag');
});
bin.on('error', function(err) {
assert.fail(err);
done();
});
bin.on('exit', done);

setTimeout(function() {
fs.appendFileSync(src, 'body {}');
setTimeout(function() {
assert.equal(didEmit, false);
bin.kill();
done();
fs.unlinkSync(src);
}, 200);
touch(src, {}, function(err) {
if (err) {
assert.fail(err);
}

setTimeout(function() {
bin.kill();
}, 1000);
});
}, 500);
});
}).timeout(5000);

it.skip('should render all watched files', function(done) {
var src = fixture('simple/bar.scss');

fs.writeFileSync(src, '');
it('should render all watched files', function(done) {
var src = fixture('watching-dir-01/index.scss');

var bin = spawn(cli, [
'--output-style', 'compressed',
Expand All @@ -281,45 +287,48 @@ describe('cli', function() {

bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function(data) {
assert.strictEqual(data.trim(), 'body{background:white}');
fs.unlinkSync(src);
assert.strictEqual(data.trim(), 'a{color:green}');
bin.kill();
});
bin.on('error', function(err) {
assert.fail(err);
done();
});
bin.on('exit', done);

setTimeout(function() {
fs.appendFileSync(src, 'body{background:white}');
touch.sync(src);
}, 500);
});
}).timeout(5000);

it.skip('should watch the full scss dep tree for a single file (scss)', function(done) {
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');

fs.writeFileSync(foo, '');

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

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

setTimeout(function() {
fs.appendFileSync(foo, 'body{background:blue}\n');
touch.sync(foo);
}, 500);
});
}).timeout(5000);

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

fs.writeFileSync(foo, '');
var child = fixture('watching/bar.sass');

var bin = spawn(cli, [
'--output-style', 'compressed',
Expand All @@ -328,66 +337,84 @@ describe('cli', function() {

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

setTimeout(function() {
fs.appendFileSync(foo, 'body\n\tbackground: red\n');
touch.sync(child);
}, 500);
});
});
}).timeout(5000);

describe('node-sass --output directory', function() {
it.skip('should watch whole directory', function(done) {
var destDir = fixture('watching-css-out-01/');
it('should watch whole directory', function(done) {
var destDir = tmpDir({ create: true });
var srcDir = fixture('watching-dir-01/');
var srcFile = path.join(srcDir, 'index.scss');

fs.writeFileSync(srcFile, '');

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

bin.stdout.setEncoding('utf8');
bin.stdout.once('data', function() {
assert.fail('should not emit console output when watching a directory');
});
bin.on('error', assert.fail);

setTimeout(function() {
fs.appendFileSync(srcFile, 'a {color:green;}\n');
setTimeout(function() {
bin.kill();
var files = fs.readdirSync(destDir);
assert.deepEqual(files, ['index.css']);
rimraf(destDir, done);
}, 200);
touch(srcFile, {}, function(err) {
if (err) {
assert.fail(err);
}

setTimeout(function() {
fs.readdir(destDir, function(err, files) {
assert.deepEqual(files, ['index.css']);
rimraf(destDir, done);
});
bin.kill();
}, 500);
});
}, 500);
});
}).timeout(5000);

it.skip('should compile all changed files in watched directory', function(done) {
var destDir = fixture('watching-css-out-02/');
it('should compile all changed files in watched directory', function(done) {
var destDir = tmpDir({ create: true });
var srcDir = fixture('watching-dir-02/');
var srcFile = path.join(srcDir, 'foo.scss');

fs.writeFileSync(srcFile, '');

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

setTimeout(function () {
fs.appendFileSync(srcFile, 'body{background:white}\n');
setTimeout(function () {
bin.kill();
var files = fs.readdirSync(destDir);
assert.deepEqual(files, ['foo.css', 'index.css']);
rimraf(destDir, done);
}, 200);
touch(srcFile, {}, function(err) {
if (err) {
assert.fail(err);
}

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

describe('node-sass in.scss --output out.css', function() {
it('should compile a scss file to build.css', function(done) {
Expand Down

0 comments on commit 68d52b3

Please sign in to comment.