Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gatsby-plugin-sharp: Remove incorrect warning when requested width === image width #3537

Merged
merged 1 commit into from
Jan 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -50,6 +50,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 @@ -475,7 +475,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