@@ -2,7 +2,7 @@ import { utimes, writeFile } from 'node:fs/promises';
22import { join } from 'node:path' ;
33import { expectType } from 'ts-expect' ;
44import { describe , expect , test } from 'vitest' ;
5- import { getPaths , getSelfAndUpperPaths } from './get-paths.js' ;
5+ import { getPaths , getSelfAndUpperPaths , slash } from './get-paths.js' ;
66import { fixtureDir } from './test/util.js' ;
77
88test ( 'getSelfAndUpperPaths' , ( ) => {
@@ -17,6 +17,7 @@ describe('getPaths', () => {
1717 'b.txt' : 'b' ,
1818 } ,
1919 fixtureDir ,
20+ false ,
2021 ) ;
2122 expect ( paths ) . toStrictEqual ( {
2223 'a.txt' : join ( fixtureDir , 'a.txt' ) ,
@@ -43,6 +44,7 @@ describe('getPaths', () => {
4344 } ,
4445 } ,
4546 fixtureDir ,
47+ false ,
4648 ) ;
4749 expect ( paths ) . toStrictEqual ( {
4850 'a.txt' : join ( fixtureDir , 'a.txt' ) ,
@@ -74,6 +76,7 @@ describe('getPaths', () => {
7476 } ,
7577 } ,
7678 fixtureDir ,
79+ false ,
7780 ) ;
7881 expect ( paths ) . toStrictEqual ( {
7982 'a' : join ( fixtureDir , 'a' ) ,
@@ -100,29 +103,29 @@ describe('getPaths', () => {
100103 } ) ;
101104
102105 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 (
104107 `[Error: Item name must not start with separator: /a.txt]` ,
105108 ) ;
106- expect ( ( ) => getPaths ( { '/a' : { } } , fixtureDir ) ) . toThrowErrorMatchingInlineSnapshot (
109+ expect ( ( ) => getPaths ( { '/a' : { } } , fixtureDir , false ) ) . toThrowErrorMatchingInlineSnapshot (
107110 `[Error: Item name must not start with separator: /a]` ,
108111 ) ;
109112 // 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 ( ) ;
111114 } ) ;
112115
113116 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 (
115118 `[Error: Item name must not end with separator: a.txt/]` ,
116119 ) ;
117- expect ( ( ) => getPaths ( { 'a/' : { } } , fixtureDir ) ) . toThrowErrorMatchingInlineSnapshot (
120+ expect ( ( ) => getPaths ( { 'a/' : { } } , fixtureDir , false ) ) . toThrowErrorMatchingInlineSnapshot (
118121 `[Error: Item name must not end with separator: a/]` ,
119122 ) ;
120123 // 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 ( ) ;
122125 } ) ;
123126
124127 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 (
126129 `[Error: Item name must not contain consecutive separators: a//a.txt]` ,
127130 ) ;
128131 } ) ;
@@ -143,6 +146,7 @@ describe('getPaths', () => {
143146 } ,
144147 } ,
145148 fixtureDir ,
149+ false ,
146150 ) ;
147151 expect ( paths ) . toStrictEqual ( {
148152 'a.txt' : join ( fixtureDir , 'a.txt' ) ,
@@ -185,6 +189,7 @@ describe('getPaths', () => {
185189 } ,
186190 } ,
187191 fixtureDir ,
192+ false ,
188193 ) ;
189194 expect ( paths ) . toStrictEqual ( {
190195 'utime.txt' : join ( fixtureDir , 'utime.txt' ) ,
@@ -196,30 +201,47 @@ describe('getPaths', () => {
196201 // eslint-disable-next-line @typescript-eslint/no-unused-expressions
197202 paths [ 'a.txt' ] ;
198203 } ) ;
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+ } ) ;
216246 } ) ;
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' ] ;
225247} ) ;
0 commit comments