Skip to content

Commit

Permalink
fix(gatsby-remark-images): adding missing plugin options (#27944)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Frachet authored Nov 12, 2020
1 parent 001e045 commit 08447bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions packages/gatsby-remark-images/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe(`pluginOptionsSchema`, () => {
`"wrapperStyle" must be one of [object, string]`,
`"backgroundColor" must be a string`,
`"quality" must be a number`,
`"withWebp" must be a boolean`,
`"withWebp" must be one of [object, boolean]`,
`"tracedSVG" must be a boolean`,
`"loading" must be one of [lazy, eager, auto]`,
`"disableBgImageOnAlpha" must be a boolean`,
Expand All @@ -29,7 +29,7 @@ describe(`pluginOptionsSchema`, () => {
wrapperStyle: true,
backgroundColor: 123,
quality: `This should be a number`,
withWebp: `This should be a boolean`,
withWebp: `This should be a boolean or an object`,
tracedSVG: `This should be a boolean`,
loading: `This should be lazy, eager or auto`,
disableBgImageOnAlpha: `This should be a boolean`,
Expand Down Expand Up @@ -60,4 +60,12 @@ describe(`pluginOptionsSchema`, () => {

expect(isValid).toBe(true)
})

it(`should validate the withWebp prop`, async () => {
const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, {
withWebp: { quality: 100 },
})

expect(isValid).toBe(true)
})
})
3 changes: 2 additions & 1 deletion packages/gatsby-remark-images/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ exports.pluginOptionsSchema = function ({ Joi }) {
quality: Joi.number()
.default(50)
.description(`The quality level of the generated files.`),
withWebp: Joi.boolean()
withWebp: Joi.alternatives()
.try(Joi.object({ quality: Joi.number() }), Joi.boolean())
.default(false)
.description(
`Additionally generate WebP versions alongside your chosen file format. They are added as a srcset with the appropriate mimetype and will be loaded in browsers that support the format. Pass true for default support, or an object of options to specifically override those for the WebP files. For example, pass { quality: 80 } to have the WebP images be at quality level 80.`
Expand Down

0 comments on commit 08447bd

Please sign in to comment.