1
1
import { resolve } from 'node:path' ;
2
+ import { mkdir } from 'node:fs/promises' ;
2
3
3
4
import test from 'ava' ;
4
- import { copy , ensureDir } from 'fs-extra' ;
5
5
import { isPlainObject , sortBy } from 'lodash-es' ;
6
6
import tempy from 'tempy' ;
7
+ import cpy from 'cpy' ;
7
8
8
9
import globAssets from '../lib/glob-assets.js' ;
9
10
@@ -13,31 +14,31 @@ const fixtures = 'test/fixtures/files';
13
14
14
15
test ( 'Retrieve file from single path' , async ( t ) => {
15
16
const cwd = tempy . directory ( ) ;
16
- await copy ( fixtures , cwd ) ;
17
+ await cpy ( fixtures , cwd , { dot : true } ) ;
17
18
const globbedAssets = await globAssets ( { cwd} , [ 'upload.txt' ] ) ;
18
19
19
20
t . deepEqual ( globbedAssets , [ 'upload.txt' ] ) ;
20
21
} ) ;
21
22
22
23
test ( 'Retrieve multiple files from path' , async ( t ) => {
23
24
const cwd = tempy . directory ( ) ;
24
- await copy ( fixtures , cwd ) ;
25
+ await cpy ( fixtures , cwd , { dot : true } ) ;
25
26
const globbedAssets = await globAssets ( { cwd} , [ 'upload.txt' , 'upload_other.txt' ] ) ;
26
27
27
28
t . deepEqual ( sortAssets ( globbedAssets ) , sortAssets ( [ 'upload_other.txt' , 'upload.txt' ] ) ) ;
28
29
} ) ;
29
30
30
31
test ( 'Include missing files as defined, using Object definition' , async ( t ) => {
31
32
const cwd = tempy . directory ( ) ;
32
- await copy ( fixtures , cwd ) ;
33
+ await cpy ( fixtures , cwd , { dot : true } ) ;
33
34
const globbedAssets = await globAssets ( { cwd} , [ 'upload.txt' , { path : 'miss*.txt' , label : 'Missing' } ] ) ;
34
35
35
36
t . deepEqual ( sortAssets ( globbedAssets ) , sortAssets ( [ 'upload.txt' , { path : 'miss*.txt' , label : 'Missing' } ] ) ) ;
36
37
} ) ;
37
38
38
39
test ( 'Retrieve multiple files from Object' , async ( t ) => {
39
40
const cwd = tempy . directory ( ) ;
40
- await copy ( fixtures , cwd ) ;
41
+ await cpy ( fixtures , cwd , { dot : true } ) ;
41
42
const globbedAssets = await globAssets ( { cwd} , [
42
43
{ path : 'upload.txt' , name : 'upload_name' , label : 'Upload label' } ,
43
44
'upload_other.txt' ,
@@ -51,7 +52,7 @@ test('Retrieve multiple files from Object', async (t) => {
51
52
52
53
test ( 'Retrieve multiple files without duplicates' , async ( t ) => {
53
54
const cwd = tempy . directory ( ) ;
54
- await copy ( fixtures , cwd ) ;
55
+ await cpy ( fixtures , cwd , { dot : true } ) ;
55
56
const globbedAssets = await globAssets ( { cwd} , [
56
57
'upload_other.txt' ,
57
58
'upload.txt' ,
@@ -66,7 +67,7 @@ test('Retrieve multiple files without duplicates', async (t) => {
66
67
67
68
test ( 'Favor Object over String values when removing duplicates' , async ( t ) => {
68
69
const cwd = tempy . directory ( ) ;
69
- await copy ( fixtures , cwd ) ;
70
+ await cpy ( fixtures , cwd , { dot : true } ) ;
70
71
const globbedAssets = await globAssets ( { cwd} , [
71
72
'upload_other.txt' ,
72
73
'upload.txt' ,
@@ -88,47 +89,47 @@ test('Favor Object over String values when removing duplicates', async (t) => {
88
89
89
90
test ( 'Retrieve file from single glob' , async ( t ) => {
90
91
const cwd = tempy . directory ( ) ;
91
- await copy ( fixtures , cwd ) ;
92
+ await cpy ( fixtures , cwd , { dot : true } ) ;
92
93
const globbedAssets = await globAssets ( { cwd} , [ 'upload.*' ] ) ;
93
94
94
95
t . deepEqual ( globbedAssets , [ 'upload.txt' ] ) ;
95
96
} ) ;
96
97
97
98
test ( 'Retrieve multiple files from single glob' , async ( t ) => {
98
99
const cwd = tempy . directory ( ) ;
99
- await copy ( fixtures , cwd ) ;
100
+ await cpy ( fixtures , cwd , { dot : true } ) ;
100
101
const globbedAssets = await globAssets ( { cwd} , [ '*.txt' ] ) ;
101
102
102
103
t . deepEqual ( sortAssets ( globbedAssets ) , sortAssets ( [ 'upload_other.txt' , 'upload.txt' ] ) ) ;
103
104
} ) ;
104
105
105
106
test ( 'Accept glob array with one value' , async ( t ) => {
106
107
const cwd = tempy . directory ( ) ;
107
- await copy ( fixtures , cwd ) ;
108
+ await cpy ( fixtures , cwd , { dot : true } ) ;
108
109
const globbedAssets = await globAssets ( { cwd} , [ [ '*load.txt' ] , [ '*_other.txt' ] ] ) ;
109
110
110
111
t . deepEqual ( sortAssets ( globbedAssets ) , sortAssets ( [ 'upload_other.txt' , 'upload.txt' ] ) ) ;
111
112
} ) ;
112
113
113
114
test ( 'Include globs that resolve to no files as defined' , async ( t ) => {
114
115
const cwd = tempy . directory ( ) ;
115
- await copy ( fixtures , cwd ) ;
116
+ await cpy ( fixtures , cwd , { dot : true } ) ;
116
117
const globbedAssets = await globAssets ( { cwd} , [ [ 'upload.txt' , '!upload.txt' ] ] ) ;
117
118
118
119
t . deepEqual ( sortAssets ( globbedAssets ) , sortAssets ( [ '!upload.txt' , 'upload.txt' ] ) ) ;
119
120
} ) ;
120
121
121
122
test ( 'Accept glob array with one value for missing files' , async ( t ) => {
122
123
const cwd = tempy . directory ( ) ;
123
- await copy ( fixtures , cwd ) ;
124
+ await cpy ( fixtures , cwd , { dot : true } ) ;
124
125
const globbedAssets = await globAssets ( { cwd} , [ [ '*missing.txt' ] , [ '*_other.txt' ] ] ) ;
125
126
126
127
t . deepEqual ( sortAssets ( globbedAssets ) , sortAssets ( [ 'upload_other.txt' , '*missing.txt' ] ) ) ;
127
128
} ) ;
128
129
129
130
test ( 'Replace name by filename for Object that match multiple files' , async ( t ) => {
130
131
const cwd = tempy . directory ( ) ;
131
- await copy ( fixtures , cwd ) ;
132
+ await cpy ( fixtures , cwd , { dot : true } ) ;
132
133
const globbedAssets = await globAssets ( { cwd} , [ { path : '*.txt' , name : 'upload_name' , label : 'Upload label' } ] ) ;
133
134
134
135
t . deepEqual (
@@ -142,56 +143,56 @@ test('Replace name by filename for Object that match multiple files', async (t)
142
143
143
144
test ( 'Include dotfiles' , async ( t ) => {
144
145
const cwd = tempy . directory ( ) ;
145
- await copy ( fixtures , cwd ) ;
146
+ await cpy ( fixtures , cwd , { dot : true } ) ;
146
147
const globbedAssets = await globAssets ( { cwd} , [ '.dot*' ] ) ;
147
148
148
149
t . deepEqual ( globbedAssets , [ '.dotfile' ] ) ;
149
150
} ) ;
150
151
151
152
test ( 'Ingnore single negated glob' , async ( t ) => {
152
153
const cwd = tempy . directory ( ) ;
153
- await copy ( fixtures , cwd ) ;
154
+ await cpy ( fixtures , cwd , { dot : true } ) ;
154
155
const globbedAssets = await globAssets ( { cwd} , [ '!*.txt' ] ) ;
155
156
156
157
t . deepEqual ( globbedAssets , [ ] ) ;
157
158
} ) ;
158
159
159
160
test ( 'Ingnore single negated glob in Object' , async ( t ) => {
160
161
const cwd = tempy . directory ( ) ;
161
- await copy ( fixtures , cwd ) ;
162
+ await cpy ( fixtures , cwd , { dot : true } ) ;
162
163
const globbedAssets = await globAssets ( { cwd} , [ { path : '!*.txt' } ] ) ;
163
164
164
165
t . deepEqual ( globbedAssets , [ ] ) ;
165
166
} ) ;
166
167
167
168
test ( 'Accept negated globs' , async ( t ) => {
168
169
const cwd = tempy . directory ( ) ;
169
- await copy ( fixtures , cwd ) ;
170
+ await cpy ( fixtures , cwd , { dot : true } ) ;
170
171
const globbedAssets = await globAssets ( { cwd} , [ [ '*.txt' , '!**/*_other.txt' ] ] ) ;
171
172
172
173
t . deepEqual ( globbedAssets , [ 'upload.txt' ] ) ;
173
174
} ) ;
174
175
175
176
test ( 'Expand directories' , async ( t ) => {
176
177
const cwd = tempy . directory ( ) ;
177
- await copy ( fixtures , resolve ( cwd , 'dir' ) ) ;
178
+ await cpy ( fixtures , resolve ( cwd , 'dir' ) , { dot : true } ) ;
178
179
const globbedAssets = await globAssets ( { cwd} , [ [ 'dir' ] ] ) ;
179
180
180
181
t . deepEqual ( sortAssets ( globbedAssets ) , sortAssets ( [ 'dir' , 'dir/upload_other.txt' , 'dir/upload.txt' , 'dir/.dotfile' ] ) ) ;
181
182
} ) ;
182
183
183
184
test ( 'Include empty tempy.directory as defined' , async ( t ) => {
184
185
const cwd = tempy . directory ( ) ;
185
- await copy ( fixtures , cwd ) ;
186
- await ensureDir ( resolve ( cwd , 'empty' ) ) ;
186
+ await cpy ( fixtures , cwd , { dot : true } ) ;
187
+ await mkdir ( resolve ( cwd , 'empty' ) , { recursive : true } ) ;
187
188
const globbedAssets = await globAssets ( { cwd} , [ [ 'empty' ] ] ) ;
188
189
189
190
t . deepEqual ( globbedAssets , [ 'empty' ] ) ;
190
191
} ) ;
191
192
192
193
test ( 'Deduplicate resulting files path' , async ( t ) => {
193
194
const cwd = tempy . directory ( ) ;
194
- await copy ( fixtures , cwd ) ;
195
+ await cpy ( fixtures , cwd , { dot : true } ) ;
195
196
const globbedAssets = await globAssets ( { cwd} , [ './upload.txt' , resolve ( cwd , 'upload.txt' ) , 'upload.txt' ] ) ;
196
197
197
198
t . is ( globbedAssets . length , 1 ) ;
0 commit comments