Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Apr 17, 2024
1 parent d94d9c5 commit 7374e36
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions packages/shared/tests/inferRoutePath.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { describe, expect, it } from 'vitest'
import { inferRoutePath } from '../src/index.js'

const testCases = [
// absolute index
['/', '/'],
['/README.md', '/'],
['/readme.md', '/'],
['/index.md', '/'],
['/index.html', '/'],
['/index', '/'],
['/foo/', '/foo/'],
['/foo/README.md', '/foo/'],
['/foo/readme.md', '/foo/'],
['/foo/index.md', '/foo/'],
['/foo/index.html', '/foo/'],
['/foo/index', '/foo/'],
['README.md', 'index.html'],
['readme.md', 'index.html'],
['index.md', 'index.html'],
['index.html', 'index.html'],
['index', 'index.html'],

// absolute non-index
['/foo', '/foo.html'],
['/foo.md', '/foo.html'],
['/foo.html', '/foo.html'],
['/foo/bar', '/foo/bar.html'],
['/foo/bar.md', '/foo/bar.html'],
['/foo/bar.html', '/foo/bar.html'],

// relative index without current
['foo/', 'foo/'],
['foo/README.md', 'foo/'],
['foo/readme.md', 'foo/'],
['foo/index.md', 'foo/'],
['foo/index.html', 'foo/'],
['foo/index', 'foo/'],

// relative non index without current
['foo', 'foo.html'],
['foo.md', 'foo.html'],
['foo.html', 'foo.html'],
['foo/bar', 'foo/bar.html'],
['foo/bar.md', 'foo/bar.html'],
['foo/bar.html', 'foo/bar.html'],

// unexpected corner cases
['', ''],
['.md', '.html'],
['foo/.md', 'foo/.html'],
['/.md', '/.html'],
['/foo/.md', '/foo/.html'],
]

describe('should normalize clean paths correctly', () => {
testCases.forEach(([path, expected]) =>
it(`"${path}" -> "${expected}"`, () => {
expect(inferRoutePath(path)).toBe(expected)
}),
)
})

0 comments on commit 7374e36

Please sign in to comment.