|
1 | 1 | import {describe, it, expect} from 'vitest'; |
2 | | -import {getVirtualRoutesV3} from './get-virtual-routes.js'; |
| 2 | +import { |
| 3 | + getVirtualRoutesV3, |
| 4 | + createVirtualRoutesPath, |
| 5 | +} from './get-virtual-routes.js'; |
3 | 6 |
|
4 | 7 | describe('virtual routes', () => { |
5 | 8 | it('gets virtual routes V3', async () => { |
@@ -30,15 +33,36 @@ describe('virtual routes', () => { |
30 | 33 | }); |
31 | 34 | }); |
32 | 35 |
|
33 | | - it('handles file paths with spaces correctly', async () => { |
34 | | - const result = await getVirtualRoutesV3(); |
| 36 | + it('decodes URL-encoded file paths with spaces', () => { |
| 37 | + // Mock import.meta.url with a path containing a space |
| 38 | + const mockImportMetaUrl = |
| 39 | + 'file:///path/with%20space/vite/get-virtual-routes.ts'; |
35 | 40 |
|
36 | | - result.routes.forEach((route) => { |
37 | | - expect(route.file).not.toContain('%20'); |
38 | | - expect(route.file).not.toContain('%'); |
39 | | - }); |
| 41 | + const result = createVirtualRoutesPath( |
| 42 | + mockImportMetaUrl, |
| 43 | + ['vite', 'virtual-routes'], |
| 44 | + 'layout.jsx', |
| 45 | + ); |
| 46 | + |
| 47 | + // Should decode %20 to actual space |
| 48 | + expect(result).toContain('with space'); |
| 49 | + expect(result).not.toContain('%20'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('removes Windows drive path prefix (e.g. /C:/)', () => { |
| 53 | + // Mock a Windows file URL with drive letter |
| 54 | + const mockWindowsUrl = |
| 55 | + 'file:///C:/Users/developer/project/vite/get-virtual-routes.ts'; |
| 56 | + |
| 57 | + const result = createVirtualRoutesPath( |
| 58 | + mockWindowsUrl, |
| 59 | + ['vite', 'virtual-routes'], |
| 60 | + 'layout.jsx', |
| 61 | + ); |
40 | 62 |
|
41 | | - expect(result.layout.file).not.toContain('%20'); |
42 | | - expect(result.layout.file).not.toContain('%'); |
| 63 | + // Should remove /C:/ prefix and start with / |
| 64 | + expect(result).not.toMatch(/^\/[a-zA-Z]:\//); |
| 65 | + expect(result).toMatch(/^\//); |
| 66 | + expect(result).toContain('layout.jsx'); |
43 | 67 | }); |
44 | 68 | }); |
0 commit comments