@@ -2,6 +2,7 @@ import { readdir, readFile, rm, writeFile } from 'node:fs/promises';
2
2
import { join } from 'node:path' ;
3
3
import { expectType } from 'ts-expect' ;
4
4
import { beforeEach , describe , expect , test , vi } from 'vitest' ;
5
+ import { slash } from './get-paths.js' ;
5
6
import { defineIFFCreator } from './index.js' ;
6
7
import { exists , fixtureDir } from './test/util.js' ;
7
8
@@ -188,12 +189,54 @@ describe('CreateIFFResult', () => {
188
189
const iff = await createIFF ( { } ) ;
189
190
expect ( iff . rootDir ) . toBe ( join ( fixtureDir , 'a' ) ) ;
190
191
} ) ;
191
- test ( 'join' , async ( ) => {
192
- const iff = await createIFF ( { 'a.txt' : 'a' } ) ;
193
- expect ( iff . join ( 'a.txt' ) ) . toBe ( join ( fixtureDir , 'a.txt' ) ) ;
194
- expect ( iff . join ( '/a.txt' ) ) . toBe ( join ( fixtureDir , 'a.txt' ) ) ;
195
- expect ( iff . join ( 'nonexistent-file.txt' ) ) . toBe ( join ( fixtureDir , 'nonexistent-file.txt' ) ) ;
196
- expect ( iff . join ( '' ) ) . toBe ( fixtureDir ) ;
192
+ describe ( 'paths' , ( ) => {
193
+ test ( 'basic' , async ( ) => {
194
+ const iff = await createIFF ( {
195
+ 'a.txt' : 'a' ,
196
+ 'b' : {
197
+ 'a.txt' : 'b-a' ,
198
+ } ,
199
+ } ) ;
200
+ expect ( iff . paths ) . toStrictEqual ( {
201
+ 'a.txt' : join ( fixtureDir , 'a.txt' ) ,
202
+ 'b' : join ( fixtureDir , 'b' ) ,
203
+ 'b/a.txt' : join ( fixtureDir , 'b/a.txt' ) ,
204
+ } ) ;
205
+ expectType < {
206
+ 'a.txt' : string ;
207
+ 'b' : string ;
208
+ 'b/a.txt' : string ;
209
+ } > ( iff . paths ) ;
210
+ // @ts -expect-error
211
+ // eslint-disable-next-line @typescript-eslint/no-unused-expressions
212
+ iff . paths [ 'b/b.txt' ] ;
213
+ } ) ;
214
+ test . runIf ( process . platform === 'win32' ) ( 'useUnixPathSeparator' , async ( ) => {
215
+ const iff = await createIFF ( {
216
+ 'a.txt' : 'a' ,
217
+ 'b' : {
218
+ 'a.txt' : 'b-a' ,
219
+ } ,
220
+ } ) ;
221
+ expect ( iff . paths ) . toStrictEqual ( {
222
+ 'a.txt' : slash ( join ( fixtureDir , 'a.txt' ) ) ,
223
+ 'b' : slash ( join ( fixtureDir , 'b' ) ) ,
224
+ 'b/a.txt' : slash ( join ( fixtureDir , 'b/a.txt' ) ) ,
225
+ } ) ;
226
+ } ) ;
227
+ } ) ;
228
+ describe ( 'join' , ( ) => {
229
+ test ( 'basic' , async ( ) => {
230
+ const iff = await createIFF ( { 'a.txt' : 'a' } ) ;
231
+ expect ( iff . join ( 'a.txt' ) ) . toBe ( join ( fixtureDir , 'a.txt' ) ) ;
232
+ expect ( iff . join ( '/a.txt' ) ) . toBe ( join ( fixtureDir , 'a.txt' ) ) ;
233
+ expect ( iff . join ( 'nonexistent-file.txt' ) ) . toBe ( join ( fixtureDir , 'nonexistent-file.txt' ) ) ;
234
+ expect ( iff . join ( '' ) ) . toBe ( fixtureDir ) ;
235
+ } ) ;
236
+ test . runIf ( process . platform === 'win32' ) ( 'useUnixPathSeparator' , async ( ) => {
237
+ const iff = await createIFF ( { } ) ;
238
+ expect ( iff . join ( 'a.txt' ) ) . toBe ( slash ( join ( fixtureDir , 'a.txt' ) ) ) ;
239
+ } ) ;
197
240
} ) ;
198
241
test ( 'rmFixtures' , async ( ) => {
199
242
const iff = await createIFF ( {
0 commit comments