Debian Codegraph @

test/symlink.js

raw ◀ ▶
Source reconstructed at patch state 0 of 3 — not the installed (fully patched) source.
3 Debian patches touch this file
1 'use strict';
2
3 var path = require('path');
4
5 var fs = require('graceful-fs');
6 var File = require('vinyl');
7 var expect = require('expect');
8 var miss = require('mississippi');
9
10 var vfs = require('../');
11
12 var cleanup = require('./utils/cleanup');
13 var isWindows = require('./utils/is-windows');
14 var testStreams = require('./utils/test-streams');
15 var always = require('./utils/always');
16 var testConstants = require('./utils/test-constants');
17 var breakPrototype = require('./utils/break-prototype');
18
19 var from = miss.from;
20 var pipe = miss.pipe;
21 var concat = miss.concat;
22
23 var count = testStreams.count;
24 var slowCount = testStreams.slowCount;
25
26 function noop() {}
27
28 var outputRelative = testConstants.outputRelative;
29 var inputBase = testConstants.inputBase;
30 var outputBase = testConstants.outputBase;
31 var inputPath = testConstants.inputPath;
32 var outputPath = testConstants.outputPath;
33 var inputDirpath = testConstants.inputDirpath;
34 var outputDirpath = testConstants.outputDirpath;
35 var contents = testConstants.contents;
36
37 var clean = cleanup(outputBase);
38
39 describe('symlink stream', function() {
40
41 beforeEach(clean);
42 afterEach(clean);
43
44 it('throws on no folder argument', function(done) {
45 function noFolder() {
46 vfs.symlink();
47 }
48
49 expect(noFolder).toThrow('Invalid symlink() folder argument. Please specify a non-empty string or a function.');
50 done();
51 });
52
53 it('throws on empty string folder argument', function(done) {
54 function emptyFolder() {
55 vfs.symlink('');
56 }
57
58 expect(emptyFolder).toThrow('Invalid symlink() folder argument. Please specify a non-empty string or a function.');
59 done();
60 });
61
62 it('passes through writes with cwd', function(done) {
63 var file = new File({
64 base: inputBase,
65 path: inputPath,
66 contents: null,
67 });
68
69 function assert(files) {
70 expect(files.length).toEqual(1);
71 expect(files).toInclude(file);
72 expect(files[0].cwd).toEqual(__dirname, 'cwd should have changed');
73 }
74
75 pipe([
76 from.obj([file]),
77 vfs.symlink(outputRelative, { cwd: __dirname }),
78 concat(assert),
79 ], done);
80 });
81
82 it('passes through writes with default cwd', function(done) {
83 var file = new File({
84 base: inputBase,
85 path: inputPath,
86 contents: null,
87 });
88
89 function assert(files) {
90 expect(files.length).toEqual(1);
91 expect(files).toInclude(file);
92 expect(files[0].cwd).toEqual(process.cwd(), 'cwd should not have changed');
93 }
94
95 pipe([
96 from.obj([file]),
97 vfs.symlink(outputBase),
98 concat(assert),
99 ], done);
100 });
101
102 it('creates a link to the right folder with relative cwd', function(done) {
103 var cwd = path.relative(process.cwd(), __dirname);
104
105 var file = new File({
106 base: inputBase,
107 path: inputPath,
108 contents: null,
109 });
110
111 function assert(files) {
112 var outputLink = fs.readlinkSync(outputPath);
113
114 expect(files.length).toEqual(1);
115 expect(files).toInclude(file);
116 expect(files[0].base).toEqual(outputBase, 'base should have changed');
117 expect(files[0].path).toEqual(outputPath, 'path should have changed');
118 expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
119 expect(files[0].isSymbolic()).toBe(true, 'file should be symbolic');
120 expect(outputLink).toEqual(inputPath);
121 }
122
123 pipe([
124 from.obj([file]),
125 vfs.symlink(outputRelative, { cwd: cwd }),
126 concat(assert),
127 ], done);
128 });
129
130 it('creates a link to the right folder with function and relative cwd', function(done) {
131 var cwd = path.relative(process.cwd(), __dirname);
132
133 var file = new File({
134 base: inputBase,
135 path: inputPath,
136 contents: null,
137 });
138
139 function outputFn(f) {
140 expect(f).toExist();
141 expect(f).toEqual(file);
142 return outputRelative;
143 }
144
145 function assert(files) {
146 var outputLink = fs.readlinkSync(outputPath);
147
148 expect(files.length).toEqual(1);
149 expect(files).toInclude(file);
150 expect(files[0].base).toEqual(outputBase, 'base should have changed');
151 expect(files[0].path).toEqual(outputPath, 'path should have changed');
152 expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
153 expect(files[0].isSymbolic()).toBe(true, 'file should be symbolic');
154 expect(outputLink).toEqual(inputPath);
155 }
156
157 pipe([
158 from.obj([file]),
159 vfs.symlink(outputFn, { cwd: cwd }),
160 concat(assert),
161 ], done);
162 });
163
164 it('creates a link for a file with buffered contents', function(done) {
165 var file = new File({
166 base: inputBase,
167 path: inputPath,
168 contents: new Buffer(contents),
169 });
170
171 function assert(files) {
172 var outputLink = fs.readlinkSync(outputPath);
173
174 expect(files.length).toEqual(1);
175 expect(files).toInclude(file);
176 expect(files[0].base).toEqual(outputBase, 'base should have changed');
177 expect(files[0].path).toEqual(outputPath, 'path should have changed');
178 expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
179 expect(files[0].isSymbolic()).toBe(true, 'file should be symbolic');
180 expect(outputLink).toEqual(inputPath);
181 }
182
183 pipe([
184 from.obj([file]),
185 vfs.symlink(outputBase),
186 concat(assert),
187 ], done);
188 });
189
190 it('can create relative links', function(done) {
191 var file = new File({
192 base: inputBase,
193 path: inputPath,
194 contents: null,
195 });
196
197 function assert(files) {
198 var outputLink = fs.readlinkSync(outputPath);
199
200 expect(files.length).toEqual(1);
201 expect(files).toInclude(file);
202 expect(files[0].base).toEqual(outputBase, 'base should have changed');
203 expect(files[0].path).toEqual(outputPath, 'path should have changed');
204 expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
205 expect(files[0].isSymbolic()).toBe(true, 'file should be symbolic');
206 expect(outputLink).toEqual(path.normalize('../fixtures/test.txt'));
207 }
208
209 pipe([
210 from.obj([file]),
211 vfs.symlink(outputBase, { relativeSymlinks: true }),
212 concat(assert),
213 ], done);
214 });
215
216 it('creates a link for a file with streaming contents', function(done) {
217 var file = new File({
218 base: inputBase,
219 path: inputPath,
220 contents: from([contents]),
221 });
222
223 function assert(files) {
224 var outputLink = fs.readlinkSync(outputPath);
225
226 expect(files.length).toEqual(1);
227 expect(files).toInclude(file);
228 expect(files[0].base).toEqual(outputBase, 'base should have changed');
229 expect(files[0].path).toEqual(outputPath, 'path should have changed');
230 expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
231 expect(files[0].isSymbolic()).toBe(true, 'file should be symbolic');
232 expect(outputLink).toEqual(inputPath);
233 }
234
235 pipe([
236 from.obj([file]),
237 vfs.symlink(outputBase),
238 concat(assert),
239 ], done);
240 });
241
242 it('emits Vinyl objects that are symbolic', function(done) {
243 var file = new File({
244 base: inputBase,
245 path: inputPath,
246 contents: null,
247 });
248
249 function assert(files) {
250 expect(files.length).toEqual(1);
251 expect(files[0].isSymbolic()).toEqual(true);
252 }
253
254 pipe([
255 from.obj([file]),
256 vfs.symlink(outputBase),
257 concat(assert),
258 ], done);
259 });
260
261 it('(*nix) creates a link for a directory', function(done) {
262 if (isWindows) {
263 this.skip();
264 return;
265 }
266
267 var file = new File({
268 base: inputBase,
269 path: inputDirpath,
270 contents: null,
271 stat: {
272 isDirectory: always(true),
273 },
274 });
275
276 function assert(files) {
277 var stats = fs.statSync(outputDirpath);
278 var lstats = fs.lstatSync(outputDirpath);
279 var outputLink = fs.readlinkSync(outputDirpath);
280
281 expect(files.length).toEqual(1);
282 expect(files).toInclude(file);
283 expect(files[0].base).toEqual(outputBase, 'base should have changed');
284 expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
285 expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
286 expect(outputLink).toEqual(inputDirpath);
287 expect(stats.isDirectory()).toEqual(true);
288 expect(lstats.isDirectory()).toEqual(false);
289 }
290
291 pipe([
292 from.obj([file]),
293 vfs.symlink(outputBase),
294 concat(assert),
295 ], done);
296 });
297
298 it('(windows) creates a junction for a directory', function(done) {
299 if (!isWindows) {
300 this.skip();
301 return;
302 }
303
304 var file = new File({
305 base: inputBase,
306 path: inputDirpath,
307 contents: null,
308 stat: {
309 isDirectory: always(true),
310 },
311 });
312
313 function assert(files) {
314 var stats = fs.statSync(outputDirpath);
315 var lstats = fs.lstatSync(outputDirpath);
316 var outputLink = fs.readlinkSync(outputDirpath);
317
318 expect(files.length).toEqual(1);
319 expect(files).toInclude(file);
320 expect(files[0].base).toEqual(outputBase, 'base should have changed');
321 expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
322 // When creating a junction, it seems Windows appends a separator
323 expect(files[0].symlink + path.sep).toEqual(outputLink, 'symlink should be set');
324 expect(outputLink).toEqual(inputDirpath + path.sep);
325 expect(stats.isDirectory()).toEqual(true);
326 expect(lstats.isDirectory()).toEqual(false);
327 }
328
329 pipe([
330 from.obj([file]),
331 vfs.symlink(outputBase),
332 concat(assert),
333 ], done);
334 });
335
336 it('(windows) options can disable junctions for a directory', function(done) {
337 if (!isWindows) {
338 this.skip();
339 return;
340 }
341
342 var file = new File({
343 base: inputBase,
344 path: inputDirpath,
345 contents: null,
346 stat: {
347 isDirectory: always(true),
348 },
349 });
350
351 function assert(files) {
352 var stats = fs.statSync(outputDirpath);
353 var lstats = fs.lstatSync(outputDirpath);
354 var outputLink = fs.readlinkSync(outputDirpath);
355
356 expect(files.length).toEqual(1);
357 expect(files).toInclude(file);
358 expect(files[0].base).toEqual(outputBase, 'base should have changed');
359 expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
360 expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
361 expect(outputLink).toEqual(inputDirpath);
362 expect(stats.isDirectory()).toEqual(true);
363 expect(lstats.isDirectory()).toEqual(false);
364 }
365
366 pipe([
367 from.obj([file]),
368 vfs.symlink(outputBase, { useJunctions: false }),
369 concat(assert),
370 ], done);
371 });
372
373 it('(windows) options can disable junctions for a directory (as a function)', function(done) {
374 if (!isWindows) {
375 this.skip();
376 return;
377 }
378
379 var file = new File({
380 base: inputBase,
381 path: inputDirpath,
382 contents: null,
383 stat: {
384 isDirectory: always(true),
385 },
386 });
387
388 function useJunctions(f) {
389 expect(f).toExist();
390 expect(f).toBe(file);
391 return false;
392 }
393
394 function assert(files) {
395 var stats = fs.statSync(outputDirpath);
396 var lstats = fs.lstatSync(outputDirpath);
397 var outputLink = fs.readlinkSync(outputDirpath);
398
399 expect(files.length).toEqual(1);
400 expect(files).toInclude(file);
401 expect(files[0].base).toEqual(outputBase, 'base should have changed');
402 expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
403 expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
404 expect(outputLink).toEqual(inputDirpath);
405 expect(stats.isDirectory()).toEqual(true);
406 expect(lstats.isDirectory()).toEqual(false);
407 }
408
409 pipe([
410 from.obj([file]),
411 vfs.symlink(outputBase, { useJunctions: useJunctions }),
412 concat(assert),
413 ], done);
414 });
415
416 it('(*nix) can create relative links for directories', function(done) {
417 if (isWindows) {
418 this.skip();
419 return;
420 }
421
422 var file = new File({
423 base: inputBase,
424 path: inputDirpath,
425 contents: null,
426 stat: {
427 isDirectory: always(true),
428 },
429 });
430
431 function assert(files) {
432 var stats = fs.statSync(outputDirpath);
433 var lstats = fs.lstatSync(outputDirpath);
434 var outputLink = fs.readlinkSync(outputDirpath);
435
436 expect(files.length).toEqual(1);
437 expect(files).toInclude(file);
438 expect(files[0].base).toEqual(outputBase, 'base should have changed');
439 expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
440 expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
441 expect(outputLink).toEqual(path.normalize('../fixtures/foo'));
442 expect(stats.isDirectory()).toEqual(true);
443 expect(lstats.isDirectory()).toEqual(false);
444 }
445
446 pipe([
447 from.obj([file]),
448 vfs.symlink(outputBase, { relativeSymlinks: true }),
449 concat(assert),
450 ], done);
451 });
452
453 it('(windows) relativeSymlinks option is ignored when junctions are used', function(done) {
454 if (!isWindows) {
455 this.skip();
456 return;
457 }
458
459 var file = new File({
460 base: inputBase,
461 path: inputDirpath,
462 contents: null,
463 stat: {
464 isDirectory: always(true),
465 },
466 });
467
468 function assert(files) {
469 var stats = fs.statSync(outputDirpath);
470 var lstats = fs.lstatSync(outputDirpath);
471 var outputLink = fs.readlinkSync(outputDirpath);
472
473 expect(files.length).toEqual(1);
474 expect(files).toInclude(file);
475 expect(files[0].base).toEqual(outputBase, 'base should have changed');
476 expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
477 // When creating a junction, it seems Windows appends a separator
478 expect(files[0].symlink + path.sep).toEqual(outputLink, 'symlink should be set');
479 expect(outputLink).toEqual(inputDirpath + path.sep);
480 expect(stats.isDirectory()).toEqual(true);
481 expect(lstats.isDirectory()).toEqual(false);
482 }
483
484 pipe([
485 from.obj([file]),
486 vfs.symlink(outputBase, { useJunctions: true, relativeSymlinks: true }),
487 concat(assert),
488 ], done);
489 });
490
491 it('(windows) supports relativeSymlinks option when link is not for a directory', function(done) {
492 if (!isWindows) {
493 this.skip();
494 return;
495 }
496
497 var file = new File({
498 base: inputBase,
499 path: inputPath,
500 contents: null,
501 });
502
503 function assert(files) {
504 var outputLink = fs.readlinkSync(outputPath);
505
506 expect(files.length).toEqual(1);
507 expect(files).toInclude(file);
508 expect(files[0].base).toEqual(outputBase, 'base should have changed');
509 expect(files[0].path).toEqual(outputPath, 'path should have changed');
510 expect(outputLink).toEqual(path.normalize('../fixtures/test.txt'));
511 }
512
513 pipe([
514 from.obj([file]),
515 // The useJunctions option is ignored when file is not a directory
516 vfs.symlink(outputBase, { useJunctions: true, relativeSymlinks: true }),
517 concat(assert),
518 ], done);
519 });
520
521 it('(windows) can create relative links for directories when junctions are disabled', function(done) {
522 if (!isWindows) {
523 this.skip();
524 return;
525 }
526
527 var file = new File({
528 base: inputBase,
529 path: inputDirpath,
530 contents: null,
531 stat: {
532 isDirectory: always(true),
533 },
534 });
535
536 function assert(files) {
537 var stats = fs.statSync(outputDirpath);
538 var lstats = fs.lstatSync(outputDirpath);
539 var outputLink = fs.readlinkSync(outputDirpath);
540
541 expect(files.length).toEqual(1);
542 expect(files).toInclude(file);
543 expect(files[0].base).toEqual(outputBase, 'base should have changed');
544 expect(files[0].path).toEqual(outputDirpath, 'path should have changed');
545 expect(files[0].symlink).toEqual(outputLink, 'symlink should be set');
546 expect(outputLink).toEqual(path.normalize('../fixtures/foo'));
547 expect(stats.isDirectory()).toEqual(true);
548 expect(lstats.isDirectory()).toEqual(false);
549 }
550
551 pipe([
552 from.obj([file]),
553 vfs.symlink(outputBase, { useJunctions: false, relativeSymlinks: true }),
554 concat(assert),
555 ], done);
556 });
557
558 it('reports IO errors', function(done) {
559 // Changing the mode of a file is not supported by node.js in Windows.
560 // This test is skipped on Windows because we have to chmod the file to 0.
561 if (isWindows) {
562 this.skip();
563 return;
564 }
565
566 var file = new File({
567 base: inputBase,
568 path: inputPath,
569 contents: null,
570 });
571
572 fs.mkdirSync(outputBase);
573 fs.chmodSync(outputBase, 0);
574
575 function assert(err) {
576 expect(err.code).toEqual('EACCES');
577 done();
578 }
579
580 pipe([
581 from.obj([file]),
582 vfs.symlink(outputDirpath),
583 ], assert);
584 });
585
586 it('does not overwrite links with overwrite option set to false', function(done) {
587 var existingContents = 'Lorem Ipsum';
588
589 var file = new File({
590 base: inputBase,
591 path: inputPath,
592 contents: null,
593 });
594
595 function assert(files) {
596 var outputContents = fs.readFileSync(outputPath, 'utf8');
597
598 expect(files.length).toEqual(1);
599 expect(outputContents).toEqual(existingContents);
600 }
601
602 // Write expected file which should not be overwritten
603 fs.mkdirSync(outputBase);
604 fs.writeFileSync(outputPath, existingContents);
605
606 pipe([
607 from.obj([file]),
608 vfs.symlink(outputBase, { overwrite: false }),
609 concat(assert),
610 ], done);
611 });
612
613 it('overwrites links with overwrite option set to true', function(done) {
614 var existingContents = 'Lorem Ipsum';
615
616 var file = new File({
617 base: inputBase,
618 path: inputPath,
619 contents: null,
620 });
621
622 function assert(files) {
623 var outputContents = fs.readFileSync(outputPath, 'utf8');
624
625 expect(files.length).toEqual(1);
626 expect(outputContents).toEqual(contents);
627 }
628
629 // This should be overwritten
630 fs.mkdirSync(outputBase);
631 fs.writeFileSync(outputPath, existingContents);
632
633 pipe([
634 from.obj([file]),
635 vfs.symlink(outputBase, { overwrite: true }),
636 concat(assert),
637 ], done);
638 });
639
640 it('does not overwrite links with overwrite option set to a function that returns false', function(done) {
641 var existingContents = 'Lorem Ipsum';
642
643 var file = new File({
644 base: inputBase,
645 path: inputPath,
646 contents: null,
647 });
648
649 function overwrite(f) {
650 expect(f).toEqual(file);
651 return false;
652 }
653
654 function assert(files) {
655 var outputContents = fs.readFileSync(outputPath, 'utf8');
656
657 expect(files.length).toEqual(1);
658 expect(outputContents).toEqual(existingContents);
659 }
660
661 // Write expected file which should not be overwritten
662 fs.mkdirSync(outputBase);
663 fs.writeFileSync(outputPath, existingContents);
664
665 pipe([
666 from.obj([file]),
667 vfs.symlink(outputBase, { overwrite: overwrite }),
668 concat(assert),
669 ], done);
670 });
671
672 it('overwrites links with overwrite option set to a function that returns true', function(done) {
673 var existingContents = 'Lorem Ipsum';
674
675 var file = new File({
676 base: inputBase,
677 path: inputPath,
678 contents: null,
679 });
680
681 function overwrite(f) {
682 expect(f).toEqual(file);
683 return true;
684 }
685
686 function assert(files) {
687 var outputContents = fs.readFileSync(outputPath, 'utf8');
688
689 expect(files.length).toEqual(1);
690 expect(outputContents).toEqual(contents);
691 }
692
693 // This should be overwritten
694 fs.mkdirSync(outputBase);
695 fs.writeFileSync(outputPath, existingContents);
696
697 pipe([
698 from.obj([file]),
699 vfs.symlink(outputBase, { overwrite: overwrite }),
700 concat(assert),
701 ], done);
702 });
703
704 it('emits an end event', function(done) {
705 var symlinkStream = vfs.symlink(outputBase);
706
707 symlinkStream.on('end', done);
708
709 var file = new File({
710 base: inputBase,
711 path: inputPath,
712 contents: null,
713 });
714
715 pipe([
716 from.obj([file]),
717 symlinkStream,
718 ]);
719 });
720
721 it('emits a finish event', function(done) {
722 var symlinkStream = vfs.symlink(outputBase);
723
724 symlinkStream.on('finish', done);
725
726 var file = new File({
727 base: inputBase,
728 path: inputPath,
729 contents: null,
730 });
731
732 pipe([
733 from.obj([file]),
734 symlinkStream,
735 ]);
736 });
737
738 it('errors when a non-Vinyl object is emitted', function(done) {
739 var file = {};
740
741 function assert(err) {
742 expect(err).toExist();
743 expect(err.message).toEqual('Received a non-Vinyl object in `symlink()`');
744 done();
745 }
746
747 pipe([
748 from.obj([file]),
749 vfs.symlink(outputBase),
750 ], assert);
751 });
752
753 it('errors when a buffer-mode stream is piped to it', function(done) {
754 var file = new Buffer('test');
755
756 function assert(err) {
757 expect(err).toExist();
758 expect(err.message).toEqual('Received a non-Vinyl object in `symlink()`');
759 done();
760 }
761
762 pipe([
763 from([file]),
764 vfs.symlink(outputBase),
765 ], assert);
766 });
767
768 it('does not get clogged by highWaterMark', function(done) {
769 var expectedCount = 17;
770 var highwatermarkFiles = [];
771 for (var idx = 0; idx < expectedCount; idx++) {
772 var file = new File({
773 base: inputBase,
774 path: inputPath,
775 contents: null,
776 });
777 highwatermarkFiles.push(file);
778 }
779
780 pipe([
781 from.obj(highwatermarkFiles),
782 count(expectedCount),
783 // Must be in the Writable position to test this
784 // So concat-stream cannot be used
785 vfs.symlink(outputBase),
786 ], done);
787 });
788
789 it('allows backpressure when piped to another, slower stream', function(done) {
790 this.timeout(20000);
791
792 var expectedCount = 24;
793 var highwatermarkFiles = [];
794 for (var idx = 0; idx < expectedCount; idx++) {
795 var file = new File({
796 base: inputBase,
797 path: inputPath,
798 contents: null,
799 });
800 highwatermarkFiles.push(file);
801 }
802
803 pipe([
804 from.obj(highwatermarkFiles),
805 count(expectedCount),
806 vfs.symlink(outputBase),
807 slowCount(expectedCount),
808 ], done);
809 });
810
811 it('respects readable listeners on symlink stream', function(done) {
812 var file = new File({
813 base: inputBase,
814 path: inputDirpath,
815 contents: null,
816 });
817
818 var symlinkStream = vfs.symlink(outputBase);
819
820 var readables = 0;
821 symlinkStream.on('readable', function() {
822 var data = symlinkStream.read();
823
824 if (data != null) {
825 readables++;
826 }
827 });
828
829 function assert(err) {
830 expect(readables).toEqual(1);
831 done(err);
832 }
833
834 pipe([
835 from.obj([file]),
836 symlinkStream,
837 ], assert);
838 });
839
840 it('respects data listeners on symlink stream', function(done) {
841 var file = new File({
842 base: inputBase,
843 path: inputDirpath,
844 contents: null,
845 });
846
847 var symlinkStream = vfs.symlink(outputBase);
848
849 var datas = 0;
850 symlinkStream.on('data', function() {
851 datas++;
852 });
853
854 function assert(err) {
855 expect(datas).toEqual(1);
856 done(err);
857 }
858
859 pipe([
860 from.obj([file]),
861 symlinkStream,
862 ], assert);
863 });
864
865 it('sinks the stream if all the readable event handlers are removed', function(done) {
866 var expectedCount = 17;
867 var highwatermarkFiles = [];
868 for (var idx = 0; idx < expectedCount; idx++) {
869 var file = new File({
870 base: inputBase,
871 path: inputPath,
872 contents: null,
873 });
874 highwatermarkFiles.push(file);
875 }
876
877 var symlinkStream = vfs.symlink(outputBase);
878
879 symlinkStream.on('readable', noop);
880
881 pipe([
882 from.obj(highwatermarkFiles),
883 count(expectedCount),
884 // Must be in the Writable position to test this
885 // So concat-stream cannot be used
886 symlinkStream,
887 ], done);
888
889 process.nextTick(function() {
890 symlinkStream.removeListener('readable', noop);
891 });
892 });
893
894 it('sinks the stream if all the data event handlers are removed', function(done) {
895 var expectedCount = 17;
896 var highwatermarkFiles = [];
897 for (var idx = 0; idx < expectedCount; idx++) {
898 var file = new File({
899 base: inputBase,
900 path: inputPath,
901 contents: null,
902 });
903 highwatermarkFiles.push(file);
904 }
905
906 var symlinkStream = vfs.symlink(outputBase);
907
908 symlinkStream.on('data', noop);
909
910 pipe([
911 from.obj(highwatermarkFiles),
912 count(expectedCount),
913 // Must be in the Writable position to test this
914 // So concat-stream cannot be used
915 symlinkStream,
916 ], done);
917
918 process.nextTick(function() {
919 symlinkStream.removeListener('data', noop);
920 });
921 });
922
923 it('does not pass options on to through2', function(done) {
924 var file = new File({
925 base: inputBase,
926 path: inputPath,
927 contents: null,
928 });
929
930 // Reference: https://github.com/gulpjs/vinyl-fs/issues/153
931 var read = expect.createSpy().andReturn(false);
932
933 function assert() {
934 // Called never because it's not a valid option
935 expect(read.calls.length).toEqual(0);
936 }
937
938 pipe([
939 from.obj([file]),
940 vfs.symlink(outputBase, { read: read }),
941 concat(assert),
942 ], done);
943 });
944
945 it('does not marshall a Vinyl object with isSymbolic method', function(done) {
946 var file = new File({
947 base: outputBase,
948 path: outputPath,
949 });
950
951 function assert(files) {
952 expect(files.length).toEqual(1);
953 // Avoid comparing stats because they get reflected
954 delete files[0].stat;
955 expect(files[0]).toMatch(file);
956 expect(files[0]).toBe(file);
957 }
958
959 pipe([
960 from.obj([file]),
961 vfs.symlink(outputBase),
962 concat(assert),
963 ], done);
964 });
965
966 it('marshalls a Vinyl object without isSymbolic to a newer Vinyl', function(done) {
967 var file = new File({
968 base: outputBase,
969 path: outputPath,
970 // Pre-set this because it is set by symlink
971 symlink: outputPath,
972 });
973
974 breakPrototype(file);
975
976 function assert(files) {
977 expect(files.length).toEqual(1);
978 // Avoid comparing stats because they get reflected
979 delete files[0].stat;
980 expect(files[0]).toMatch(file);
981 expect(files[0]).toNotBe(file);
982 }
983
984 pipe([
985 from.obj([file]),
986 vfs.symlink(outputBase),
987 concat(assert),
988 ], done);
989 });
990 });