Open History to see the last commit
1import { afterEach, describe, expect, test, vi } from 'vitest'
2β
3const originalPlatform = Object.getOwnPropertyDescriptor(process, 'platform')
4β
5async function importUtilsWithPlatform(platform: NodeJS.Platform) {
6 vi.resetModules()
7 Object.defineProperty(process, 'platform', {
8 ...originalPlatform,
9 value: platform,
10 })
11β
12 return await import('../src/utils')
13}
14β
15afterEach(() => {
16 vi.resetModules()
17 if (originalPlatform) {
18 Object.defineProperty(process, 'platform', originalPlatform)
19 }
20})
21β
22describe('normalizePath', () => {
23 test('normalizes POSIX path segments on POSIX platforms', async () => {
24 const { normalizePath } = await importUtilsWithPlatform('linux')
25β
26 expect(normalizePath('/app//src/../routes/index.tsx')).toBe(
27 '/app/routes/index.tsx',
28 )
29 })
30β
31 test('normalizes empty paths like path.posix.normalize', async () => {
32 const { normalizePath } = await importUtilsWithPlatform('linux')
33β
34 expect(normalizePath('')).toBe('.')
35 })
36β
37 test('keeps Windows separators as normal characters on POSIX platforms', async () => {
38 const { normalizePath } = await importUtilsWithPlatform('linux')
39 const input = String.raw`C:\app\src\..\routes\index.tsx`
40β
41 expect(normalizePath(input)).toBe(input)
42 })
43β
44 test('converts Windows separators before POSIX normalization on Windows', async () => {
45 const { normalizePath } = await importUtilsWithPlatform('win32')
46β
47 expect(normalizePath(String.raw`C:\app\src\..\routes\index.tsx`)).toBe(
48 'C:/app/routes/index.tsx',
49 )
50 })
51})