Skip to content

Commit 2155005

Browse files
committed
test: add tests
1 parent cd340ed commit 2155005

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

src/get-paths.test.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { utimes, writeFile } from 'node:fs/promises';
22
import { join } from 'node:path';
33
import { expectType } from 'ts-expect';
44
import { describe, expect, test } from 'vitest';
5-
import { getPaths, getSelfAndUpperPaths } from './get-paths.js';
5+
import { getPaths, getSelfAndUpperPaths, slash } from './get-paths.js';
66
import { fixtureDir } from './test/util.js';
77

88
test('getSelfAndUpperPaths', () => {
@@ -227,4 +227,21 @@ describe('getPaths', () => {
227227
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
228228
paths['d.txt'];
229229
});
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+
});
246+
});
230247
});

src/index.test.ts

+49-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { readdir, readFile, rm, writeFile } from 'node:fs/promises';
22
import { join } from 'node:path';
33
import { expectType } from 'ts-expect';
44
import { beforeEach, describe, expect, test, vi } from 'vitest';
5+
import { slash } from './get-paths.js';
56
import { defineIFFCreator } from './index.js';
67
import { exists, fixtureDir } from './test/util.js';
78

@@ -188,12 +189,54 @@ describe('CreateIFFResult', () => {
188189
const iff = await createIFF({});
189190
expect(iff.rootDir).toBe(join(fixtureDir, 'a'));
190191
});
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+
});
197240
});
198241
test('rmFixtures', async () => {
199242
const iff = await createIFF({

0 commit comments

Comments
 (0)