-
-
Notifications
You must be signed in to change notification settings - Fork 632
/
filepath.test.ts
29 lines (24 loc) · 1.45 KB
/
filepath.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { getFilePath } from './filepath'
describe('getFilePath', () => {
it('Should return file path correctly', async () => {
expect(getFilePath({ filename: 'foo' })).toBe('foo/index.html')
expect(getFilePath({ filename: 'foo.txt' })).toBe('foo.txt')
expect(getFilePath({ filename: 'foo', root: 'bar' })).toBe('bar/foo/index.html')
expect(getFilePath({ filename: 'foo.txt', root: 'bar' })).toBe('bar/foo.txt')
expect(getFilePath({ filename: 'foo', defaultDocument: 'index.txt' })).toBe('foo/index.txt')
expect(getFilePath({ filename: 'foo', root: 'bar', defaultDocument: 'index.txt' })).toBe(
'bar/foo/index.txt'
)
expect(getFilePath({ filename: './foo' })).toBe('foo/index.html')
expect(getFilePath({ filename: 'foo', root: './bar' })).toBe('bar/foo/index.html')
expect(getFilePath({ filename: '../foo' })).toBeUndefined()
expect(getFilePath({ filename: '/../foo' })).toBeUndefined()
expect(getFilePath({ filename: './../foo' })).toBeUndefined()
expect(getFilePath({ filename: 'foo..bar.txt' })).toBe('foo..bar.txt')
expect(getFilePath({ filename: '/foo..bar.txt' })).toBe('foo..bar.txt')
expect(getFilePath({ filename: './foo..bar.txt' })).toBe('foo..bar.txt')
expect(getFilePath({ filename: './..foo/bar.txt' })).toBe('..foo/bar.txt')
expect(getFilePath({ filename: './foo../bar.txt' })).toBe('foo../bar.txt')
expect(getFilePath({ filename: './..foo../bar.txt' })).toBe('..foo../bar.txt')
})
})