@@ -12,6 +12,7 @@ var vfs = require('../');
1212var cleanup = require ( './utils/cleanup' ) ;
1313var isWindows = require ( './utils/is-windows' ) ;
1414var isDirectory = require ( './utils/is-directory-mock' ) ;
15+ var isSymbolicLink = require ( './utils/is-symbolic-link-mock' ) ;
1516var testConstants = require ( './utils/test-constants' ) ;
1617
1718var from = miss . from ;
@@ -25,6 +26,11 @@ var outputPath = testConstants.outputPath;
2526var inputDirpath = testConstants . inputDirpath ;
2627var outputDirpath = testConstants . outputDirpath ;
2728var contents = testConstants . contents ;
29+ // For not-exists tests
30+ var neInputBase = testConstants . neInputBase ;
31+ var neOutputBase = testConstants . neOutputBase ;
32+ var neInputDirpath = testConstants . neInputDirpath ;
33+ var neOutputDirpath = testConstants . neOutputDirpath ;
2834
2935var clean = cleanup ( outputBase ) ;
3036
@@ -33,11 +39,14 @@ describe('.dest() with symlinks', function() {
3339 beforeEach ( clean ) ;
3440 afterEach ( clean ) ;
3541
36- it ( 'creates symlinks when the `symlink` attribute is set on the file ' , function ( done ) {
42+ it ( 'creates symlinks when `file.isSymbolic()` is true ' , function ( done ) {
3743 var file = new File ( {
3844 base : inputBase ,
3945 path : inputPath ,
4046 contents : null ,
47+ stat : {
48+ isSymbolicLink : isSymbolicLink ,
49+ } ,
4150 } ) ;
4251
4352 // `src()` adds this side-effect with `resolveSymlinks` option set to false
@@ -59,11 +68,90 @@ describe('.dest() with symlinks', function() {
5968 ] , done ) ;
6069 } ) ;
6170
71+ it ( 'does not create symlinks when `file.isSymbolic()` is false' , function ( done ) {
72+ var file = new File ( {
73+ base : inputBase ,
74+ path : inputPath ,
75+ contents : null ,
76+ stat : {
77+ isSymbolicLink : function ( ) {
78+ return false ;
79+ } ,
80+ } ,
81+ } ) ;
82+
83+ // `src()` adds this side-effect with `resolveSymlinks` option set to false
84+ file . symlink = inputPath ;
85+
86+ function assert ( files ) {
87+ var symlinkExists = fs . existsSync ( outputPath ) ;
88+
89+ expect ( files . length ) . toEqual ( 1 ) ;
90+ expect ( symlinkExists ) . toBe ( false ) ;
91+ }
92+
93+ pipe ( [
94+ from . obj ( [ file ] ) ,
95+ vfs . dest ( outputBase ) ,
96+ concat ( assert ) ,
97+ ] , done ) ;
98+ } ) ;
99+
100+ it ( 'errors if missing a `.symlink` property' , function ( done ) {
101+ var file = new File ( {
102+ base : inputBase ,
103+ path : inputPath ,
104+ contents : null ,
105+ stat : {
106+ isSymbolicLink : isSymbolicLink ,
107+ } ,
108+ } ) ;
109+
110+ function assert ( err ) {
111+ expect ( err ) . toExist ( ) ;
112+ // TODO: Should we assert anything else about this err?
113+ done ( ) ;
114+ }
115+
116+ pipe ( [
117+ from . obj ( [ file ] ) ,
118+ vfs . dest ( outputBase ) ,
119+ ] , assert ) ;
120+ } ) ;
121+
122+ it ( 'emits Vinyl files that are symbolic' , function ( done ) {
123+ var file = new File ( {
124+ base : inputBase ,
125+ path : inputPath ,
126+ contents : null ,
127+ stat : {
128+ isSymbolicLink : isSymbolicLink ,
129+ } ,
130+ } ) ;
131+
132+ // `src()` adds this side-effect with `resolveSymlinks` option set to false
133+ file . symlink = inputPath ;
134+
135+ function assert ( files ) {
136+ expect ( files . length ) . toEqual ( 1 ) ;
137+ expect ( files [ 0 ] . isSymbolic ( ) ) . toEqual ( true ) ;
138+ }
139+
140+ pipe ( [
141+ from . obj ( [ file ] ) ,
142+ vfs . dest ( outputBase ) ,
143+ concat ( assert ) ,
144+ ] , done ) ;
145+ } ) ;
146+
62147 it ( 'can create relative links' , function ( done ) {
63148 var file = new File ( {
64149 base : inputBase ,
65150 path : inputPath ,
66151 contents : null ,
152+ stat : {
153+ isSymbolicLink : isSymbolicLink ,
154+ } ,
67155 } ) ;
68156
69157 // `src()` adds this side-effect with `resolveSymlinks` option set to false
@@ -94,7 +182,7 @@ describe('.dest() with symlinks', function() {
94182 path : inputDirpath ,
95183 contents : null ,
96184 stat : {
97- isDirectory : isDirectory ,
185+ isSymbolicLink : isSymbolicLink ,
98186 } ,
99187 } ) ;
100188
@@ -130,7 +218,7 @@ describe('.dest() with symlinks', function() {
130218 path : inputDirpath ,
131219 contents : null ,
132220 stat : {
133- isDirectory : isDirectory ,
221+ isSymbolicLink : isSymbolicLink ,
134222 } ,
135223 } ) ;
136224
@@ -167,7 +255,7 @@ describe('.dest() with symlinks', function() {
167255 path : inputDirpath ,
168256 contents : null ,
169257 stat : {
170- isDirectory : isDirectory ,
258+ isSymbolicLink : isSymbolicLink ,
171259 } ,
172260 } ) ;
173261
@@ -203,7 +291,7 @@ describe('.dest() with symlinks', function() {
203291 path : inputDirpath ,
204292 contents : null ,
205293 stat : {
206- isDirectory : isDirectory ,
294+ isSymbolicLink : isSymbolicLink ,
207295 } ,
208296 } ) ;
209297
@@ -245,7 +333,7 @@ describe('.dest() with symlinks', function() {
245333 path : inputDirpath ,
246334 contents : null ,
247335 stat : {
248- isDirectory : isDirectory ,
336+ isSymbolicLink : isSymbolicLink ,
249337 } ,
250338 } ) ;
251339
@@ -270,6 +358,83 @@ describe('.dest() with symlinks', function() {
270358 ] , done ) ;
271359 } ) ;
272360
361+ it ( '(*nix) receives a virtual symbolic directory and creates a symlink' , function ( done ) {
362+ if ( isWindows ) {
363+ this . skip ( ) ;
364+ return ;
365+ }
366+
367+ var file = new File ( {
368+ base : neInputBase ,
369+ path : neInputDirpath ,
370+ contents : null ,
371+ stat : {
372+ isSymbolicLink : isSymbolicLink ,
373+ } ,
374+ } ) ;
375+
376+ // `src()` adds this side-effect with `resolveSymlinks` option set to false
377+ file . symlink = neInputDirpath ;
378+
379+ function assert ( files ) {
380+ var lstats = fs . lstatSync ( neOutputDirpath ) ;
381+ var outputLink = fs . readlinkSync ( neOutputDirpath ) ;
382+ var linkTargetExists = fs . existsSync ( outputLink ) ;
383+
384+ expect ( files . length ) . toEqual ( 1 ) ;
385+ expect ( outputLink ) . toEqual ( neInputDirpath ) ;
386+ expect ( linkTargetExists ) . toEqual ( false ) ;
387+ expect ( lstats . isSymbolicLink ( ) ) . toEqual ( true ) ;
388+ }
389+
390+ pipe ( [
391+ // This could also be from a different Vinyl adapter
392+ from . obj ( [ file ] ) ,
393+ vfs . dest ( neOutputBase ) ,
394+ concat ( assert ) ,
395+ ] , done ) ;
396+ } ) ;
397+
398+ // There's no way to determine the proper type of link to create with a dangling link
399+ // So we just create a 'file' type symlink
400+ // There's also no real way to test the type that was created
401+ it ( '(windows) receives a virtual symbolic directory and creates a symlink' , function ( done ) {
402+ if ( ! isWindows ) {
403+ this . skip ( ) ;
404+ return ;
405+ }
406+
407+ var file = new File ( {
408+ base : neInputBase ,
409+ path : neInputDirpath ,
410+ contents : null ,
411+ stat : {
412+ isSymbolicLink : isSymbolicLink ,
413+ } ,
414+ } ) ;
415+
416+ // `src()` adds this side-effect with `resolveSymlinks` option set to false
417+ file . symlink = neInputDirpath ;
418+
419+ function assert ( files ) {
420+ var lstats = fs . lstatSync ( neOutputDirpath ) ;
421+ var outputLink = fs . readlinkSync ( neOutputDirpath ) ;
422+ var linkTargetExists = fs . existsSync ( outputLink ) ;
423+
424+ expect ( files . length ) . toEqual ( 1 ) ;
425+ expect ( outputLink ) . toEqual ( neInputDirpath ) ;
426+ expect ( linkTargetExists ) . toEqual ( false ) ;
427+ expect ( lstats . isSymbolicLink ( ) ) . toEqual ( true ) ;
428+ }
429+
430+ pipe ( [
431+ // This could also be from a different Vinyl adapter
432+ from . obj ( [ file ] ) ,
433+ vfs . dest ( neOutputBase ) ,
434+ concat ( assert ) ,
435+ ] , done ) ;
436+ } ) ;
437+
273438 it ( '(windows) relativeSymlinks option is ignored when junctions are used' , function ( done ) {
274439 if ( ! isWindows ) {
275440 this . skip ( ) ;
@@ -281,7 +446,7 @@ describe('.dest() with symlinks', function() {
281446 path : inputDirpath ,
282447 contents : null ,
283448 stat : {
284- isDirectory : isDirectory ,
449+ isSymbolicLink : isSymbolicLink ,
285450 } ,
286451 } ) ;
287452
@@ -317,6 +482,9 @@ describe('.dest() with symlinks', function() {
317482 base : inputBase ,
318483 path : inputPath ,
319484 contents : null ,
485+ stat : {
486+ isSymbolicLink : isSymbolicLink ,
487+ } ,
320488 } ) ;
321489
322490 // `src()` adds this side-effect with `resolveSymlinks` option set to false
@@ -348,7 +516,7 @@ describe('.dest() with symlinks', function() {
348516 path : inputDirpath ,
349517 contents : null ,
350518 stat : {
351- isDirectory : isDirectory ,
519+ isSymbolicLink : isSymbolicLink ,
352520 } ,
353521 } ) ;
354522
@@ -383,6 +551,9 @@ describe('.dest() with symlinks', function() {
383551 base : inputBase ,
384552 path : inputPath ,
385553 contents : null ,
554+ stat : {
555+ isSymbolicLink : isSymbolicLink ,
556+ } ,
386557 } ) ;
387558
388559 // `src()` adds this side-effect with `resolveSymlinks` option set to false
@@ -414,6 +585,9 @@ describe('.dest() with symlinks', function() {
414585 base : inputBase ,
415586 path : inputPath ,
416587 contents : null ,
588+ stat : {
589+ isSymbolicLink : isSymbolicLink ,
590+ } ,
417591 } ) ;
418592
419593 // `src()` adds this side-effect with `resolveSymlinks` option set to false
@@ -444,6 +618,9 @@ describe('.dest() with symlinks', function() {
444618 base : inputBase ,
445619 path : inputPath ,
446620 contents : null ,
621+ stat : {
622+ isSymbolicLink : isSymbolicLink ,
623+ } ,
447624 } ) ;
448625
449626 // `src()` adds this side-effect with `resolveSymlinks` option set to false
@@ -479,6 +656,9 @@ describe('.dest() with symlinks', function() {
479656 base : inputBase ,
480657 path : inputPath ,
481658 contents : null ,
659+ stat : {
660+ isSymbolicLink : isSymbolicLink ,
661+ } ,
482662 } ) ;
483663
484664 // `src()` adds this side-effect with `resolveSymlinks` option set to false
0 commit comments