Skip to content

Commit 7374e36

Browse files
committed
test: add unit tests
1 parent d94d9c5 commit 7374e36

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { inferRoutePath } from '../src/index.js'
3+
4+
const testCases = [
5+
// absolute index
6+
['/', '/'],
7+
['/README.md', '/'],
8+
['/readme.md', '/'],
9+
['/index.md', '/'],
10+
['/index.html', '/'],
11+
['/index', '/'],
12+
['/foo/', '/foo/'],
13+
['/foo/README.md', '/foo/'],
14+
['/foo/readme.md', '/foo/'],
15+
['/foo/index.md', '/foo/'],
16+
['/foo/index.html', '/foo/'],
17+
['/foo/index', '/foo/'],
18+
['README.md', 'index.html'],
19+
['readme.md', 'index.html'],
20+
['index.md', 'index.html'],
21+
['index.html', 'index.html'],
22+
['index', 'index.html'],
23+
24+
// absolute non-index
25+
['/foo', '/foo.html'],
26+
['/foo.md', '/foo.html'],
27+
['/foo.html', '/foo.html'],
28+
['/foo/bar', '/foo/bar.html'],
29+
['/foo/bar.md', '/foo/bar.html'],
30+
['/foo/bar.html', '/foo/bar.html'],
31+
32+
// relative index without current
33+
['foo/', 'foo/'],
34+
['foo/README.md', 'foo/'],
35+
['foo/readme.md', 'foo/'],
36+
['foo/index.md', 'foo/'],
37+
['foo/index.html', 'foo/'],
38+
['foo/index', 'foo/'],
39+
40+
// relative non index without current
41+
['foo', 'foo.html'],
42+
['foo.md', 'foo.html'],
43+
['foo.html', 'foo.html'],
44+
['foo/bar', 'foo/bar.html'],
45+
['foo/bar.md', 'foo/bar.html'],
46+
['foo/bar.html', 'foo/bar.html'],
47+
48+
// unexpected corner cases
49+
['', ''],
50+
['.md', '.html'],
51+
['foo/.md', 'foo/.html'],
52+
['/.md', '/.html'],
53+
['/foo/.md', '/foo/.html'],
54+
]
55+
56+
describe('should normalize clean paths correctly', () => {
57+
testCases.forEach(([path, expected]) =>
58+
it(`"${path}" -> "${expected}"`, () => {
59+
expect(inferRoutePath(path)).toBe(expected)
60+
}),
61+
)
62+
})

0 commit comments

Comments
 (0)