Skip to content
Myr

filepath.test.ts

This file

Path

src/utils/filepath.test.ts

67 lines · 3.0 KiB · TypeScript

Last changed by

Not known.

History of this file

Take it

The walk stopped after 200 commits: lines older than 82bdc4d point at it.

4.9.0Yusuke Wadabefore adoption82bdc4d

lines 1–67why, one step back
1import { getFilePath, getFilePathWithoutDefaultDocument } from './filepath'
23describe('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})4849describe('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 )5960 expect(getFilePath({ filename: 'filename.suffix_index' })).toBe('filename.suffix_index')61 expect(getFilePath({ filename: 'filename.suffix-index' })).toBe('filename.suffix-index')62 })63})6465function slashToBackslash(filename: string) {66 return filename.split('/').join('\\')67}