Skip to content

Commit

Permalink
gatsby-plugin-sharp: Remove warning for resolutions when requested wi…
Browse files Browse the repository at this point in the history
…dth and image width are equal (gatsbyjs#3537)
  • Loading branch information
dannywils authored and jastack committed Jan 24, 2018
1 parent 3912e79 commit ccd179c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
38 changes: 37 additions & 1 deletion packages/gatsby-plugin-sharp/src/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require(`path`)

const { base64, responsiveSizes } = require(`../`)
const { base64, responsiveSizes, resolutions } = require(`../`)

describe(`gatsby-plugin-sharp`, () => {
const args = {
Expand Down Expand Up @@ -73,6 +73,42 @@ describe(`gatsby-plugin-sharp`, () => {
})
})

describe(`resolutions`, () => {
console.warn = jest.fn()

beforeEach(() => {
console.warn.mockClear()
})

afterAll(() => {
console.warn.mockClear()
})

it(`does not warn when the requested width is equal to the image width`, async () => {
const args = { width: 1 }

const result = await resolutions({
file,
args,
})

expect(result.width).toEqual(1)
expect(console.warn).toHaveBeenCalledTimes(0)
})

it(`warns when the requested width is greater than the image width`, async () => {
const args = { width: 2 }

const result = await resolutions({
file,
args,
})

expect(result.width).toEqual(1)
expect(console.warn).toHaveBeenCalledTimes(1)
})
})

describe(`base64`, () => {
it(`converts image to base64`, async () => {
const result = await base64({
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ async function resolutions({ file, args = {} }) {
sizes.push(options.width * 3)
const dimensions = imageSize(file.absolutePath)

const filteredSizes = sizes.filter(size => size < dimensions.width)
const filteredSizes = sizes.filter(size => size <= dimensions.width)

// If there's no sizes after filtering (e.g. image is smaller than what's
// requested, add back the original so there's at least something)
Expand Down

0 comments on commit ccd179c

Please sign in to comment.