-
Notifications
You must be signed in to change notification settings - Fork 27.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional tests for image type detection
- Loading branch information
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
test/integration/image-optimizer/test/detect-content-type.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* eslint-env jest */ | ||
import { detectContentType } from '../../../../packages/next/dist/server/image-optimizer.js' | ||
import { readFile } from 'fs/promises' | ||
import { join } from 'path' | ||
|
||
const getImage = (filepath) => readFile(join(__dirname, filepath)) | ||
|
||
describe('detectContentType', () => { | ||
it('should return jpg', async () => { | ||
const buffer = await getImage('../public/test.jpg') | ||
expect(detectContentType(buffer)).toBe('image/jpeg') | ||
}) | ||
it('should return png', async () => { | ||
const buffer = await getImage('../public/test.png') | ||
expect(detectContentType(buffer)).toBe('image/png') | ||
}) | ||
it('should return webp', async () => { | ||
const buffer = await getImage('../public/animated.webp') | ||
expect(detectContentType(buffer)).toBe('image/webp') | ||
}) | ||
it('should return svg', async () => { | ||
const buffer = await getImage('../public/test.svg') | ||
expect(detectContentType(buffer)).toBe('image/svg+xml') | ||
}) | ||
}) |