Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Kanta Kodama committed Jan 12, 2021
1 parent e4955fe commit b180fd1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/integration/image-optimizer/test/index.test.js
Expand Up @@ -380,6 +380,44 @@ function runTests({ w, isDev, domains }) {
expect(json2).toStrictEqual(json1)
})

it('should use cached image file when parameters are the same for svg', async () => {
await fs.remove(imagesDir)

const query = { url: '/test.svg', w, q: 80 }
const opts = { headers: { accept: 'image/webp' } }

const res1 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
expect(res1.status).toBe(200)
expect(res1.headers.get('Content-Type')).toBe('image/svg+xml')
const json1 = await fsToJson(imagesDir)
expect(Object.keys(json1).length).toBe(1)

const res2 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
expect(res2.status).toBe(200)
expect(res2.headers.get('Content-Type')).toBe('image/svg+xml')
const json2 = await fsToJson(imagesDir)
expect(json2).toStrictEqual(json1)
})

it('should use cached image file when parameters are the same for animated gif', async () => {
await fs.remove(imagesDir)

const query = { url: '/animated.gif', w, q: 80 }
const opts = { headers: { accept: 'image/webp' } }

const res1 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
expect(res1.status).toBe(200)
expect(res1.headers.get('Content-Type')).toBe('image/gif')
const json1 = await fsToJson(imagesDir)
expect(Object.keys(json1).length).toBe(1)

const res2 = await fetchViaHTTP(appPort, '/_next/image', query, opts)
expect(res2.status).toBe(200)
expect(res2.headers.get('Content-Type')).toBe('image/gif')
const json2 = await fsToJson(imagesDir)
expect(json2).toStrictEqual(json1)
})

it('should set 304 status without body when etag matches if-none-match', async () => {
const query = { url: '/test.jpg', w, q: 80 }
const opts1 = { headers: { accept: 'image/webp' } }
Expand Down

0 comments on commit b180fd1

Please sign in to comment.