@@ -5,8 +5,11 @@ var assert = require('assert'),
5
5
glob = require ( 'glob' ) ,
6
6
rimraf = require ( 'rimraf' ) ,
7
7
stream = require ( 'stream' ) ,
8
+ once = require ( 'lodash.once' ) ,
8
9
spawn = require ( 'cross-spawn' ) ,
9
10
cli = path . join ( __dirname , '..' , 'bin' , 'node-sass' ) ,
11
+ touch = require ( 'touch' ) ,
12
+ tmpDir = require ( 'unique-temp-dir' ) ,
10
13
fixture = path . join . bind ( null , __dirname , 'fixtures' ) ;
11
14
12
15
describe ( 'cli' , function ( ) {
@@ -226,165 +229,196 @@ describe('cli', function() {
226
229
} , 100 ) ;
227
230
} ) ;
228
231
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 , '' ) ;
232
+ it ( 'should emit `warn` on file change when using --watch option' , function ( done ) {
233
+ var src = fixture ( 'watching-dir-01/index.scss' ) ;
233
234
234
235
var bin = spawn ( cli , [ '--watch' , src ] ) ;
235
236
236
237
bin . stderr . setEncoding ( 'utf8' ) ;
237
238
bin . stderr . once ( 'data' , function ( data ) {
238
239
assert . strictEqual ( data . trim ( ) , '=> changed: ' + src ) ;
239
- fs . unlinkSync ( src ) ;
240
240
bin . kill ( ) ;
241
+ } ) ;
242
+ bin . on ( 'error' , function ( err ) {
243
+ assert . fail ( err ) ;
241
244
done ( ) ;
242
245
} ) ;
246
+ bin . on ( 'exit' , done ) ;
243
247
244
248
setTimeout ( function ( ) {
245
- fs . appendFileSync ( src , 'body {}' ) ;
249
+ touch . sync ( src ) ;
246
250
} , 500 ) ;
247
- } ) ;
251
+ } ) . timeout ( 5000 ) ;
248
252
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 , '' ) ;
253
+ it ( 'should emit nothing on file change when using --watch and --quiet options' , function ( done ) {
254
+ var src = fixture ( 'watching-dir-01/index.scss' ) ;
253
255
254
256
var bin = spawn ( cli , [ '--watch' , '--quiet' , src ] ) ;
255
257
256
258
bin . stderr . setEncoding ( 'utf8' ) ;
257
259
bin . stderr . once ( 'data' , function ( ) {
258
- didEmit = true ;
260
+ assert . fail ( 'should not emit console output with --quiet flag' ) ;
261
+ } ) ;
262
+ bin . on ( 'error' , function ( err ) {
263
+ assert . fail ( err ) ;
264
+ done ( ) ;
259
265
} ) ;
266
+ bin . on ( 'exit' , done ) ;
260
267
261
268
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 ) ;
269
+ touch ( src , { } , function ( err ) {
270
+ if ( err ) {
271
+ assert . fail ( err ) ;
272
+ }
273
+
274
+ setTimeout ( function ( ) {
275
+ bin . kill ( ) ;
276
+ } , 1000 ) ;
277
+ } ) ;
269
278
} , 500 ) ;
270
- } ) ;
279
+ } ) . timeout ( 5000 ) ;
271
280
272
- it . skip ( 'should render all watched files' , function ( done ) {
273
- var src = fixture ( 'simple/bar .scss' ) ;
281
+ it ( 'should render all watched files' , function ( done ) {
282
+ var src = fixture ( 'watching-dir-01/index .scss' ) ;
274
283
275
- fs . writeFileSync ( src , '' ) ;
276
-
277
- var bin = spawn ( cli , [
278
- '--output-style' , 'compressed' ,
279
- '--watch' , src
280
- ] ) ;
284
+ var bin = spawn ( cli , [ '--output-style' , 'compressed' , '--watch' , src ] ) ;
281
285
282
286
bin . stdout . setEncoding ( 'utf8' ) ;
283
287
bin . stdout . once ( 'data' , function ( data ) {
284
- assert . strictEqual ( data . trim ( ) , 'body{background:white}' ) ;
285
- fs . unlinkSync ( src ) ;
288
+ assert . strictEqual ( data . trim ( ) , 'a{color:green}' ) ;
286
289
bin . kill ( ) ;
290
+ } ) ;
291
+ bin . on ( 'error' , function ( err ) {
292
+ assert . fail ( err ) ;
287
293
done ( ) ;
288
294
} ) ;
295
+ bin . on ( 'exit' , done ) ;
289
296
290
297
setTimeout ( function ( ) {
291
- fs . appendFileSync ( src , 'body{background:white}' ) ;
298
+ touch . sync ( src ) ;
292
299
} , 500 ) ;
293
- } ) ;
300
+ } ) . timeout ( 5000 ) ;
294
301
295
- it . skip ( 'should watch the full scss dep tree for a single file (scss)' , function ( done ) {
302
+ it ( 'should watch the full scss dep tree for a single file (scss)' , function ( done ) {
296
303
var src = fixture ( 'watching/index.scss' ) ;
297
- var foo = fixture ( 'watching/white.scss' ) ;
298
-
299
- fs . writeFileSync ( foo , '' ) ;
304
+ var child = fixture ( 'watching/white.scss' ) ;
300
305
301
306
var bin = spawn ( cli , [
302
307
'--output-style' , 'compressed' ,
303
308
'--watch' , src
304
309
] ) ;
305
310
306
311
bin . stdout . setEncoding ( 'utf8' ) ;
307
- bin . stdout . once ( 'data' , function ( data ) {
308
- assert . strictEqual ( data . trim ( ) , 'body{background:blue}' ) ;
309
- bin . kill ( ) ;
312
+ bin . stdout . once ( 'data' , function ( ) {
313
+ touch ( child , function ( ) {
314
+ bin . stdout . once ( 'data' , function ( data ) {
315
+ assert . strictEqual ( data . trim ( ) , 'body{background:white}' ) ;
316
+ bin . kill ( ) ;
317
+ } ) ;
318
+ } ) ;
319
+ } ) ;
320
+ bin . on ( 'error' , function ( err ) {
321
+ assert . fail ( err ) ;
310
322
done ( ) ;
311
323
} ) ;
324
+ bin . on ( 'exit' , done ) ;
325
+ } ) . timeout ( 5000 ) ;
312
326
313
- setTimeout ( function ( ) {
314
- fs . appendFileSync ( foo , 'body{background:blue}\n' ) ;
315
- } , 500 ) ;
316
- } ) ;
317
-
318
- it . skip ( 'should watch the full sass dep tree for a single file (sass)' , function ( done ) {
327
+ it ( 'should watch the full sass dep tree for a single file (sass)' , function ( done ) {
319
328
var src = fixture ( 'watching/index.sass' ) ;
320
- var foo = fixture ( 'watching/bar.sass' ) ;
321
-
322
- fs . writeFileSync ( foo , '' ) ;
329
+ var child = fixture ( 'watching/bar.sass' ) ;
323
330
324
331
var bin = spawn ( cli , [
325
332
'--output-style' , 'compressed' ,
326
333
'--watch' , src
327
334
] ) ;
328
335
329
336
bin . stdout . setEncoding ( 'utf8' ) ;
330
- bin . stdout . once ( 'data' , function ( data ) {
331
- assert . strictEqual ( data . trim ( ) , 'body{background:red}' ) ;
332
- bin . kill ( ) ;
337
+ bin . stdout . once ( 'data' , function ( ) {
338
+ touch ( child , function ( ) {
339
+ bin . stdout . once ( 'data' , function ( data ) {
340
+ assert . strictEqual ( data . trim ( ) , 'body{background:white}' ) ;
341
+ bin . kill ( ) ;
342
+ } ) ;
343
+ } ) ;
344
+ } ) ;
345
+ bin . on ( 'error' , function ( err ) {
346
+ assert . fail ( err ) ;
333
347
done ( ) ;
334
348
} ) ;
349
+ bin . on ( 'exit' , done ) ;
335
350
336
351
setTimeout ( function ( ) {
337
- fs . appendFileSync ( foo , 'body\n\tbackground: red\n' ) ;
352
+ touch . sync ( child ) ;
338
353
} , 500 ) ;
339
354
} ) ;
340
- } ) ;
355
+ } ) . timeout ( 5000 ) ;
341
356
342
357
describe ( 'node-sass --output directory' , function ( ) {
343
- it . skip ( 'should watch whole directory' , function ( done ) {
344
- var destDir = fixture ( 'watching-css-out-01/' ) ;
358
+ it ( 'should watch whole directory' , function ( done ) {
359
+ var destDir = tmpDir ( {
360
+ create : true
361
+ } ) ;
345
362
var srcDir = fixture ( 'watching-dir-01/' ) ;
346
363
var srcFile = path . join ( srcDir , 'index.scss' ) ;
347
-
348
- fs . writeFileSync ( srcFile , '' ) ;
364
+ var w ;
349
365
350
366
var bin = spawn ( cli , [
351
367
'--output-style' , 'compressed' ,
352
368
'--output' , destDir ,
353
369
'--watch' , srcDir
354
370
] ) ;
355
371
356
- setTimeout ( function ( ) {
357
- fs . appendFileSync ( srcFile , 'a {color:green;}\n' ) ;
358
- setTimeout ( function ( ) {
359
- bin . kill ( ) ;
360
- var files = fs . readdirSync ( destDir ) ;
372
+ bin . stdout . setEncoding ( 'utf8' ) ;
373
+ bin . stdout . once ( 'data' , function ( data ) {
374
+ assert . equal ( 'Watching ' + srcDir , data . trim ( ) ) ;
375
+ touch ( srcFile , function ( ) {
376
+ bin . stdout . once ( 'data' , function ( ) {
377
+ assert . fail ( 'should not emit console output when watching a directory' ) ;
378
+ } ) ;
379
+ } ) ;
380
+ } ) ;
381
+ bin . on ( 'error' , assert . fail ) ;
382
+ bin . on ( 'exit' , w . close ) ;
383
+
384
+ w = fs . watch ( destDir , function ( ) {
385
+ bin . kill ( ) ;
386
+ fs . readdir ( destDir , function ( err , files ) {
361
387
assert . deepEqual ( files , [ 'index.css' ] ) ;
362
388
rimraf ( destDir , done ) ;
363
- } , 200 ) ;
364
- } , 500 ) ;
365
- } ) ;
389
+ } ) ;
390
+ } ) ;
391
+ } ) . timeout ( 5000 ) ;
366
392
367
- it . skip ( 'should compile all changed files in watched directory' , function ( done ) {
368
- var destDir = fixture ( 'watching-css-out-02/' ) ;
393
+ it ( 'should compile all changed files in watched directory' , function ( done ) {
394
+ var destDir = tmpDir ( {
395
+ create : true
396
+ } ) ;
369
397
var srcDir = fixture ( 'watching-dir-02/' ) ;
370
398
var srcFile = path . join ( srcDir , 'foo.scss' ) ;
371
399
372
- fs . writeFileSync ( srcFile , '' ) ;
373
-
374
400
var bin = spawn ( cli , [
375
401
'--output-style' , 'compressed' ,
376
402
'--output' , destDir ,
377
403
'--watch' , srcDir
378
404
] ) ;
379
405
380
- setTimeout ( function ( ) {
381
- fs . appendFileSync ( srcFile , 'body{background:white}\n' ) ;
382
- setTimeout ( function ( ) {
406
+ bin . stdout . setEncoding ( 'utf8' ) ;
407
+ bin . stdout . once ( 'data' , function ( ) {
408
+ assert . fail ( 'should not emit console output when watching a directory' ) ;
409
+ } ) ;
410
+ bin . on ( 'error' , assert . fail ) ;
411
+
412
+ setTimeout ( function ( ) {
413
+ setTimeout ( function ( ) {
383
414
bin . kill ( ) ;
384
- var files = fs . readdirSync ( destDir ) ;
385
- assert . deepEqual ( files , [ 'foo.css' , 'index.css' ] ) ;
386
- rimraf ( destDir , done ) ;
387
- } , 200 ) ;
415
+ fs . readdir ( destDir , function ( err , files ) {
416
+ assert . deepEqual ( files , [ 'foo.css' , 'index.css' ] ) ;
417
+ rimraf ( destDir , done ) ;
418
+ } ) ;
419
+ } , 1000 ) ;
420
+
421
+ spawn ( 'node' , [ '-e' , 'require("touch").sync("' + srcFile + '")' ] ) ;
388
422
} , 500 ) ;
389
423
} ) ;
390
424
} ) ;
0 commit comments