1 | var assert = require('assert').strict,
|
2 | fs = require('fs'),
|
3 | path = require('path'),
|
4 | read = require('fs').readFileSync,
|
5 | glob = require('glob'),
|
6 | rimraf = require('rimraf'),
|
7 | stream = require('stream'),
|
8 | spawn = require('cross-spawn'),
|
9 | cli = path.join(__dirname, '..', 'bin', 'node-sass'),
|
10 | fixture = path.join.bind(null, __dirname, 'fixtures');
|
11 |
|
12 | describe('cli', function() {
|
13 |
|
14 |
|
15 | this.retries(4);
|
16 |
|
17 | describe('node-sass < in.scss', function() {
|
18 | it('should read data from stdin', function(done) {
|
19 | var src = fs.createReadStream(fixture('simple/index.scss'));
|
20 | var expected = read(fixture('simple/expected.css'), 'utf8').trim();
|
21 | var bin = spawn(cli);
|
22 |
|
23 | bin.stdout.setEncoding('utf8');
|
24 | bin.stdout.once('data', function(data) {
|
25 | assert.strictEqual(data.trim(), expected.replace(/\r\n/g, '\n'));
|
26 | done();
|
27 | });
|
28 |
|
29 | src.pipe(bin.stdin);
|
30 | });
|
31 |
|
32 | it('should compile sass using the --indented-syntax option', function(done) {
|
33 | var src = fs.createReadStream(fixture('indent/index.sass'));
|
34 | var expected = read(fixture('indent/expected.css'), 'utf8').trim();
|
35 | var bin = spawn(cli, ['--indented-syntax']);
|
36 |
|
37 | bin.stdout.setEncoding('utf8');
|
38 | bin.stdout.once('data', function(data) {
|
39 | assert.strictEqual(data.trim(), expected.replace(/\r\n/g, '\n'));
|
40 | done();
|
41 | });
|
42 |
|
43 | src.pipe(bin.stdin);
|
44 | });
|
45 |
|
46 | it('should compile with the --quiet option', function(done) {
|
47 | var src = fs.createReadStream(fixture('simple/index.scss'));
|
48 | var expected = read(fixture('simple/expected.css'), 'utf8').trim();
|
49 | var bin = spawn(cli, ['--quiet']);
|
50 |
|
51 | bin.stdout.setEncoding('utf8');
|
52 | bin.stdout.once('data', function(data) {
|
53 | assert.strictEqual(data.trim(), expected.replace(/\r\n/g, '\n'));
|
54 | done();
|
55 | });
|
56 |
|
57 | src.pipe(bin.stdin);
|
58 | });
|
59 |
|
60 | it('should compile with the --output-style option', function(done) {
|
61 | var src = fs.createReadStream(fixture('compressed/index.scss'));
|
62 | var expected = read(fixture('compressed/expected.css'), 'utf8').trim();
|
63 | var bin = spawn(cli, ['--output-style', 'compressed']);
|
64 |
|
65 | bin.stdout.setEncoding('utf8');
|
66 | bin.stdout.once('data', function(data) {
|
67 | assert.strictEqual(data.trim(), expected.replace(/\r\n/g, '\n'));
|
68 | done();
|
69 | });
|
70 |
|
71 | src.pipe(bin.stdin);
|
72 | });
|
73 |
|
74 | it('should compile with the --source-comments option', function(done) {
|
75 | var src = fs.createReadStream(fixture('source-comments/index.scss'));
|
76 | var expected = read(fixture('source-comments/expected.css'), 'utf8').trim();
|
77 | var bin = spawn(cli, ['--source-comments']);
|
78 |
|
79 | bin.stdout.setEncoding('utf8');
|
80 | bin.stdout.once('data', function(data) {
|
81 | assert.strictEqual(data.trim(), expected.replace(/\r\n/g, '\n'));
|
82 | done();
|
83 | });
|
84 |
|
85 | src.pipe(bin.stdin);
|
86 | });
|
87 |
|
88 | it('should render with indentWidth and indentType options', function(done) {
|
89 | var src = new stream.Readable();
|
90 | var bin = spawn(cli, ['--indent-width', 7, '--indent-type', 'tab']);
|
91 |
|
92 | src._read = function() { };
|
93 | src.push('div { color: transparent; }');
|
94 | src.push(null);
|
95 |
|
96 | bin.stdout.setEncoding('utf8');
|
97 | bin.stdout.once('data', function(data) {
|
98 | assert.strictEqual(data.trim(), 'div {\n\t\t\t\t\t\t\tcolor: transparent; }');
|
99 | done();
|
100 | });
|
101 |
|
102 | src.pipe(bin.stdin);
|
103 | });
|
104 |
|
105 | it('should render with linefeed option', function(done) {
|
106 | var src = new stream.Readable();
|
107 | var bin = spawn(cli, ['--linefeed', 'lfcr']);
|
108 |
|
109 | src._read = function() { };
|
110 | src.push('div { color: transparent; }');
|
111 | src.push(null);
|
112 |
|
113 | bin.stdout.setEncoding('utf8');
|
114 | bin.stdout.once('data', function(data) {
|
115 | assert.strictEqual(data.trim(), 'div {\n\r color: transparent; }');
|
116 | done();
|
117 | });
|
118 |
|
119 | src.pipe(bin.stdin);
|
120 | });
|
121 | });
|
122 |
|
123 | describe('node-sass in.scss', function() {
|
124 | it('should compile a scss file', function(done) {
|
125 | var src = fixture('simple/index.scss');
|
126 | var dest = fixture('simple/index.css');
|
127 | var bin = spawn(cli, [src, dest]);
|
128 |
|
129 | bin.once('close', function() {
|
130 | assert(fs.existsSync(dest));
|
131 | fs.unlinkSync(dest);
|
132 | done();
|
133 | });
|
134 | });
|
135 |
|
136 | it('should compile a scss file to custom destination', function(done) {
|
137 | var src = fixture('simple/index.scss');
|
138 | var dest = fixture('simple/index-custom.css');
|
139 | var bin = spawn(cli, [src, dest]);
|
140 |
|
141 | bin.once('close', function() {
|
142 | assert(fs.existsSync(dest));
|
143 | fs.unlinkSync(dest);
|
144 | done();
|
145 | });
|
146 | });
|
147 |
|
148 | it('should compile with the --include-path option', function(done) {
|
149 | var includePaths = [
|
150 | '--include-path', fixture('include-path/functions'),
|
151 | '--include-path', fixture('include-path/lib')
|
152 | ];
|
153 |
|
154 | var src = fixture('include-path/index.scss');
|
155 | var expected = read(fixture('include-path/expected.css'), 'utf8').trim();
|
156 | var bin = spawn(cli, [src].concat(includePaths));
|
157 |
|
158 | bin.stdout.setEncoding('utf8');
|
159 | bin.stdout.once('data', function(data) {
|
160 | assert.strictEqual(data.trim(), expected.replace(/\r\n/g, '\n'));
|
161 | done();
|
162 | });
|
163 | });
|
164 |
|
165 | it('should compile silently using the --quiet option', function(done) {
|
166 | var src = fixture('simple/index.scss');
|
167 | var dest = fixture('simple/index.css');
|
168 | var bin = spawn(cli, [src, dest, '--quiet']);
|
169 | var didEmit = false;
|
170 |
|
171 | bin.stderr.once('data', function() {
|
172 | didEmit = true;
|
173 | });
|
174 |
|
175 | bin.once('close', function() {
|
176 | assert.strictEqual(didEmit, false);
|
177 | fs.unlinkSync(dest);
|
178 | done();
|
179 | });
|
180 | });
|
181 |
|
182 | it('should still report errors with the --quiet option', function(done) {
|
183 | var src = fixture('invalid/index.scss');
|
184 | var dest = fixture('invalid/index.css');
|
185 | var bin = spawn(cli, [src, dest, '--quiet']);
|
186 | var didEmit = false;
|
187 |
|
188 | bin.stderr.once('data', function() {
|
189 | didEmit = true;
|
190 | });
|
191 |
|
192 | bin.once('close', function() {
|
193 | assert.strictEqual(didEmit, true);
|
194 | done();
|
195 | });
|
196 | });
|
197 |
|
198 | it('should not exit with the --watch option', function(done) {
|
199 | var src = fixture('simple/index.scss');
|
200 | var bin = spawn(cli, [src, '--watch']);
|
201 | var exited;
|
202 |
|
203 | bin.once('close', function() {
|
204 | exited = true;
|
205 | });
|
206 |
|
207 | setTimeout(function() {
|
208 | if (exited) {
|
209 | throw new Error('Watch ended too early!');
|
210 | } else {
|
211 | bin.kill();
|
212 | done();
|
213 | }
|
214 | }, 100);
|
215 | });
|
216 |
|
217 | it.skip('should emit `warn` on file change when using --watch option', function(done) {
|
218 | var src = fixture('simple/tmp.scss');
|
219 |
|
220 | fs.writeFileSync(src, '');
|
221 |
|
222 | var bin = spawn(cli, ['--watch', src]);
|
223 |
|
224 | bin.stderr.setEncoding('utf8');
|
225 | bin.stderr.once('data', function(data) {
|
226 | assert.strictEqual(data.trim(), '=> changed: ' + src);
|
227 | fs.unlinkSync(src);
|
228 | bin.kill();
|
229 | done();
|
230 | });
|
231 |
|
232 | setTimeout(function() {
|
233 | fs.appendFileSync(src, 'body {}');
|
234 | }, 500);
|
235 | });
|
236 |
|
237 | it.skip('should emit nothing on file change when using --watch and --quiet options', function(done) {
|
238 | var src = fixture('simple/tmp.scss');
|
239 | var didEmit = false;
|
240 | fs.writeFileSync(src, '');
|
241 |
|
242 | var bin = spawn(cli, ['--watch', '--quiet', src]);
|
243 |
|
244 | bin.stderr.setEncoding('utf8');
|
245 | bin.stderr.once('data', function() {
|
246 | didEmit = true;
|
247 | });
|
248 |
|
249 | setTimeout(function() {
|
250 | fs.appendFileSync(src, 'body {}');
|
251 | setTimeout(function() {
|
252 | assert.strictEqual(didEmit, false);
|
253 | bin.kill();
|
254 | done();
|
255 | fs.unlinkSync(src);
|
256 | }, 200);
|
257 | }, 500);
|
258 | });
|
259 |
|
260 | it.skip('should render all watched files', function(done) {
|
261 | var src = fixture('simple/bar.scss');
|
262 |
|
263 | fs.writeFileSync(src, '');
|
264 |
|
265 | var bin = spawn(cli, [
|
266 | '--output-style', 'compressed',
|
267 | '--watch', src
|
268 | ]);
|
269 |
|
270 | bin.stdout.setEncoding('utf8');
|
271 | bin.stdout.once('data', function(data) {
|
272 | assert.strictEqual(data.trim(), 'body{background:white}');
|
273 | fs.unlinkSync(src);
|
274 | bin.kill();
|
275 | done();
|
276 | });
|
277 |
|
278 | setTimeout(function() {
|
279 | fs.appendFileSync(src, 'body{background:white}');
|
280 | }, 500);
|
281 | });
|
282 |
|
283 | it.skip('should watch the full scss dep tree for a single file (scss)', function(done) {
|
284 | var src = fixture('watching/index.scss');
|
285 | var foo = fixture('watching/white.scss');
|
286 |
|
287 | fs.writeFileSync(foo, '');
|
288 |
|
289 | var bin = spawn(cli, [
|
290 | '--output-style', 'compressed',
|
291 | '--watch', src
|
292 | ]);
|
293 |
|
294 | bin.stdout.setEncoding('utf8');
|
295 | bin.stdout.once('data', function(data) {
|
296 | assert.strictEqual(data.trim(), 'body{background:blue}');
|
297 | bin.kill();
|
298 | done();
|
299 | });
|
300 |
|
301 | setTimeout(function() {
|
302 | fs.appendFileSync(foo, 'body{background:blue}\n');
|
303 | }, 500);
|
304 | });
|
305 |
|
306 | it.skip('should watch the full sass dep tree for a single file (sass)', function(done) {
|
307 | var src = fixture('watching/index.sass');
|
308 | var foo = fixture('watching/bar.sass');
|
309 |
|
310 | fs.writeFileSync(foo, '');
|
311 |
|
312 | var bin = spawn(cli, [
|
313 | '--output-style', 'compressed',
|
314 | '--watch', src
|
315 | ]);
|
316 |
|
317 | bin.stdout.setEncoding('utf8');
|
318 | bin.stdout.once('data', function(data) {
|
319 | assert.strictEqual(data.trim(), 'body{background:red}');
|
320 | bin.kill();
|
321 | done();
|
322 | });
|
323 |
|
324 | setTimeout(function() {
|
325 | fs.appendFileSync(foo, 'body\n\tbackground: red\n');
|
326 | }, 500);
|
327 | });
|
328 | });
|
329 |
|
330 | describe('node-sass --output directory', function() {
|
331 | it.skip('should watch whole directory', function(done) {
|
332 | var destDir = fixture('watching-css-out-01/');
|
333 | var srcDir = fixture('watching-dir-01/');
|
334 | var srcFile = path.join(srcDir, 'index.scss');
|
335 |
|
336 | fs.writeFileSync(srcFile, '');
|
337 |
|
338 | var bin = spawn(cli, [
|
339 | '--output-style', 'compressed',
|
340 | '--output', destDir,
|
341 | '--watch', srcDir
|
342 | ]);
|
343 |
|
344 | setTimeout(function() {
|
345 | fs.appendFileSync(srcFile, 'a {color:green;}\n');
|
346 | setTimeout(function() {
|
347 | bin.kill();
|
348 | var files = fs.readdirSync(destDir);
|
349 | assert.deepStrictEqual(files, ['index.css']);
|
350 | rimraf(destDir, done);
|
351 | }, 200);
|
352 | }, 500);
|
353 | });
|
354 |
|
355 | it.skip('should compile all changed files in watched directory', function(done) {
|
356 | var destDir = fixture('watching-css-out-02/');
|
357 | var srcDir = fixture('watching-dir-02/');
|
358 | var srcFile = path.join(srcDir, 'foo.scss');
|
359 |
|
360 | fs.writeFileSync(srcFile, '');
|
361 |
|
362 | var bin = spawn(cli, [
|
363 | '--output-style', 'compressed',
|
364 | '--output', destDir,
|
365 | '--watch', srcDir
|
366 | ]);
|
367 |
|
368 | setTimeout(function () {
|
369 | fs.appendFileSync(srcFile, 'body{background:white}\n');
|
370 | setTimeout(function () {
|
371 | bin.kill();
|
372 | var files = fs.readdirSync(destDir);
|
373 | assert.deepStrictEqual(files, ['foo.css', 'index.css']);
|
374 | rimraf(destDir, done);
|
375 | }, 200);
|
376 | }, 500);
|
377 | });
|
378 | });
|
379 |
|
380 | describe('node-sass in.scss --output out.css', function() {
|
381 | it('should compile a scss file to build.css', function(done) {
|
382 | var src = fixture('simple/index.scss');
|
383 | var dest = fixture('simple/index.css');
|
384 | var bin = spawn(cli, [src, '--output', path.dirname(dest)]);
|
385 |
|
386 | bin.once('close', function() {
|
387 | assert(fs.existsSync(dest));
|
388 | fs.unlinkSync(dest);
|
389 | done();
|
390 | });
|
391 | });
|
392 |
|
393 | it('should compile with the --source-map option', function(done) {
|
394 | var src = fixture('source-map/index.scss');
|
395 | var destCss = fixture('source-map/index.css');
|
396 | var destMap = fixture('source-map/index.map');
|
397 | var expectedCss = read(fixture('source-map/expected.css'), 'utf8').trim().replace(/\r\n/g, '\n');
|
398 | var expectedMap = read(fixture('source-map/expected.map'), 'utf8').trim().replace(/\r\n/g, '\n');
|
399 | var bin = spawn(cli, [src, '--output', path.dirname(destCss), '--source-map', destMap]);
|
400 |
|
401 | bin.once('close', function() {
|
402 | assert.strictEqual(read(destCss, 'utf8').trim(), expectedCss);
|
403 | assert.strictEqual(read(destMap, 'utf8').trim(), expectedMap);
|
404 | fs.unlinkSync(destCss);
|
405 | fs.unlinkSync(destMap);
|
406 | done();
|
407 | });
|
408 | });
|
409 |
|
410 | it('should omit sourceMappingURL if --omit-source-map-url flag is used', function(done) {
|
411 | var src = fixture('source-map/index.scss');
|
412 | var dest = fixture('source-map/index.css');
|
413 | var map = fixture('source-map/index.map');
|
414 | var bin = spawn(cli, [
|
415 | src, '--output', path.dirname(dest),
|
416 | '--source-map', map, '--omit-source-map-url'
|
417 | ]);
|
418 |
|
419 | bin.once('close', function() {
|
420 | assert.strictEqual(read(dest, 'utf8').indexOf('sourceMappingURL'), -1);
|
421 | assert(fs.existsSync(map));
|
422 | fs.unlinkSync(map);
|
423 | fs.unlinkSync(dest);
|
424 | done();
|
425 | });
|
426 | });
|
427 |
|
428 | it('should compile with the --source-root option', function(done) {
|
429 | var src = fixture('source-map/index.scss');
|
430 | var destCss = fixture('source-map/index.css');
|
431 | var destMap = fixture('source-map/index.map');
|
432 | var expectedCss = read(fixture('source-map/expected.css'), 'utf8').trim().replace(/\r\n/g, '\n');
|
433 | var expectedUrl = 'http://test/';
|
434 | var bin = spawn(cli, [
|
435 | src, '--output', path.dirname(destCss),
|
436 | '--source-map-root', expectedUrl,
|
437 | '--source-map', destMap
|
438 | ]);
|
439 |
|
440 | bin.once('close', function() {
|
441 | assert.strictEqual(read(destCss, 'utf8').trim(), expectedCss);
|
442 | assert.strictEqual(JSON.parse(read(destMap, 'utf8')).sourceRoot, expectedUrl);
|
443 | fs.unlinkSync(destCss);
|
444 | fs.unlinkSync(destMap);
|
445 | done();
|
446 | });
|
447 | });
|
448 |
|
449 | it('should compile with the --source-map-embed option and no outfile', function(done) {
|
450 | var src = fixture('source-map-embed/index.scss');
|
451 | var expectedCss = read(fixture('source-map-embed/expected.css'), 'utf8').trim().replace(/\r\n/g, '\n');
|
452 | var result = '';
|
453 | var bin = spawn(cli, [
|
454 | src,
|
455 | '--source-map-embed',
|
456 | '--source-map', 'true'
|
457 | ]);
|
458 |
|
459 | bin.stdout.on('data', function(data) {
|
460 | result += data;
|
461 | });
|
462 |
|
463 | bin.once('close', function() {
|
464 | assert.strictEqual(result.trim().replace(/\r\n/g, '\n'), expectedCss);
|
465 | done();
|
466 | });
|
467 | });
|
468 | });
|
469 |
|
470 | describe('node-sass sass/ --output css/', function() {
|
471 | it('should create the output directory', function(done) {
|
472 | var src = fixture('input-directory/sass');
|
473 | var dest = fixture('input-directory/css');
|
474 | var bin = spawn(cli, [src, '--output', dest]);
|
475 |
|
476 | bin.once('close', function() {
|
477 | assert(fs.existsSync(dest));
|
478 | rimraf.sync(dest);
|
479 | done();
|
480 | });
|
481 | });
|
482 |
|
483 | it('should compile all files in the folder', function(done) {
|
484 | var src = fixture('input-directory/sass');
|
485 | var dest = fixture('input-directory/css');
|
486 | var bin = spawn(cli, [src, '--output', dest]);
|
487 |
|
488 | bin.once('close', function() {
|
489 | var files = fs.readdirSync(dest).sort();
|
490 | assert.deepStrictEqual(files, ['one.css', 'two.css', 'nested'].sort());
|
491 | var nestedFiles = fs.readdirSync(path.join(dest, 'nested'));
|
492 | assert.deepStrictEqual(nestedFiles, ['three.css']);
|
493 | rimraf.sync(dest);
|
494 | done();
|
495 | });
|
496 | });
|
497 |
|
498 | it('should compile with --source-map set to directory', function(done) {
|
499 | var src = fixture('input-directory/sass');
|
500 | var dest = fixture('input-directory/css');
|
501 | var destMap = fixture('input-directory/map');
|
502 | var bin = spawn(cli, [src, '--output', dest, '--source-map', destMap]);
|
503 |
|
504 | bin.once('close', function() {
|
505 | var map = JSON.parse(read(fixture('input-directory/map/nested/three.css.map'), 'utf8'));
|
506 |
|
507 | assert.strictEqual(map.file, '../../css/nested/three.css');
|
508 | rimraf.sync(dest);
|
509 | rimraf.sync(destMap);
|
510 | done();
|
511 | });
|
512 | });
|
513 |
|
514 | it('should skip files with an underscore', function(done) {
|
515 | var src = fixture('input-directory/sass');
|
516 | var dest = fixture('input-directory/css');
|
517 | var bin = spawn(cli, [src, '--output', dest]);
|
518 |
|
519 | bin.once('close', function() {
|
520 | var files = fs.readdirSync(dest);
|
521 | assert.strictEqual(files.indexOf('_skipped.css'), -1);
|
522 | rimraf.sync(dest);
|
523 | done();
|
524 | });
|
525 | });
|
526 |
|
527 | it('should ignore nested files if --recursive false', function(done) {
|
528 | var src = fixture('input-directory/sass');
|
529 | var dest = fixture('input-directory/css');
|
530 | var bin = spawn(cli, [
|
531 | src, '--output', dest,
|
532 | '--recursive', false
|
533 | ]);
|
534 |
|
535 | bin.once('close', function() {
|
536 | var files = fs.readdirSync(dest);
|
537 | assert.deepStrictEqual(files, ['one.css', 'two.css']);
|
538 | rimraf.sync(dest);
|
539 | done();
|
540 | });
|
541 | });
|
542 |
|
543 | it('should error if no output directory is provided', function(done) {
|
544 | var src = fixture('input-directory/sass');
|
545 | var bin = spawn(cli, [src]);
|
546 |
|
547 | bin.once('close', function(code) {
|
548 | assert.notStrictEqual(code, 0);
|
549 | assert.strictEqual(glob.sync(fixture('input-directory/**/*.css')).length, 0);
|
550 | done();
|
551 | });
|
552 | });
|
553 |
|
554 | it('should error if output directory is not a directory', function(done) {
|
555 | var src = fixture('input-directory/sass');
|
556 | var dest = fixture('input-directory/sass/one.scss');
|
557 | var bin = spawn(cli, [src, '--output', dest]);
|
558 |
|
559 | bin.once('close', function(code) {
|
560 | assert.notStrictEqual(code, 0);
|
561 | assert.strictEqual(glob.sync(fixture('input-directory/**/*.css')).length, 0);
|
562 | done();
|
563 | });
|
564 | });
|
565 |
|
566 | it('should not error if output directory is a symlink', function(done) {
|
567 | var outputDir = fixture('input-directory/css');
|
568 | var src = fixture('input-directory/sass');
|
569 | var symlink = fixture('symlinked-css');
|
570 | fs.mkdirSync(outputDir);
|
571 | fs.symlinkSync(outputDir, symlink);
|
572 | var bin = spawn(cli, [src, '--output', symlink]);
|
573 |
|
574 | bin.once('close', function() {
|
575 | var files = fs.readdirSync(outputDir).sort();
|
576 | assert.deepStrictEqual(files, ['one.css', 'two.css', 'nested'].sort());
|
577 | var nestedFiles = fs.readdirSync(path.join(outputDir, 'nested'));
|
578 | assert.deepStrictEqual(nestedFiles, ['three.css']);
|
579 | rimraf.sync(outputDir);
|
580 | fs.unlinkSync(symlink);
|
581 | done();
|
582 | });
|
583 | });
|
584 | });
|
585 |
|
586 | describe('node-sass in.scss --output path/to/file/out.css', function() {
|
587 | it('should create the output directory', function(done) {
|
588 | var src = fixture('output-directory/index.scss');
|
589 | var dest = fixture('output-directory/path/to/file/index.css');
|
590 | var bin = spawn(cli, [src, '--output', path.dirname(dest)]);
|
591 |
|
592 | bin.once('close', function() {
|
593 | assert(fs.existsSync(path.dirname(dest)));
|
594 | fs.unlinkSync(dest);
|
595 | fs.rmdirSync(path.dirname(dest));
|
596 | dest = path.dirname(dest);
|
597 | fs.rmdirSync(path.dirname(dest));
|
598 | dest = path.dirname(dest);
|
599 | fs.rmdirSync(path.dirname(dest));
|
600 | done();
|
601 | });
|
602 | });
|
603 |
|
604 | });
|
605 |
|
606 | describe('node-sass --follow --output output-dir input-dir', function() {
|
607 | it('should compile with the --follow option', function(done) {
|
608 | var src = fixture('follow/input-dir');
|
609 | var dest = fixture('follow/output-dir');
|
610 |
|
611 | fs.mkdirSync(src);
|
612 | fs.symlinkSync(path.join(path.dirname(src), 'foo'), path.join(src, 'foo'), 'dir');
|
613 |
|
614 | var bin = spawn(cli, [src, '--follow', '--output', dest]);
|
615 |
|
616 | bin.once('close', function() {
|
617 | var expected = path.join(dest, 'foo/bar/index.css');
|
618 | fs.unlinkSync(path.join(src, 'foo'));
|
619 | fs.rmdirSync(src);
|
620 | assert(fs.existsSync(expected));
|
621 | fs.unlinkSync(expected);
|
622 | expected = path.dirname(expected);
|
623 | fs.rmdirSync(expected);
|
624 | expected = path.dirname(expected);
|
625 | fs.rmdirSync(expected);
|
626 | fs.rmdirSync(dest);
|
627 | done();
|
628 | });
|
629 | });
|
630 | });
|
631 |
|
632 | describe('importer', function() {
|
633 | var dest = fixture('include-files/index.css');
|
634 | var src = fixture('include-files/index.scss');
|
635 | var expectedData = read(fixture('include-files/expected-data-importer.css'), 'utf8').trim().replace(/\r\n/g, '\n');
|
636 | var expectedFile = read(fixture('include-files/expected-file-importer.css'), 'utf8').trim().replace(/\r\n/g, '\n');
|
637 |
|
638 | it('should override imports and fire callback with file and contents', function(done) {
|
639 | var bin = spawn(cli, [
|
640 | src, '--output', path.dirname(dest),
|
641 | '--importer', fixture('extras/my_custom_importer_file_and_data_cb.js')
|
642 | ]);
|
643 |
|
644 | bin.once('close', function() {
|
645 | assert.strictEqual(read(dest, 'utf8').trim(), expectedData);
|
646 | fs.unlinkSync(dest);
|
647 | done();
|
648 | });
|
649 | });
|
650 |
|
651 | it('should override imports and fire callback with file', function(done) {
|
652 | var bin = spawn(cli, [
|
653 | src, '--output', path.dirname(dest),
|
654 | '--importer', fixture('extras/my_custom_importer_file_cb.js')
|
655 | ]);
|
656 |
|
657 | bin.once('close', function() {
|
658 | if (fs.existsSync(dest)) {
|
659 | assert.strictEqual(read(dest, 'utf8').trim(), expectedFile);
|
660 | fs.unlinkSync(dest);
|
661 | }
|
662 |
|
663 | done();
|
664 | });
|
665 | });
|
666 |
|
667 | it('should override imports and fire callback with data', function(done) {
|
668 | var bin = spawn(cli, [
|
669 | src, '--output', path.dirname(dest),
|
670 | '--importer', fixture('extras/my_custom_importer_data_cb.js')
|
671 | ]);
|
672 |
|
673 | bin.once('close', function() {
|
674 | assert.strictEqual(read(dest, 'utf8').trim(), expectedData);
|
675 | fs.unlinkSync(dest);
|
676 | done();
|
677 | });
|
678 | });
|
679 |
|
680 | it('should override imports and return file and contents', function(done) {
|
681 | var bin = spawn(cli, [
|
682 | src, '--output', path.dirname(dest),
|
683 | '--importer', fixture('extras/my_custom_importer_file_and_data.js')
|
684 | ]);
|
685 |
|
686 | bin.once('close', function() {
|
687 | assert.strictEqual(read(dest, 'utf8').trim(), expectedData);
|
688 | fs.unlinkSync(dest);
|
689 | done();
|
690 | });
|
691 | });
|
692 |
|
693 | it('should override imports and return file', function(done) {
|
694 | var bin = spawn(cli, [
|
695 | src, '--output', path.dirname(dest),
|
696 | '--importer', fixture('extras/my_custom_importer_file.js')
|
697 | ]);
|
698 |
|
699 | bin.once('close', function() {
|
700 | if (fs.existsSync(dest)) {
|
701 | assert.strictEqual(read(dest, 'utf8').trim(), expectedFile);
|
702 | fs.unlinkSync(dest);
|
703 | }
|
704 |
|
705 | done();
|
706 | });
|
707 | });
|
708 |
|
709 | it('should override imports and return data', function(done) {
|
710 | var bin = spawn(cli, [
|
711 | src, '--output', path.dirname(dest),
|
712 | '--importer', fixture('extras/my_custom_importer_data.js')
|
713 | ]);
|
714 |
|
715 | bin.once('close', function() {
|
716 | assert.strictEqual(read(dest, 'utf8').trim(), expectedData);
|
717 | fs.unlinkSync(dest);
|
718 | done();
|
719 | });
|
720 | });
|
721 |
|
722 | it('should accept arrays of importers and return respect the order', function(done) {
|
723 | var bin = spawn(cli, [
|
724 | src, '--output', path.dirname(dest),
|
725 | '--importer', fixture('extras/my_custom_arrays_of_importers.js')
|
726 | ]);
|
727 |
|
728 | bin.once('close', function() {
|
729 | assert.strictEqual(read(dest, 'utf8').trim(), expectedData);
|
730 | fs.unlinkSync(dest);
|
731 | done();
|
732 | });
|
733 | });
|
734 |
|
735 | it('should return error for invalid importer file path', function(done) {
|
736 | var bin = spawn(cli, [
|
737 | src, '--output', path.dirname(dest),
|
738 | '--importer', fixture('non/existing/path')
|
739 | ]);
|
740 |
|
741 | bin.once('close', function(code) {
|
742 | assert.notStrictEqual(code, 0);
|
743 | done();
|
744 | });
|
745 | });
|
746 |
|
747 | it('should reflect user-defined Error', function(done) {
|
748 | var bin = spawn(cli, [
|
749 | src, '--output', path.dirname(dest),
|
750 | '--importer', fixture('extras/my_custom_importer_error.js')
|
751 | ]);
|
752 |
|
753 | bin.stderr.once('data', function(code) {
|
754 | assert.strictEqual(JSON.parse(code).message, 'doesn\'t exist!');
|
755 | done();
|
756 | });
|
757 | });
|
758 | });
|
759 |
|
760 | describe('functions', function() {
|
761 | it('should let custom functions call setter methods on wrapped sass values (number)', function(done) {
|
762 | var dest = fixture('custom-functions/setter.css');
|
763 | var src = fixture('custom-functions/setter.scss');
|
764 | var expected = read(fixture('custom-functions/setter-expected.css'), 'utf8').trim().replace(/\r\n/g, '\n');
|
765 | var bin = spawn(cli, [
|
766 | src, '--output', path.dirname(dest),
|
767 | '--functions', fixture('extras/my_custom_functions_setter.js')
|
768 | ]);
|
769 |
|
770 | bin.once('close', function() {
|
771 | assert.strictEqual(read(dest, 'utf8').trim(), expected);
|
772 | fs.unlinkSync(dest);
|
773 | done();
|
774 | });
|
775 | });
|
776 |
|
777 | it('should properly convert strings when calling custom functions', function(done) {
|
778 | var dest = fixture('custom-functions/string-conversion.css');
|
779 | var src = fixture('custom-functions/string-conversion.scss');
|
780 | var expected = read(fixture('custom-functions/string-conversion-expected.css'), 'utf8').trim().replace(/\r\n/g, '\n');
|
781 | var bin = spawn(cli, [
|
782 | src, '--output', path.dirname(dest),
|
783 | '--functions', fixture('extras/my_custom_functions_string_conversion.js')
|
784 | ]);
|
785 |
|
786 | bin.once('close', function() {
|
787 | assert.strictEqual(read(dest, 'utf8').trim(), expected);
|
788 | fs.unlinkSync(dest);
|
789 | done();
|
790 | });
|
791 | });
|
792 | });
|
793 | });
|