Skip to content

Commit

Permalink
fix(util): replace index.get.tsx to index.get correctly (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
yusukebe authored Feb 16, 2024
1 parent b68870f commit a3e872f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export const filePathToPath = (filePath: string) => {
filePath = filePath
.replace(/\.tsx?$/g, '')
.replace(/\.mdx$/g, '')
.replace(/^\/?index/, '/') // `/index`
.replace(/\/index/, '') // `/about/index`
.replace(/^\/?index$/, '/') // `/index`
.replace(/\/index$/, '') // `/about/index`
.replace(/\[\.{3}.+\]/, '*')
.replace(/\[(.+)\]/, ':$1')
return /^\//.test(filePath) ? filePath : '/' + filePath
Expand Down
2 changes: 2 additions & 0 deletions test/unit/utils/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import {
describe('filePathToPath', () => {
it('Should return a correct path', () => {
expect(filePathToPath('index.tsx')).toBe('/')
expect(filePathToPath('index.get.tsx')).toBe('/index.get')
expect(filePathToPath('about.tsx')).toBe('/about')
expect(filePathToPath('about/index.tsx')).toBe('/about')
expect(filePathToPath('about/me')).toBe('/about/me')
expect(filePathToPath('about/me/index.tsx')).toBe('/about/me')
expect(filePathToPath('about/me/address.tsx')).toBe('/about/me/address')

expect(filePathToPath('/index.tsx')).toBe('/')
expect(filePathToPath('/index.get.tsx')).toBe('/index.get')
expect(filePathToPath('/about.tsx')).toBe('/about')
expect(filePathToPath('/about/index.tsx')).toBe('/about')
expect(filePathToPath('/about/me')).toBe('/about/me')
Expand Down

0 comments on commit a3e872f

Please sign in to comment.