From 49fdb53ecd1857b67d7bb078bcd2bb42e352b7cb Mon Sep 17 00:00:00 2001 From: Max Stoiber Date: Tue, 27 Oct 2020 13:10:32 +0100 Subject: [PATCH] fix(gatsby-plugin-manifest): fix plugin option schema and add a test for it (#27565) * fix(gatsby-plugin-manifest): fix plugin option schema and add a test for it * Remove .only * Fix dependency version --- packages/gatsby-plugin-manifest/package.json | 1 + .../src/__tests__/gatsby-node.js | 15 ++++++++++++++- .../gatsby-plugin-manifest/src/gatsby-node.js | 4 ++-- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-plugin-manifest/package.json b/packages/gatsby-plugin-manifest/package.json index 7312f8a088e01..7bc3d70bedb71 100644 --- a/packages/gatsby-plugin-manifest/package.json +++ b/packages/gatsby-plugin-manifest/package.json @@ -9,6 +9,7 @@ "dependencies": { "@babel/runtime": "^7.11.2", "gatsby-core-utils": "^1.3.23", + "gatsby-plugin-utils": "0.2.35", "semver": "^7.3.2", "sharp": "^0.25.4" }, diff --git a/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js index 16cfe17183cb5..998f7b4aee766 100644 --- a/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js @@ -61,7 +61,8 @@ const reporter = { } }), } -const { onPostBootstrap } = require(`../gatsby-node`) +const { onPostBootstrap, pluginOptionsSchema } = require(`../gatsby-node`) +const { testPluginOptionsSchema } = require(`gatsby-plugin-utils`) const apiArgs = { reporter, @@ -524,3 +525,15 @@ describe(`Test plugin manifest options`, () => { expect(fs.copyFileSync).toHaveBeenCalledTimes(0) }) }) + +describe(`pluginOptionsSchema`, () => { + it(`validates options correctly`, () => { + expect(testPluginOptionsSchema(pluginOptionsSchema, manifestOptions)) + .toMatchInlineSnapshot(` + Object { + "errors": Array [], + "isValid": true, + } + `) + }) +}) diff --git a/packages/gatsby-plugin-manifest/src/gatsby-node.js b/packages/gatsby-plugin-manifest/src/gatsby-node.js index ef7bac75aaa1f..9b07663fc3007 100644 --- a/packages/gatsby-plugin-manifest/src/gatsby-node.js +++ b/packages/gatsby-plugin-manifest/src/gatsby-node.js @@ -59,7 +59,7 @@ async function checkCache(cache, icon, srcIcon, srcIconDigest, callback) { } if (process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION) { - exports.pluginOptionsSchema = ({ Joi }) => { + exports.pluginOptionsSchema = ({ Joi }) => Joi.object({ name: Joi.string(), short_name: Joi.string(), @@ -89,13 +89,13 @@ if (process.env.GATSBY_EXPERIMENTAL_PLUGIN_OPTION_VALIDATION) { src: Joi.string(), sizes: Joi.string(), type: Joi.string(), + purpose: Joi.string(), }) ), icon_options: Joi.object({ purpose: Joi.string(), }), }) - } } /**