-
Notifications
You must be signed in to change notification settings - Fork 0
/
findRouteFiles.test.ts
100 lines (95 loc) · 2.87 KB
/
findRouteFiles.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import mockFs from 'mock-fs'
import { convertRoutePathToPagePath } from '../convertRoutePathToPagePath'
import { findRouteFiles } from '../findRouteFiles'
describe('findRouteFiles', () => {
afterEach(() => {
// Restore the real filesystem after each test
mockFs.restore()
})
it('should return the expected RouteFile objects', () => {
// Set up a mocked filesystem
mockFs({
'/mocked/path/routes': {
// Index routes
'(page).js': '',
'(layout).tsx': '',
'(loading).jsx': '',
'(error).tsx': '',
'(route).ts': '',
// Nested routes
'test1.(page).tsx': '',
'test2.(layout).tsx': '',
'test2.foo.[...any].[id].bar.(loading).tsx': '',
'test2.(error).tsx': '',
'test2.(route).tsx': '',
subDir: {
'test3.(error).tsx': '',
},
},
})
const expected = [
// Index routes
{
pagePath: '/mocked/path/(.routes)/error.tsx',
routePath: '/mocked/path/routes/(error).tsx',
},
{
pagePath: '/mocked/path/(.routes)/layout.tsx',
routePath: '/mocked/path/routes/(layout).tsx',
},
{
pagePath: '/mocked/path/(.routes)/loading.jsx',
routePath: '/mocked/path/routes/(loading).jsx',
},
{
pagePath: '/mocked/path/(.routes)/page.js',
routePath: '/mocked/path/routes/(page).js',
},
{
pagePath: '/mocked/path/(.routes)/route.ts',
routePath: '/mocked/path/routes/(route).ts',
},
// Nested routes
{
routePath: '/mocked/path/routes/subDir/test3.(error).tsx',
pagePath: convertRoutePathToPagePath(
'/mocked/path/routes/subDir/test3.(error).tsx'
),
},
{
routePath: '/mocked/path/routes/test1.(page).tsx',
pagePath: convertRoutePathToPagePath(
'/mocked/path/routes/test1.(page).tsx'
),
},
{
routePath: '/mocked/path/routes/test2.(error).tsx',
pagePath: convertRoutePathToPagePath(
'/mocked/path/routes/test2.(error).tsx'
),
},
{
routePath: '/mocked/path/routes/test2.(layout).tsx',
pagePath: convertRoutePathToPagePath(
'/mocked/path/routes/test2.(layout).tsx'
),
},
{
routePath:
'/mocked/path/routes/test2.foo.[...any].[id].bar.(loading).tsx',
pagePath: convertRoutePathToPagePath(
'/mocked/path/routes/test2.foo.[...any].[id].bar.(loading).tsx'
),
},
{
routePath: '/mocked/path/routes/test2.(route).tsx',
pagePath: convertRoutePathToPagePath(
'/mocked/path/routes/test2.(route).tsx'
),
},
]
const result = findRouteFiles('/mocked/path')
expect(result).toEqual(expect.arrayContaining(expected))
expect(expected).toEqual(expect.arrayContaining(result))
})
})