Skip to content
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