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

Commit 68d52b3

Browse files
committed
Reenable watcher tests
1 parent a11a3a8 commit 68d52b3

File tree

2 files changed

+95
-66
lines changed

2 files changed

+95
-66
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@
8181
"object-merge": "^2.5.1",
8282
"read-yaml": "^1.0.0",
8383
"rimraf": "^2.5.2",
84-
"sass-spec": "3.5.0-1"
84+
"sass-spec": "3.5.0-1",
85+
"touch": "^1.0.0",
86+
"unique-temp-dir": "^1.0.0"
8587
}
8688
}

test/cli.js

Lines changed: 92 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var assert = require('assert'),
77
stream = require('stream'),
88
spawn = require('cross-spawn'),
99
cli = path.join(__dirname, '..', 'bin', 'node-sass'),
10+
touch = require('touch'),
11+
tmpDir = require('unique-temp-dir'),
1012
fixture = path.join.bind(null, __dirname, 'fixtures');
1113

1214
describe('cli', function() {
@@ -226,53 +228,57 @@ describe('cli', function() {
226228
}, 100);
227229
});
228230

229-
it.skip('should emit `warn` on file change when using --watch option', function(done) {
230-
var src = fixture('simple/tmp.scss');
231-
232-
fs.writeFileSync(src, '');
231+
it('should emit `warn` on file change when using --watch option', function(done) {
232+
var src = fixture('watching-dir-01/index.scss');
233233

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

236236
bin.stderr.setEncoding('utf8');
237237
bin.stderr.once('data', function(data) {
238238
assert.strictEqual(data.trim(), '=> changed: ' + src);
239-
fs.unlinkSync(src);
240239
bin.kill();
240+
});
241+
bin.on('error', function(err) {
242+
assert.fail(err);
241243
done();
242244
});
245+
bin.on('exit', done);
243246

244247
setTimeout(function() {
245-
fs.appendFileSync(src, 'body {}');
248+
touch.sync(src);
246249
}, 500);
247-
});
250+
}).timeout(5000);
248251

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

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

256257
bin.stderr.setEncoding('utf8');
257258
bin.stderr.once('data', function() {
258-
didEmit = true;
259+
assert.fail('should not emit console output with --quiet flag');
260+
});
261+
bin.on('error', function(err) {
262+
assert.fail(err);
263+
done();
259264
});
265+
bin.on('exit', done);
260266

261267
setTimeout(function() {
262-
fs.appendFileSync(src, 'body {}');
263-
setTimeout(function() {
264-
assert.equal(didEmit, false);
265-
bin.kill();
266-
done();
267-
fs.unlinkSync(src);
268-
}, 200);
268+
touch(src, {}, function(err) {
269+
if (err) {
270+
assert.fail(err);
271+
}
272+
273+
setTimeout(function() {
274+
bin.kill();
275+
}, 1000);
276+
});
269277
}, 500);
270-
});
278+
}).timeout(5000);
271279

272-
it.skip('should render all watched files', function(done) {
273-
var src = fixture('simple/bar.scss');
274-
275-
fs.writeFileSync(src, '');
280+
it('should render all watched files', function(done) {
281+
var src = fixture('watching-dir-01/index.scss');
276282

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

282288
bin.stdout.setEncoding('utf8');
283289
bin.stdout.once('data', function(data) {
284-
assert.strictEqual(data.trim(), 'body{background:white}');
285-
fs.unlinkSync(src);
290+
assert.strictEqual(data.trim(), 'a{color:green}');
286291
bin.kill();
292+
});
293+
bin.on('error', function(err) {
294+
assert.fail(err);
287295
done();
288296
});
297+
bin.on('exit', done);
289298

290299
setTimeout(function() {
291-
fs.appendFileSync(src, 'body{background:white}');
300+
touch.sync(src);
292301
}, 500);
293-
});
302+
}).timeout(5000);
294303

295-
it.skip('should watch the full scss dep tree for a single file (scss)', function(done) {
304+
it('should watch the full scss dep tree for a single file (scss)', function(done) {
296305
var src = fixture('watching/index.scss');
297306
var foo = fixture('watching/white.scss');
298307

299-
fs.writeFileSync(foo, '');
300-
301308
var bin = spawn(cli, [
302309
'--output-style', 'compressed',
303310
'--watch', src
304311
]);
305312

306313
bin.stdout.setEncoding('utf8');
307314
bin.stdout.once('data', function(data) {
308-
assert.strictEqual(data.trim(), 'body{background:blue}');
315+
assert.strictEqual(data.trim(), 'body{background:white}');
309316
bin.kill();
317+
});
318+
bin.on('error', function(err) {
319+
assert.fail(err);
310320
done();
311321
});
322+
bin.on('exit', done);
312323

313324
setTimeout(function() {
314-
fs.appendFileSync(foo, 'body{background:blue}\n');
325+
touch.sync(foo);
315326
}, 500);
316-
});
327+
}).timeout(5000);
317328

318-
it.skip('should watch the full sass dep tree for a single file (sass)', function(done) {
329+
it('should watch the full sass dep tree for a single file (sass)', function(done) {
319330
var src = fixture('watching/index.sass');
320-
var foo = fixture('watching/bar.sass');
321-
322-
fs.writeFileSync(foo, '');
331+
var child = fixture('watching/bar.sass');
323332

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

329338
bin.stdout.setEncoding('utf8');
330339
bin.stdout.once('data', function(data) {
331-
assert.strictEqual(data.trim(), 'body{background:red}');
340+
assert.strictEqual(data.trim(), 'body{background:white}');
332341
bin.kill();
342+
});
343+
bin.on('error', function(err) {
344+
assert.fail(err);
333345
done();
334346
});
347+
bin.on('exit', done);
335348

336349
setTimeout(function() {
337-
fs.appendFileSync(foo, 'body\n\tbackground: red\n');
350+
touch.sync(child);
338351
}, 500);
339352
});
340-
});
353+
}).timeout(5000);
341354

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

348-
fs.writeFileSync(srcFile, '');
349-
350361
var bin = spawn(cli, [
351362
'--output-style', 'compressed',
352363
'--output', destDir,
353364
'--watch', srcDir
354365
]);
355366

367+
bin.stdout.setEncoding('utf8');
368+
bin.stdout.once('data', function() {
369+
assert.fail('should not emit console output when watching a directory');
370+
});
371+
bin.on('error', assert.fail);
372+
356373
setTimeout(function() {
357-
fs.appendFileSync(srcFile, 'a {color:green;}\n');
358-
setTimeout(function() {
359-
bin.kill();
360-
var files = fs.readdirSync(destDir);
361-
assert.deepEqual(files, ['index.css']);
362-
rimraf(destDir, done);
363-
}, 200);
374+
touch(srcFile, {}, function(err) {
375+
if (err) {
376+
assert.fail(err);
377+
}
378+
379+
setTimeout(function() {
380+
fs.readdir(destDir, function(err, files) {
381+
assert.deepEqual(files, ['index.css']);
382+
rimraf(destDir, done);
383+
});
384+
bin.kill();
385+
}, 500);
386+
});
364387
}, 500);
365-
});
388+
}).timeout(5000);
366389

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

372-
fs.writeFileSync(srcFile, '');
373-
374395
var bin = spawn(cli, [
375396
'--output-style', 'compressed',
376397
'--output', destDir,
377398
'--watch', srcDir
378399
]);
379400

380401
setTimeout(function () {
381-
fs.appendFileSync(srcFile, 'body{background:white}\n');
382-
setTimeout(function () {
383-
bin.kill();
384-
var files = fs.readdirSync(destDir);
385-
assert.deepEqual(files, ['foo.css', 'index.css']);
386-
rimraf(destDir, done);
387-
}, 200);
402+
touch(srcFile, {}, function(err) {
403+
if (err) {
404+
assert.fail(err);
405+
}
406+
407+
setTimeout(function() {
408+
bin.kill();
409+
fs.readdir(destDir, function(err, files) {
410+
assert.deepEqual(files, ['foo.css', 'index.css']);
411+
rimraf(destDir, done);
412+
});
413+
}, 500);
414+
});
388415
}, 500);
389416
});
390-
});
417+
}).timeout(5000);
391418

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

0 commit comments

Comments
 (0)