@@ -7,6 +7,8 @@ var assert = require('assert'),
7
7
stream = require ( 'stream' ) ,
8
8
spawn = require ( 'cross-spawn' ) ,
9
9
cli = path . join ( __dirname , '..' , 'bin' , 'node-sass' ) ,
10
+ touch = require ( 'touch' ) ,
11
+ tmpDir = require ( 'unique-temp-dir' ) ,
10
12
fixture = path . join . bind ( null , __dirname , 'fixtures' ) ;
11
13
12
14
describe ( 'cli' , function ( ) {
@@ -226,53 +228,57 @@ describe('cli', function() {
226
228
} , 100 ) ;
227
229
} ) ;
228
230
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' ) ;
233
233
234
234
var bin = spawn ( cli , [ '--watch' , src ] ) ;
235
235
236
236
bin . stderr . setEncoding ( 'utf8' ) ;
237
237
bin . stderr . once ( 'data' , function ( data ) {
238
238
assert . strictEqual ( data . trim ( ) , '=> changed: ' + src ) ;
239
- fs . unlinkSync ( src ) ;
240
239
bin . kill ( ) ;
240
+ } ) ;
241
+ bin . on ( 'error' , function ( err ) {
242
+ assert . fail ( err ) ;
241
243
done ( ) ;
242
244
} ) ;
245
+ bin . on ( 'exit' , done ) ;
243
246
244
247
setTimeout ( function ( ) {
245
- fs . appendFileSync ( src , 'body {}' ) ;
248
+ touch . sync ( src ) ;
246
249
} , 500 ) ;
247
- } ) ;
250
+ } ) . timeout ( 5000 ) ;
248
251
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' ) ;
253
254
254
255
var bin = spawn ( cli , [ '--watch' , '--quiet' , src ] ) ;
255
256
256
257
bin . stderr . setEncoding ( 'utf8' ) ;
257
258
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 ( ) ;
259
264
} ) ;
265
+ bin . on ( 'exit' , done ) ;
260
266
261
267
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
+ } ) ;
269
277
} , 500 ) ;
270
- } ) ;
278
+ } ) . timeout ( 5000 ) ;
271
279
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' ) ;
276
282
277
283
var bin = spawn ( cli , [
278
284
'--output-style' , 'compressed' ,
@@ -281,45 +287,48 @@ describe('cli', function() {
281
287
282
288
bin . stdout . setEncoding ( 'utf8' ) ;
283
289
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}' ) ;
286
291
bin . kill ( ) ;
292
+ } ) ;
293
+ bin . on ( 'error' , function ( err ) {
294
+ assert . fail ( err ) ;
287
295
done ( ) ;
288
296
} ) ;
297
+ bin . on ( 'exit' , done ) ;
289
298
290
299
setTimeout ( function ( ) {
291
- fs . appendFileSync ( src , 'body{background:white}' ) ;
300
+ touch . sync ( src ) ;
292
301
} , 500 ) ;
293
- } ) ;
302
+ } ) . timeout ( 5000 ) ;
294
303
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 ) {
296
305
var src = fixture ( 'watching/index.scss' ) ;
297
306
var foo = fixture ( 'watching/white.scss' ) ;
298
307
299
- fs . writeFileSync ( foo , '' ) ;
300
-
301
308
var bin = spawn ( cli , [
302
309
'--output-style' , 'compressed' ,
303
310
'--watch' , src
304
311
] ) ;
305
312
306
313
bin . stdout . setEncoding ( 'utf8' ) ;
307
314
bin . stdout . once ( 'data' , function ( data ) {
308
- assert . strictEqual ( data . trim ( ) , 'body{background:blue }' ) ;
315
+ assert . strictEqual ( data . trim ( ) , 'body{background:white }' ) ;
309
316
bin . kill ( ) ;
317
+ } ) ;
318
+ bin . on ( 'error' , function ( err ) {
319
+ assert . fail ( err ) ;
310
320
done ( ) ;
311
321
} ) ;
322
+ bin . on ( 'exit' , done ) ;
312
323
313
324
setTimeout ( function ( ) {
314
- fs . appendFileSync ( foo , 'body{background:blue}\n' ) ;
325
+ touch . sync ( foo ) ;
315
326
} , 500 ) ;
316
- } ) ;
327
+ } ) . timeout ( 5000 ) ;
317
328
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 ) {
319
330
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' ) ;
323
332
324
333
var bin = spawn ( cli , [
325
334
'--output-style' , 'compressed' ,
@@ -328,66 +337,84 @@ describe('cli', function() {
328
337
329
338
bin . stdout . setEncoding ( 'utf8' ) ;
330
339
bin . stdout . once ( 'data' , function ( data ) {
331
- assert . strictEqual ( data . trim ( ) , 'body{background:red }' ) ;
340
+ assert . strictEqual ( data . trim ( ) , 'body{background:white }' ) ;
332
341
bin . kill ( ) ;
342
+ } ) ;
343
+ bin . on ( 'error' , function ( err ) {
344
+ assert . fail ( err ) ;
333
345
done ( ) ;
334
346
} ) ;
347
+ bin . on ( 'exit' , done ) ;
335
348
336
349
setTimeout ( function ( ) {
337
- fs . appendFileSync ( foo , 'body\n\tbackground: red\n' ) ;
350
+ touch . sync ( child ) ;
338
351
} , 500 ) ;
339
352
} ) ;
340
- } ) ;
353
+ } ) . timeout ( 5000 ) ;
341
354
342
355
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 } ) ;
345
358
var srcDir = fixture ( 'watching-dir-01/' ) ;
346
359
var srcFile = path . join ( srcDir , 'index.scss' ) ;
347
360
348
- fs . writeFileSync ( srcFile , '' ) ;
349
-
350
361
var bin = spawn ( cli , [
351
362
'--output-style' , 'compressed' ,
352
363
'--output' , destDir ,
353
364
'--watch' , srcDir
354
365
] ) ;
355
366
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
+
356
373
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
+ } ) ;
364
387
} , 500 ) ;
365
- } ) ;
388
+ } ) . timeout ( 5000 ) ;
366
389
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 } ) ;
369
392
var srcDir = fixture ( 'watching-dir-02/' ) ;
370
393
var srcFile = path . join ( srcDir , 'foo.scss' ) ;
371
394
372
- fs . writeFileSync ( srcFile , '' ) ;
373
-
374
395
var bin = spawn ( cli , [
375
396
'--output-style' , 'compressed' ,
376
397
'--output' , destDir ,
377
398
'--watch' , srcDir
378
399
] ) ;
379
400
380
401
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
+ } ) ;
388
415
} , 500 ) ;
389
416
} ) ;
390
- } ) ;
417
+ } ) . timeout ( 5000 ) ;
391
418
392
419
describe ( 'node-sass in.scss --output out.css' , function ( ) {
393
420
it ( 'should compile a scss file to build.css' , function ( done ) {
0 commit comments