Skip to content
Myr

filepath.test.ts

This file

Path

src/utils/filepath.test.ts

64 lines · 2.8 KiB · TypeScript

Last changed by

fix(serve-static): support extensionless files and refactor (#2260)Yusuke Wadabefore adoptionf8371ab

History of this file

Take it

The walk stopped after 200 commits: lines older than 2f9a07d point at it.

fix(serve-static): support extensionless files and refactor (#2260)Yusuke Wadabefore adoptionf8371ab

line 1why, one step back
1import { getFilePath, getFilePathWithoutDefaultDocument } from './filepath'

perf(hono-base): use `instanceOf` (#1565)Yusuke Wadabefore adoption2f9a07d

line 2why, one step back
2

fix(serve-static): support extensionless files and refactor (#2260)Yusuke Wadabefore adoptionf8371ab

lines 3–48why, one step back
3describe('getFilePathWithoutDefaultDocument', () => {
4 it('Should return file path correctly', async () => {5 expect(getFilePathWithoutDefaultDocument({ filename: 'foo.txt' })).toBe('foo.txt')6 expect(getFilePathWithoutDefaultDocument({ filename: 'foo.txt', root: 'bar' })).toBe(7 'bar/foo.txt'8 )910 expect(getFilePathWithoutDefaultDocument({ filename: '../foo' })).toBeUndefined()11 expect(getFilePathWithoutDefaultDocument({ filename: '/../foo' })).toBeUndefined()12 expect(getFilePathWithoutDefaultDocument({ filename: './../foo' })).toBeUndefined()13 expect(getFilePathWithoutDefaultDocument({ filename: 'foo..bar.txt' })).toBe('foo..bar.txt')14 expect(getFilePathWithoutDefaultDocument({ filename: '/foo..bar.txt' })).toBe('foo..bar.txt')15 expect(getFilePathWithoutDefaultDocument({ filename: './foo..bar.txt' })).toBe('foo..bar.txt')16 expect(getFilePathWithoutDefaultDocument({ filename: './..foo/bar.txt' })).toBe('..foo/bar.txt')17 expect(getFilePathWithoutDefaultDocument({ filename: './foo../bar.txt' })).toBe('foo../bar.txt')18 expect(getFilePathWithoutDefaultDocument({ filename: './..foo../bar.txt' })).toBe(19 '..foo../bar.txt'20 )2122 expect(23 getFilePathWithoutDefaultDocument({ filename: slashToBackslash('/../foo') })24 ).toBeUndefined()25 expect(26 getFilePathWithoutDefaultDocument({ filename: slashToBackslash('./../foo') })27 ).toBeUndefined()28 expect(getFilePathWithoutDefaultDocument({ filename: slashToBackslash('foo..bar.txt') })).toBe(29 'foo..bar.txt'30 )31 expect(getFilePathWithoutDefaultDocument({ filename: slashToBackslash('/foo..bar.txt') })).toBe(32 'foo..bar.txt'33 )34 expect(35 getFilePathWithoutDefaultDocument({ filename: slashToBackslash('./foo..bar.txt') })36 ).toBe('foo..bar.txt')37 expect(38 getFilePathWithoutDefaultDocument({ filename: slashToBackslash('./..foo/bar.txt') })39 ).toBe('..foo/bar.txt')40 expect(41 getFilePathWithoutDefaultDocument({ filename: slashToBackslash('./foo../bar.txt') })42 ).toBe('foo../bar.txt')43 expect(44 getFilePathWithoutDefaultDocument({ filename: slashToBackslash('./..foo../bar.txt') })45 ).toBe('..foo../bar.txt')46 })47})48

perf(hono-base): use `instanceOf` (#1565)Yusuke Wadabefore adoption2f9a07d

lines 49–60why, one step back
49describe('getFilePath', () => {
50 it('Should return file path correctly', async () => {51 expect(getFilePath({ filename: 'foo' })).toBe('foo/index.html')5253 expect(getFilePath({ filename: 'foo', root: 'bar' })).toBe('bar/foo/index.html')5455 expect(getFilePath({ filename: 'foo', defaultDocument: 'index.txt' })).toBe('foo/index.txt')56 expect(getFilePath({ filename: 'foo', root: 'bar', defaultDocument: 'index.txt' })).toBe(57 'bar/foo/index.txt'58 )59 })60})

fix(utils/filepath): filepath supports Windows (#1642)Yusuke Wadabefore adoption48dc87d

lines 61–64why, one step back
61
62function slashToBackslash(filename: string) {63 return filename.split('/').join('\\')64}