This repository has been archived by the owner on Dec 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for the new pluginOptionsSchema function in gatsby-…
…node (#15)
- Loading branch information
1 parent
2ed6b9a
commit 691be05
Showing
5 changed files
with
68 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const jest = require("kcd-scripts/jest"); | ||
|
||
module.exports = { | ||
...jest, | ||
coverageThreshold: null, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { testPluginOptionsSchema } from "gatsby-plugin-utils"; | ||
|
||
import { pluginOptionsSchema } from "../gatsby-node"; | ||
|
||
test.each` | ||
saveButton | expectedErrors | ||
${"This should be a boolean or an object"} | ${['"saveButton" must be one of [boolean, object]']} | ||
${{ round: "This should be a boolean", tall: "This should be a boolean" }} | ${['"saveButton" does not match any of the allowed types']} | ||
${{ round: "This should be a boolean", tall: true }} | ${['"saveButton.round" must be a boolean']} | ||
${{ round: true, tall: "This should be a boolean" }} | ${['"saveButton.tall" must be a boolean']} | ||
`( | ||
"should provide meaningful errors when fields are invalid: $saveButton", | ||
async ({ expectedErrors, saveButton }) => { | ||
const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { | ||
saveButton, | ||
}); | ||
|
||
expect(errors).toEqual(expectedErrors); | ||
}, | ||
); | ||
|
||
test.each` | ||
saveButton | ||
${undefined} | ||
${true} | ||
${false} | ||
${{}} | ||
${{ round: true }} | ||
${{ round: false }} | ||
${{ tall: true }} | ||
${{ tall: false }} | ||
${{ round: true, tall: true }} | ||
`("should validate the schema: $saveButton", async ({ saveButton }) => { | ||
const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { | ||
saveButton, | ||
}); | ||
|
||
expect(isValid).toBe(true); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,21 @@ | ||
const deprecationWarning = `[gatsby-plugin-pinterest] From now on, you can use the 'saveButton' option to show Pinterest's save button on images. | ||
if (process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION) { | ||
exports.pluginOptionsSchema = ({ Joi }) => | ||
Joi.object({ | ||
saveButton: Joi.alternatives().try( | ||
Joi.boolean(), | ||
Joi.object({ | ||
round: Joi.boolean(), | ||
tall: Joi.boolean(), | ||
}), | ||
), | ||
}); | ||
} else { | ||
const deprecationWarning = `[gatsby-plugin-pinterest] From now on, you can use the 'saveButton' option to show Pinterest's save button on images. | ||
See https://github.com/robinmetral/gatsby-plugin-pinterest#usage`; | ||
|
||
exports.onPreInit = ({ reporter }, { round, tall } = {}) => { | ||
if (round || tall) { | ||
reporter.warn(deprecationWarning); | ||
} | ||
}; | ||
exports.onPreInit = ({ reporter }, { round, tall } = {}) => { | ||
if (round || tall) { | ||
reporter.warn(deprecationWarning); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION = "true"; |