@@ -2,7 +2,7 @@ import { utimes, writeFile } from 'node:fs/promises';
2
2
import { join } from 'node:path' ;
3
3
import { expectType } from 'ts-expect' ;
4
4
import { describe , expect , test } from 'vitest' ;
5
- import { getPaths , getSelfAndUpperPaths } from './get-paths.js' ;
5
+ import { getPaths , getSelfAndUpperPaths , slash } from './get-paths.js' ;
6
6
import { fixtureDir } from './test/util.js' ;
7
7
8
8
test ( 'getSelfAndUpperPaths' , ( ) => {
@@ -17,6 +17,7 @@ describe('getPaths', () => {
17
17
'b.txt' : 'b' ,
18
18
} ,
19
19
fixtureDir ,
20
+ false ,
20
21
) ;
21
22
expect ( paths ) . toStrictEqual ( {
22
23
'a.txt' : join ( fixtureDir , 'a.txt' ) ,
@@ -43,6 +44,7 @@ describe('getPaths', () => {
43
44
} ,
44
45
} ,
45
46
fixtureDir ,
47
+ false ,
46
48
) ;
47
49
expect ( paths ) . toStrictEqual ( {
48
50
'a.txt' : join ( fixtureDir , 'a.txt' ) ,
@@ -74,6 +76,7 @@ describe('getPaths', () => {
74
76
} ,
75
77
} ,
76
78
fixtureDir ,
79
+ false ,
77
80
) ;
78
81
expect ( paths ) . toStrictEqual ( {
79
82
'a' : join ( fixtureDir , 'a' ) ,
@@ -100,29 +103,29 @@ describe('getPaths', () => {
100
103
} ) ;
101
104
102
105
test ( 'throw error when item name starts with separator' , ( ) => {
103
- expect ( ( ) => getPaths ( { '/a.txt' : 'a' } , fixtureDir ) ) . toThrowErrorMatchingInlineSnapshot (
106
+ expect ( ( ) => getPaths ( { '/a.txt' : 'a' } , fixtureDir , false ) ) . toThrowErrorMatchingInlineSnapshot (
104
107
`[Error: Item name must not start with separator: /a.txt]` ,
105
108
) ;
106
- expect ( ( ) => getPaths ( { '/a' : { } } , fixtureDir ) ) . toThrowErrorMatchingInlineSnapshot (
109
+ expect ( ( ) => getPaths ( { '/a' : { } } , fixtureDir , false ) ) . toThrowErrorMatchingInlineSnapshot (
107
110
`[Error: Item name must not start with separator: /a]` ,
108
111
) ;
109
112
// NOTE: Use of Windows path separator is an undefined behavior.
110
- expect ( ( ) => getPaths ( { '\\a.txt' : 'a' } , fixtureDir ) ) . not . toThrow ( ) ;
113
+ expect ( ( ) => getPaths ( { '\\a.txt' : 'a' } , fixtureDir , false ) ) . not . toThrow ( ) ;
111
114
} ) ;
112
115
113
116
test ( 'throw error when item name ends with separator' , ( ) => {
114
- expect ( ( ) => getPaths ( { 'a.txt/' : 'a' } , fixtureDir ) ) . toThrowErrorMatchingInlineSnapshot (
117
+ expect ( ( ) => getPaths ( { 'a.txt/' : 'a' } , fixtureDir , false ) ) . toThrowErrorMatchingInlineSnapshot (
115
118
`[Error: Item name must not end with separator: a.txt/]` ,
116
119
) ;
117
- expect ( ( ) => getPaths ( { 'a/' : { } } , fixtureDir ) ) . toThrowErrorMatchingInlineSnapshot (
120
+ expect ( ( ) => getPaths ( { 'a/' : { } } , fixtureDir , false ) ) . toThrowErrorMatchingInlineSnapshot (
118
121
`[Error: Item name must not end with separator: a/]` ,
119
122
) ;
120
123
// NOTE: Use of Windows path separator is an undefined behavior.
121
- expect ( ( ) => getPaths ( { 'a.txt\\' : 'a' } , fixtureDir ) ) . not . toThrow ( ) ;
124
+ expect ( ( ) => getPaths ( { 'a.txt\\' : 'a' } , fixtureDir , false ) ) . not . toThrow ( ) ;
122
125
} ) ;
123
126
124
127
test ( 'throw error when item name contains consecutive separators' , ( ) => {
125
- expect ( ( ) => getPaths ( { 'a//a.txt' : 'a--a' } , fixtureDir ) ) . toThrowErrorMatchingInlineSnapshot (
128
+ expect ( ( ) => getPaths ( { 'a//a.txt' : 'a--a' } , fixtureDir , false ) ) . toThrowErrorMatchingInlineSnapshot (
126
129
`[Error: Item name must not contain consecutive separators: a//a.txt]` ,
127
130
) ;
128
131
} ) ;
@@ -143,6 +146,7 @@ describe('getPaths', () => {
143
146
} ,
144
147
} ,
145
148
fixtureDir ,
149
+ false ,
146
150
) ;
147
151
expect ( paths ) . toStrictEqual ( {
148
152
'a.txt' : join ( fixtureDir , 'a.txt' ) ,
@@ -185,6 +189,7 @@ describe('getPaths', () => {
185
189
} ,
186
190
} ,
187
191
fixtureDir ,
192
+ false ,
188
193
) ;
189
194
expect ( paths ) . toStrictEqual ( {
190
195
'utime.txt' : join ( fixtureDir , 'utime.txt' ) ,
@@ -196,30 +201,47 @@ describe('getPaths', () => {
196
201
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
197
202
paths [ 'a.txt' ] ;
198
203
} ) ;
199
- } ) ;
200
-
201
- test ( 'allow function and null as items' , ( ) => {
202
- const paths = getPaths (
203
- {
204
- 'a.txt' : null ,
205
- // eslint-disable-next-line @typescript-eslint/naming-convention
206
- 'b.txt' : ( ) => { } ,
207
- // eslint-disable-next-line @typescript-eslint/naming-convention
208
- 'c.txt' : async ( ) => { } ,
209
- } ,
210
- fixtureDir ,
211
- ) ;
212
- expect ( paths ) . toStrictEqual ( {
213
- 'a.txt' : join ( fixtureDir , 'a.txt' ) ,
214
- 'b.txt' : join ( fixtureDir , 'b.txt' ) ,
215
- 'c.txt' : join ( fixtureDir , 'c.txt' ) ,
204
+ test ( 'allow function and null as items' , ( ) => {
205
+ const paths = getPaths (
206
+ {
207
+ 'a.txt' : null ,
208
+ // eslint-disable-next-line @typescript-eslint/naming-convention
209
+ 'b.txt' : ( ) => { } ,
210
+ // eslint-disable-next-line @typescript-eslint/naming-convention
211
+ 'c.txt' : async ( ) => { } ,
212
+ } ,
213
+ fixtureDir ,
214
+ false ,
215
+ ) ;
216
+ expect ( paths ) . toStrictEqual ( {
217
+ 'a.txt' : join ( fixtureDir , 'a.txt' ) ,
218
+ 'b.txt' : join ( fixtureDir , 'b.txt' ) ,
219
+ 'c.txt' : join ( fixtureDir , 'c.txt' ) ,
220
+ } ) ;
221
+ expectType < {
222
+ 'a.txt' : string ;
223
+ 'b.txt' : string ;
224
+ 'c.txt' : string ;
225
+ } > ( paths ) ;
226
+ // @ts -expect-error
227
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
228
+ paths [ 'd.txt' ] ;
229
+ } ) ;
230
+ test . runIf ( process . platform === 'win32' ) ( 'convert windows path separator to unix path separator' , ( ) => {
231
+ const paths = getPaths (
232
+ {
233
+ 'a.txt' : 'a' ,
234
+ 'b' : {
235
+ 'a.txt' : 'b-a' ,
236
+ } ,
237
+ } ,
238
+ fixtureDir ,
239
+ true ,
240
+ ) ;
241
+ expect ( paths ) . toStrictEqual ( {
242
+ 'a.txt' : slash ( join ( fixtureDir , 'a.txt' ) ) ,
243
+ 'b' : slash ( join ( fixtureDir , 'b' ) ) ,
244
+ 'b/a.txt' : slash ( join ( fixtureDir , 'b/a.txt' ) ) ,
245
+ } ) ;
216
246
} ) ;
217
- expectType < {
218
- 'a.txt' : string ;
219
- 'b.txt' : string ;
220
- 'c.txt' : string ;
221
- } > ( paths ) ;
222
- // @ts -expect-error
223
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
224
- paths [ 'd.txt' ] ;
225
247
} ) ;
0 commit comments