-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
feat(gatsby-plugin-sharp): Add image plugin defaults #29147
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { testPluginOptionsSchema } from "gatsby-plugin-utils" | ||
import { pluginOptionsSchema } from "../../gatsby-node" | ||
|
||
describe(`pluginOptionsSchema`, () => { | ||
it(`should reject incorrect options`, async () => { | ||
const options = { | ||
defaults: { | ||
formats: [`gif`, `webp`], | ||
placeholder: `base64`, | ||
quality: `great`, | ||
breakpoints: [`mobile`], | ||
backgroundColor: 0, | ||
tracedSVGOptions: null, | ||
transformOptions: false, | ||
blurredOptions: 1, | ||
jpgOptions: `none`, | ||
pngOptions: [{}], | ||
webpOptions: /a/, | ||
avifOptions: 1, | ||
}, | ||
} | ||
const { isValid, errors } = await testPluginOptionsSchema( | ||
pluginOptionsSchema, | ||
options | ||
) | ||
expect(isValid).toBe(false) | ||
expect(errors).toEqual([ | ||
`"defaults.formats[0]" must be one of [auto, png, jpg, webp, avif]`, | ||
`"defaults.placeholder" must be one of [tracedSVG, dominantColor, blurred, none]`, | ||
`"defaults.quality" must be a number`, | ||
`"defaults.breakpoints[0]" must be a number`, | ||
`"defaults.backgroundColor" must be a string`, | ||
`"defaults.transformOptions" must be of type object`, | ||
`"defaults.tracedSVGOptions" must be of type object`, | ||
`"defaults.blurredOptions" must be of type object`, | ||
`"defaults.jpgOptions" must be of type object`, | ||
`"defaults.pngOptions" must be of type object`, | ||
`"defaults.avifOptions" must be of type object`, | ||
]) | ||
}) | ||
|
||
it(`should accept correct options`, async () => { | ||
const options = { | ||
defaults: { | ||
formats: [`auto`, `webp`], | ||
placeholder: `dominantColor`, | ||
quality: 50, | ||
breakpoints: [100, 200], | ||
backgroundColor: `rebeccapurple`, | ||
tracedSVGOptions: {}, | ||
blurredOptions: { quality: 20 }, | ||
jpgOptions: { quality: 20 }, | ||
pngOptions: { quality: 20 }, | ||
webpOptions: { quality: 20 }, | ||
avifOptions: { quality: 20 }, | ||
}, | ||
} | ||
const { isValid } = await testPluginOptionsSchema( | ||
pluginOptionsSchema, | ||
options | ||
) | ||
expect(isValid).toBe(true) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,4 +215,27 @@ exports.pluginOptionsSchema = ({ Joi }) => | |
stripMetadata: Joi.boolean().default(true), | ||
defaultQuality: Joi.number().default(50), | ||
failOnError: Joi.boolean().default(true), | ||
defaults: Joi.object({ | ||
formats: Joi.array().items( | ||
Joi.string().valid(`auto`, `png`, `jpg`, `webp`, `avif`) | ||
), | ||
placeholder: Joi.string().valid( | ||
`tracedSVG`, | ||
`dominantColor`, | ||
`blurred`, | ||
`none` | ||
), | ||
quality: Joi.number(), | ||
breakpoints: Joi.array().items(Joi.number()), | ||
backgroundColor: Joi.string(), | ||
transformOptions: Joi.object(), | ||
tracedSVGOptions: Joi.object(), | ||
blurredOptions: Joi.object(), | ||
jpgOptions: Joi.object(), | ||
pngOptions: Joi.object(), | ||
webpOptions: Joi.object(), | ||
avifOptions: Joi.object(), | ||
}).description( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. transformOptions? Any of the sizing stuff like aspectRatio? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think the sizing options make sense to have as global defaults. I guess transformOptions could though. I'll add them. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ya, my one thought was aspectRatio could, since it's more look and feel that strict sizing. But no strong feelings on that one. |
||
`Default options used by gatsby-plugin-image. \nSee https://gatsbyjs.com/docs/reference/built-in-components/gatsby-plugin-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.
is jpeg valid?
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.
No