Skip to content

Conversation

@axe312ger
Copy link
Contributor

fixes #32511

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Jul 28, 2021
@bartveneman
Copy link
Contributor

Tested this locally in my reduced tescase from #32511 and works great!

@axe312ger
Copy link
Contributor Author

@bartveneman awesome, thanks for testing.

@wardpeet wardpeet changed the title fix: show useful error message for files that can not be rendered as image fix(gatsby-remark-image-contentful): show useful error message for files that can not be rendered as image Aug 3, 2021
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small test nits

}
}),
}
return { metadata: mockedSharpMetadata }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return { metadata: mockedSharpMetadata }
return { metadata: jest.fn() }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it closer to how gatsby-plugin-sharp mocks sharp. Please have a look

Comment on lines 25 to 39
const mockSharpSuccess = () => {
mockedSharpMetadata = jest.fn(() => {
return {
width: 200,
height: 200,
density: 75,
}
})
}

const mockSharpFailure = () => {
mockedSharpMetadata = jest.fn(() =>
Promise.reject(new Error(`invalid image`))
)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the proper way to mock :)

Suggested change
const mockSharpSuccess = () => {
mockedSharpMetadata = jest.fn(() => {
return {
width: 200,
height: 200,
density: 75,
}
})
}
const mockSharpFailure = () => {
mockedSharpMetadata = jest.fn(() =>
Promise.reject(new Error(`invalid image`))
)
}
const sharp = require('sharp');
const mockSharpSuccess = () => {
sharp.metadata.mockResolvedValueOnce({
width: 200,
height: 200,
density: 75,
})
}
const mockSharpFailure = () => {
sharp.metadata.mockRejectedValue(new Error(`invalid image`)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comment above

@LekoArts LekoArts added topic: plugins Related to plugin system, themes & catch-all for plugins that don't have a label and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Aug 4, 2021
@wardpeet wardpeet merged commit 77e9aab into master Aug 6, 2021
@wardpeet wardpeet deleted the fix/gatsby-remark-images-contentful-invalid-images branch August 6, 2021 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: plugins Related to plugin system, themes & catch-all for plugins that don't have a label

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[gatsby-remark-images-contentful] No stack trace on unsupported image format

5 participants