@@ -125,6 +125,60 @@ test('cwd', async t => {
125125 ) ;
126126} ) ;
127127
128+ test ( 'cwd with glob *' , async t => {
129+ fs . mkdirSync ( t . context . tmp ) ;
130+ fs . mkdirSync ( path . join ( t . context . tmp , 'cwd' ) ) ;
131+ fs . writeFileSync (
132+ path . join ( t . context . tmp , 'cwd/hello.js' ) ,
133+ 'console.log("hello");' ,
134+ ) ;
135+
136+ await cpy ( [ '*' ] , 'destination' , {
137+ cwd : path . join ( t . context . tmp , 'cwd' ) ,
138+ } ) ;
139+
140+ t . is (
141+ read ( t . context . tmp , 'cwd/hello.js' ) ,
142+ read ( t . context . tmp , 'cwd/destination/hello.js' ) ,
143+ ) ;
144+ } ) ;
145+
146+ test ( 'cwd with glob * and relative destination' , async t => {
147+ fs . mkdirSync ( t . context . tmp ) ;
148+ fs . mkdirSync ( path . join ( t . context . tmp , 'cwd' ) ) ;
149+ fs . writeFileSync (
150+ path . join ( t . context . tmp , 'cwd/hello.js' ) ,
151+ 'console.log("hello");' ,
152+ ) ;
153+
154+ await cpy ( [ '*' ] , '../destination' , {
155+ cwd : path . join ( t . context . tmp , 'cwd' ) ,
156+ } ) ;
157+
158+ t . is (
159+ read ( t . context . tmp , 'cwd/hello.js' ) ,
160+ read ( t . context . tmp , 'destination/hello.js' ) ,
161+ ) ;
162+ } ) ;
163+
164+ test ( 'cwd with glob ./*' , async t => {
165+ fs . mkdirSync ( t . context . tmp ) ;
166+ fs . mkdirSync ( path . join ( t . context . tmp , 'cwd' ) ) ;
167+ fs . writeFileSync (
168+ path . join ( t . context . tmp , 'cwd/hello.js' ) ,
169+ 'console.log("hello");' ,
170+ ) ;
171+
172+ await cpy ( [ './*' ] , 'destination' , {
173+ cwd : path . join ( t . context . tmp , 'cwd' ) ,
174+ } ) ;
175+
176+ t . is (
177+ read ( t . context . tmp , 'cwd/hello.js' ) ,
178+ read ( t . context . tmp , 'cwd/destination/hello.js' ) ,
179+ ) ;
180+ } ) ;
181+
128182test ( 'do not overwrite' , async t => {
129183 fs . mkdirSync ( t . context . tmp ) ;
130184 fs . writeFileSync ( path . join ( t . context . tmp , 'license' ) , '' ) ;
@@ -480,3 +534,88 @@ test('returns destination path', async t => {
480534 path . join ( t . context . tmp , 'bar' ) ,
481535 ] ) ;
482536} ) ;
537+
538+ test ( 'absolute directory source paths' , async t => {
539+ fs . mkdirSync ( t . context . tmp ) ;
540+ fs . mkdirSync ( path . join ( t . context . tmp , 'source' ) ) ;
541+ fs . mkdirSync ( path . join ( t . context . tmp , 'out' ) ) ;
542+ fs . writeFileSync (
543+ path . join ( t . context . tmp , 'source/hello.js' ) ,
544+ 'console.log("hello");' ,
545+ ) ;
546+
547+ await cpy ( [ path . join ( t . context . tmp , 'source' ) ] , path . join ( t . context . tmp , 'out' ) ) ;
548+
549+ t . is (
550+ read ( t . context . tmp , 'source/hello.js' ) ,
551+ read ( t . context . tmp , 'out/hello.js' ) ,
552+ ) ;
553+ } ) ;
554+
555+ test ( 'absolute file source paths' , async t => {
556+ fs . mkdirSync ( t . context . tmp ) ;
557+ fs . mkdirSync ( path . join ( t . context . tmp , 'out' ) ) ;
558+ fs . writeFileSync (
559+ path . join ( t . context . tmp , 'hello.js' ) ,
560+ 'console.log("hello");' ,
561+ ) ;
562+
563+ await cpy ( [ path . join ( t . context . tmp , 'hello.js' ) ] , path . join ( t . context . tmp , 'out' ) ) ;
564+
565+ t . is (
566+ read ( t . context . tmp , 'hello.js' ) ,
567+ read ( t . context . tmp , 'out/hello.js' ) ,
568+ ) ;
569+ } ) ;
570+
571+ test ( 'negative patterns' , async t => {
572+ fs . mkdirSync ( t . context . tmp ) ;
573+ fs . mkdirSync ( path . join ( t . context . tmp , 'source' ) ) ;
574+ fs . mkdirSync ( path . join ( t . context . tmp , 'out' ) ) ;
575+ fs . writeFileSync ( path . join ( t . context . tmp , 'source/keep.js' ) , 'console.log("keep");' ) ;
576+ fs . writeFileSync ( path . join ( t . context . tmp , 'source/ignore.js' ) , 'console.log("ignore");' ) ;
577+ fs . writeFileSync ( path . join ( t . context . tmp , 'source/also-keep.txt' ) , 'keep this' ) ;
578+
579+ await cpy ( [ 'source/*' , '!source/ignore.js' ] , path . join ( t . context . tmp , 'out' ) , {
580+ cwd : t . context . tmp ,
581+ } ) ;
582+
583+ t . is (
584+ read ( t . context . tmp , 'source/keep.js' ) ,
585+ read ( t . context . tmp , 'out/keep.js' ) ,
586+ ) ;
587+ t . is (
588+ read ( t . context . tmp , 'source/also-keep.txt' ) ,
589+ read ( t . context . tmp , 'out/also-keep.txt' ) ,
590+ ) ;
591+ t . false ( fs . existsSync ( path . join ( t . context . tmp , 'out/ignore.js' ) ) ) ;
592+ } ) ;
593+
594+ test ( 'recursive directory copying' , async t => {
595+ fs . mkdirSync ( t . context . tmp ) ;
596+ fs . mkdirSync ( path . join ( t . context . tmp , 'source' ) ) ;
597+ fs . mkdirSync ( path . join ( t . context . tmp , 'source/nested' ) ) ;
598+ fs . mkdirSync ( path . join ( t . context . tmp , 'source/nested/deep' ) ) ;
599+ fs . mkdirSync ( path . join ( t . context . tmp , 'out' ) ) ;
600+
601+ fs . writeFileSync ( path . join ( t . context . tmp , 'source/file1.js' ) , 'console.log("file1");' ) ;
602+ fs . writeFileSync ( path . join ( t . context . tmp , 'source/nested/file2.js' ) , 'console.log("file2");' ) ;
603+ fs . writeFileSync ( path . join ( t . context . tmp , 'source/nested/deep/file3.js' ) , 'console.log("file3");' ) ;
604+
605+ await cpy ( [ 'source/**' ] , path . join ( t . context . tmp , 'out' ) , {
606+ cwd : t . context . tmp ,
607+ } ) ;
608+
609+ t . is (
610+ read ( t . context . tmp , 'source/file1.js' ) ,
611+ read ( t . context . tmp , 'out/file1.js' ) ,
612+ ) ;
613+ t . is (
614+ read ( t . context . tmp , 'source/nested/file2.js' ) ,
615+ read ( t . context . tmp , 'out/nested/file2.js' ) ,
616+ ) ;
617+ t . is (
618+ read ( t . context . tmp , 'source/nested/deep/file3.js' ) ,
619+ read ( t . context . tmp , 'out/nested/deep/file3.js' ) ,
620+ ) ;
621+ } ) ;
0 commit comments