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