@@ -5,18 +5,15 @@ var assert = require('assert'),
5
5
glob = require ( 'glob' ) ,
6
6
rimraf = require ( 'rimraf' ) ,
7
7
stream = require ( 'stream' ) ,
8
- once = require ( 'lodash.once' ) ,
9
8
spawn = require ( 'cross-spawn' ) ,
10
9
cli = path . join ( __dirname , '..' , 'bin' , 'node-sass' ) ,
11
10
touch = require ( 'touch' ) ,
12
11
tmpDir = require ( 'unique-temp-dir' ) ,
13
12
fixture = path . join . bind ( null , __dirname , 'fixtures' ) ;
14
13
15
- describe . only ( 'cli' , function ( ) {
16
- // For some reason we experience random timeout failures in CI
17
- // due to spawn hanging/failing silently. See #1692.
18
- // this.retries(4);
14
+ process . env . NODE_ENV = 'test' ;
19
15
16
+ describe ( 'cli' , function ( ) {
20
17
describe ( 'node-sass < in.scss' , function ( ) {
21
18
it ( 'should read data from stdin' , function ( done ) {
22
19
var src = fs . createReadStream ( fixture ( 'simple/index.scss' ) ) ;
@@ -125,33 +122,11 @@ describe.only('cli', function() {
125
122
126
123
describe ( 'node-sass in.scss' , function ( ) {
127
124
it ( 'should compile a scss file' , function ( done ) {
128
- process . chdir ( fixture ( 'simple' ) ) ;
129
-
130
125
var src = fixture ( 'simple/index.scss' ) ;
131
- var dest = fixture ( 'simple/ index.css') ;
126
+ var dest = path . join ( tmpDir ( { create : true } ) , ' index.css') ;
132
127
var bin = spawn ( cli , [ src , dest ] ) ;
133
128
134
- bin . once ( 'close' , function ( ) {
135
- assert ( fs . existsSync ( dest ) ) ;
136
- fs . unlinkSync ( dest ) ;
137
- process . chdir ( __dirname ) ;
138
- done ( ) ;
139
- } ) ;
140
- } ) ;
141
-
142
- it ( 'should compile a scss file to custom destination' , function ( done ) {
143
- process . chdir ( fixture ( 'simple' ) ) ;
144
-
145
- var src = fixture ( 'simple/index.scss' ) ;
146
- var dest = fixture ( 'simple/index-custom.css' ) ;
147
- var bin = spawn ( cli , [ src , dest ] ) ;
148
-
149
- bin . once ( 'close' , function ( ) {
150
- assert ( fs . existsSync ( dest ) ) ;
151
- fs . unlinkSync ( dest ) ;
152
- process . chdir ( __dirname ) ;
153
- done ( ) ;
154
- } ) ;
129
+ bin . once ( 'close' , done ) ;
155
130
} ) ;
156
131
157
132
it ( 'should compile with the --include-path option' , function ( done ) {
@@ -167,45 +142,39 @@ describe.only('cli', function() {
167
142
bin . stdout . setEncoding ( 'utf8' ) ;
168
143
bin . stdout . once ( 'data' , function ( data ) {
169
144
assert . equal ( data . trim ( ) , expected . replace ( / \r \n / g, '\n' ) ) ;
170
- done ( ) ;
145
+ bin . kill ( ) ;
171
146
} ) ;
147
+ bin . on ( 'exit' , done ) ;
172
148
} ) ;
173
149
174
150
it ( 'should compile silently using the --quiet option' , function ( done ) {
175
- process . chdir ( fixture ( 'simple' ) ) ;
176
-
177
151
var src = fixture ( 'simple/index.scss' ) ;
178
- var dest = fixture ( 'simple/ index.css') ;
152
+ var dest = path . join ( tmpDir ( { create : true } ) , ' index.css') ;
179
153
var bin = spawn ( cli , [ src , dest , '--quiet' ] ) ;
180
- var didEmit = false ;
181
154
182
- bin . stderr . once ( 'data' , function ( ) {
183
- didEmit = true ;
155
+ bin . stderr . on ( 'data' , function ( data ) {
156
+ if ( ! / ^ T E S T I N G / . test ( data . toString ( ) ) ) {
157
+ assert . fail ( 'should not emit console output with --quiet flag' ) ;
158
+ }
184
159
} ) ;
185
160
186
- bin . once ( 'close' , function ( ) {
187
- assert . equal ( didEmit , false ) ;
188
- fs . unlinkSync ( dest ) ;
189
- process . chdir ( __dirname ) ;
190
- done ( ) ;
191
- } ) ;
161
+ bin . on ( 'close' , done ) ;
192
162
} ) ;
193
163
194
164
it ( 'should still report errors with the --quiet option' , function ( done ) {
195
- process . chdir ( fixture ( 'invalid' ) ) ;
196
-
197
165
var src = fixture ( 'invalid/index.scss' ) ;
198
- var dest = fixture ( 'invalid/ index.css') ;
166
+ var dest = path . join ( tmpDir ( { create : true } ) , ' index.css') ;
199
167
var bin = spawn ( cli , [ src , dest , '--quiet' ] ) ;
200
168
var didEmit = false ;
201
169
202
- bin . stderr . once ( 'data' , function ( ) {
203
- didEmit = true ;
170
+ bin . stderr . on ( 'data' , function ( data ) {
171
+ if ( ! / ^ T E S T I N G / . test ( data . toString ( ) ) ) {
172
+ didEmit = true ;
173
+ }
204
174
} ) ;
205
175
206
176
bin . once ( 'close' , function ( ) {
207
177
assert . equal ( didEmit , true ) ;
208
- process . chdir ( __dirname ) ;
209
178
done ( ) ;
210
179
} ) ;
211
180
} ) ;
@@ -219,14 +188,16 @@ describe.only('cli', function() {
219
188
exited = true ;
220
189
} ) ;
221
190
222
- setTimeout ( function ( ) {
223
- if ( exited ) {
224
- throw new Error ( 'Watch ended too early!' ) ;
225
- } else {
226
- bin . kill ( ) ;
227
- done ( ) ;
228
- }
229
- } , 100 ) ;
191
+ bin . stderr . once ( 'data' , function ( ) {
192
+ setTimeout ( function ( ) {
193
+ if ( exited ) {
194
+ throw new Error ( 'Watch ended too early!' ) ;
195
+ } else {
196
+ bin . kill ( ) ;
197
+ done ( ) ;
198
+ }
199
+ } , 100 ) ;
200
+ } ) ;
230
201
} ) ;
231
202
232
203
it ( 'should emit `warn` on file change when using --watch option' , function ( done ) {
@@ -235,8 +206,8 @@ describe.only('cli', function() {
235
206
var bin = spawn ( cli , [ '--watch' , src ] ) ;
236
207
237
208
bin . stderr . setEncoding ( 'utf8' ) ;
238
- bin . stderr . once ( 'data' , function ( data ) {
239
- touch . sync ( src ) ;
209
+ bin . stderr . once ( 'data' , function ( ) {
210
+ touch ( src ) ;
240
211
} ) ;
241
212
bin . stderr . on ( 'data' , function ( data ) {
242
213
if ( data . trim ( ) === '=> changed: ' + src ) {
@@ -248,35 +219,31 @@ describe.only('cli', function() {
248
219
done ( ) ;
249
220
} ) ;
250
221
bin . on ( 'exit' , done ) ;
251
- } ) . timeout ( 5000 ) ;
222
+ } ) ;
252
223
253
224
it ( 'should emit nothing on file change when using --watch and --quiet options' , function ( done ) {
254
225
var src = fixture ( 'watching-dir-01/index.scss' ) ;
255
226
256
227
var bin = spawn ( cli , [ '--watch' , '--quiet' , src ] ) ;
257
228
258
229
bin . stderr . setEncoding ( 'utf8' ) ;
230
+ // bin.stderr.on('data', function(data) { console.log('stderr', data.toString()) })
231
+ // bin.stdout.on('data', function(data) { console.log('stdout', data.toString()) })
259
232
bin . stderr . once ( 'data' , function ( ) {
260
- assert . fail ( 'should not emit console output with --quiet flag' ) ;
233
+ touch ( src ) ;
234
+ } ) ;
235
+ bin . stderr . on ( 'data' , function ( data ) {
236
+ if ( ! / ^ T E S T I N G / . test ( data . toString ( ) ) ) {
237
+ assert . fail ( 'should not emit console output with --quiet flag' ) ;
238
+ }
239
+ bin . kill ( ) ;
261
240
} ) ;
262
241
bin . on ( 'error' , function ( err ) {
263
242
assert . fail ( err ) ;
264
243
done ( ) ;
265
244
} ) ;
266
245
bin . on ( 'exit' , done ) ;
267
-
268
- setTimeout ( function ( ) {
269
- touch ( src , { } , function ( err ) {
270
- if ( err ) {
271
- assert . fail ( err ) ;
272
- }
273
-
274
- setTimeout ( function ( ) {
275
- bin . kill ( ) ;
276
- } , 1000 ) ;
277
- } ) ;
278
- } , 500 ) ;
279
- } ) . timeout ( 5000 ) ;
246
+ } ) ;
280
247
281
248
it ( 'should render all watched files' , function ( done ) {
282
249
var src = fixture ( 'watching-dir-01/index.scss' ) ;
@@ -287,8 +254,9 @@ describe.only('cli', function() {
287
254
] ) ;
288
255
289
256
bin . stdout . setEncoding ( 'utf8' ) ;
290
- // bin.stderr.on('data', function(data) { console.log('stderr', data.toString()) })
291
- // bin.stdout.on('data', function(data) { console.log('stdout', data.toString()) })
257
+ bin . stderr . on ( 'data' , function ( ) {
258
+ touch ( src ) ;
259
+ } ) ;
292
260
bin . stdout . once ( 'data' , function ( data ) {
293
261
assert . strictEqual ( data . trim ( ) , 'a{color:green}' ) ;
294
262
bin . kill ( ) ;
@@ -298,11 +266,7 @@ describe.only('cli', function() {
298
266
done ( ) ;
299
267
} ) ;
300
268
bin . on ( 'exit' , done ) ;
301
-
302
- setTimeout ( function ( ) {
303
- touch . sync ( src ) ;
304
- } , 500 ) ;
305
- } ) . timeout ( 5000 ) ;
269
+ } ) ;
306
270
307
271
it ( 'should watch the full scss dep tree for a single file (scss)' , function ( done ) {
308
272
var src = fixture ( 'watching/index.scss' ) ;
@@ -327,7 +291,7 @@ describe.only('cli', function() {
327
291
done ( ) ;
328
292
} ) ;
329
293
bin . on ( 'exit' , done ) ;
330
- } ) . timeout ( 5000 ) ;
294
+ } ) ;
331
295
332
296
it ( 'should watch the full sass dep tree for a single file (sass)' , function ( done ) {
333
297
var src = fixture ( 'watching/index.sass' ) ;
@@ -357,7 +321,7 @@ describe.only('cli', function() {
357
321
touch . sync ( child ) ;
358
322
} , 500 ) ;
359
323
} ) ;
360
- } ) . timeout ( 5000 ) ;
324
+ } ) ;
361
325
362
326
describe ( 'node-sass --output directory' , function ( ) {
363
327
it ( 'should watch whole directory' , function ( done ) {
@@ -395,7 +359,7 @@ describe.only('cli', function() {
395
359
} ) ;
396
360
bin . on ( 'error' , assert . fail ) ;
397
361
bin . on ( 'exit' , done ) ;
398
- } ) . timeout ( 5000 ) ;
362
+ } ) ;
399
363
400
364
it ( 'should compile all changed files in watched directory' , function ( done ) {
401
365
var destDir = tmpDir ( {
@@ -691,10 +655,20 @@ describe.only('cli', function() {
691
655
} ) ;
692
656
693
657
describe ( 'importer' , function ( ) {
694
- var dest = fixture ( 'include-files/index.css' ) ;
658
+ var dest ;
695
659
var src = fixture ( 'include-files/index.scss' ) ;
696
660
var expected = read ( fixture ( 'include-files/expected-importer.css' ) , 'utf8' ) . trim ( ) . replace ( / \r \n / g, '\n' ) ;
697
661
662
+ beforeEach ( function ( ) {
663
+ dest = path . join ( tmpDir ( { create : true } ) , 'index.css' ) ;
664
+ } ) ;
665
+
666
+ afterEach ( function ( ) {
667
+ if ( fs . existsSync ( dest ) ) {
668
+ fs . unlinkSync ( dest ) ;
669
+ }
670
+ } ) ;
671
+
698
672
it ( 'should override imports and fire callback with file and contents' , function ( done ) {
699
673
var bin = spawn ( cli , [
700
674
src , '--output' , path . dirname ( dest ) ,
@@ -703,7 +677,6 @@ describe.only('cli', function() {
703
677
704
678
bin . once ( 'close' , function ( ) {
705
679
assert . equal ( read ( dest , 'utf8' ) . trim ( ) , expected ) ;
706
- fs . unlinkSync ( dest ) ;
707
680
done ( ) ;
708
681
} ) ;
709
682
} ) ;
@@ -715,11 +688,7 @@ describe.only('cli', function() {
715
688
] ) ;
716
689
717
690
bin . once ( 'close' , function ( ) {
718
- if ( fs . existsSync ( dest ) ) {
719
- assert . equal ( read ( dest , 'utf8' ) . trim ( ) , '' ) ;
720
- fs . unlinkSync ( dest ) ;
721
- }
722
-
691
+ assert . equal ( read ( dest , 'utf8' ) . trim ( ) , '/* foo.scss */\n/* bar.scss */' ) ;
723
692
done ( ) ;
724
693
} ) ;
725
694
} ) ;
@@ -732,7 +701,6 @@ describe.only('cli', function() {
732
701
733
702
bin . once ( 'close' , function ( ) {
734
703
assert . equal ( read ( dest , 'utf8' ) . trim ( ) , expected ) ;
735
- fs . unlinkSync ( dest ) ;
736
704
done ( ) ;
737
705
} ) ;
738
706
} ) ;
@@ -745,7 +713,6 @@ describe.only('cli', function() {
745
713
746
714
bin . once ( 'close' , function ( ) {
747
715
assert . equal ( read ( dest , 'utf8' ) . trim ( ) , expected ) ;
748
- fs . unlinkSync ( dest ) ;
749
716
done ( ) ;
750
717
} ) ;
751
718
} ) ;
@@ -757,11 +724,7 @@ describe.only('cli', function() {
757
724
] ) ;
758
725
759
726
bin . once ( 'close' , function ( ) {
760
- if ( fs . existsSync ( dest ) ) {
761
- assert . equal ( read ( dest , 'utf8' ) . trim ( ) , '' ) ;
762
- fs . unlinkSync ( dest ) ;
763
- }
764
-
727
+ assert . equal ( read ( dest , 'utf8' ) . trim ( ) , '/* foo.scss */\n/* bar.scss */' ) ;
765
728
done ( ) ;
766
729
} ) ;
767
730
} ) ;
@@ -774,7 +737,6 @@ describe.only('cli', function() {
774
737
775
738
bin . once ( 'close' , function ( ) {
776
739
assert . equal ( read ( dest , 'utf8' ) . trim ( ) , expected ) ;
777
- fs . unlinkSync ( dest ) ;
778
740
done ( ) ;
779
741
} ) ;
780
742
} ) ;
@@ -787,7 +749,6 @@ describe.only('cli', function() {
787
749
788
750
bin . once ( 'close' , function ( ) {
789
751
assert . equal ( read ( dest , 'utf8' ) . trim ( ) , expected ) ;
790
- fs . unlinkSync ( dest ) ;
791
752
done ( ) ;
792
753
} ) ;
793
754
} ) ;
0 commit comments