-
Notifications
You must be signed in to change notification settings - Fork 28k
/
Copy pathdetect-content-type.test.ts
37 lines (35 loc) · 1.37 KB
/
detect-content-type.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
30
31
32
33
34
35
36
37
/* eslint-env jest */
import { detectContentType } from 'next/dist/server/image-optimizer'
import { readFile } from 'fs-extra'
import { join } from 'path'
const getImage = (filepath) => readFile(join(__dirname, filepath))
describe('detectContentType', () => {
it('should return jpg', async () => {
const buffer = await getImage('./images/test.jpg')
expect(detectContentType(buffer)).toBe('image/jpeg')
})
it('should return png', async () => {
const buffer = await getImage('./images/test.png')
expect(detectContentType(buffer)).toBe('image/png')
})
it('should return webp', async () => {
const buffer = await getImage('./images/animated.webp')
expect(detectContentType(buffer)).toBe('image/webp')
})
it('should return svg', async () => {
const buffer = await getImage('./images/test.svg')
expect(detectContentType(buffer)).toBe('image/svg+xml')
})
it('should return svg for inline svg', async () => {
const buffer = await getImage('./images/test-inline.svg')
expect(detectContentType(buffer)).toBe('image/svg+xml')
})
it('should return avif', async () => {
const buffer = await getImage('./images/test.avif')
expect(detectContentType(buffer)).toBe('image/avif')
})
it('should return icon', async () => {
const buffer = await getImage('./images/test.ico')
expect(detectContentType(buffer)).toBe('image/x-icon')
})
})