@@ -95,6 +95,77 @@ function nextdir() {
9595}
9696
9797
98+ // It throws error when verbatimSymlinks is not a boolean.
99+ {
100+ const src = './test/fixtures/copy/kitchen-sink' ;
101+ [ 1 , [ ] , { } , null , 1n , undefined , null , Symbol ( ) , '' , ( ) => { } ]
102+ . forEach ( ( verbatimSymlinks ) => {
103+ assert . throws (
104+ ( ) => cpSync ( src , src , { verbatimSymlinks } ) ,
105+ { code : 'ERR_INVALID_ARG_TYPE' }
106+ ) ;
107+ } ) ;
108+ }
109+
110+
111+ // It throws an error when both dereference and verbatimSymlinks are enabled.
112+ {
113+ const src = './test/fixtures/copy/kitchen-sink' ;
114+ assert . throws (
115+ ( ) => cpSync ( src , src , { dereference : true , verbatimSymlinks : true } ) ,
116+ { code : 'ERR_INCOMPATIBLE_OPTION_PAIR' }
117+ ) ;
118+ }
119+
120+
121+ // It resolves relative symlinks to their absolute path by default.
122+ {
123+ const src = nextdir ( ) ;
124+ mkdirSync ( src , { recursive : true } ) ;
125+ writeFileSync ( join ( src , 'foo.js' ) , 'foo' , 'utf8' ) ;
126+ symlinkSync ( 'foo.js' , join ( src , 'bar.js' ) ) ;
127+
128+ const dest = nextdir ( ) ;
129+ mkdirSync ( dest , { recursive : true } ) ;
130+
131+ cpSync ( src , dest , { recursive : true } ) ;
132+ const link = readlinkSync ( join ( dest , 'bar.js' ) ) ;
133+ assert . strictEqual ( link , join ( src , 'foo.js' ) ) ;
134+ }
135+
136+
137+ // It resolves relative symlinks when verbatimSymlinks is false.
138+ {
139+ const src = nextdir ( ) ;
140+ mkdirSync ( src , { recursive : true } ) ;
141+ writeFileSync ( join ( src , 'foo.js' ) , 'foo' , 'utf8' ) ;
142+ symlinkSync ( 'foo.js' , join ( src , 'bar.js' ) ) ;
143+
144+ const dest = nextdir ( ) ;
145+ mkdirSync ( dest , { recursive : true } ) ;
146+
147+ cpSync ( src , dest , { recursive : true , verbatimSymlinks : false } ) ;
148+ const link = readlinkSync ( join ( dest , 'bar.js' ) ) ;
149+ assert . strictEqual ( link , join ( src , 'foo.js' ) ) ;
150+ }
151+
152+
153+ // It does not resolve relative symlinks when verbatimSymlinks is true.
154+ {
155+ const src = nextdir ( ) ;
156+ mkdirSync ( src , { recursive : true } ) ;
157+ writeFileSync ( join ( src , 'foo.js' ) , 'foo' , 'utf8' ) ;
158+ symlinkSync ( 'foo.js' , join ( src , 'bar.js' ) ) ;
159+
160+ const dest = nextdir ( ) ;
161+ mkdirSync ( dest , { recursive : true } ) ;
162+
163+ cpSync ( src , dest , { recursive : true , verbatimSymlinks : true } ) ;
164+ const link = readlinkSync ( join ( dest , 'bar.js' ) ) ;
165+ assert . strictEqual ( link , 'foo.js' ) ;
166+ }
167+
168+
98169// It throws error when src and dest are identical.
99170{
100171 const src = './test/fixtures/copy/kitchen-sink' ;
0 commit comments