-
Notifications
You must be signed in to change notification settings - Fork 10.3k
fix(gatsby-remark-image-contentful): show useful error message for files that can not be rendered as image #32530
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
fix(gatsby-remark-image-contentful): show useful error message for files that can not be rendered as image #32530
Conversation
|
Tested this locally in my reduced tescase from #32511 and works great! |
|
@bartveneman awesome, thanks for testing. |
wardpeet
left a comment
There was a problem hiding this 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 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| return { metadata: mockedSharpMetadata } | |
| return { metadata: jest.fn() } |
There was a problem hiding this comment.
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
| const mockSharpSuccess = () => { | ||
| mockedSharpMetadata = jest.fn(() => { | ||
| return { | ||
| width: 200, | ||
| height: 200, | ||
| density: 75, | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| const mockSharpFailure = () => { | ||
| mockedSharpMetadata = jest.fn(() => | ||
| Promise.reject(new Error(`invalid image`)) | ||
| ) | ||
| } |
There was a problem hiding this comment.
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 :)
| 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`) | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see comment above
fixes #32511