From 57b2428cff1ba89118e97d655e9fb52e3e697e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Sat, 10 Apr 2021 15:49:03 +0200 Subject: [PATCH 1/3] tests: update pluginOptionsSchema tests --- .../configuring-usage-with-plugin-options.md | 12 +- .../src/__tests__/gatsby-node.js | 13 +- .../src/__tests__/gatsby-node.js | 13 +- .../src/__tests__/gatsby-node.js | 50 ++-- .../src/__tests__/gatsby-node.js | 14 +- .../__tests__/gatsby-node.js | 86 ++++--- .../src/__tests__/gatsby-node.js | 50 ++-- .../src/__tests__/gatsby-node.js | 126 +++++----- .../src/__tests__/gatsby-node.js | 138 ++++++----- .../src/__tests__/plugin-options.ts | 20 +- .../src/__tests__/gatsby-node.js | 13 +- .../src/__tests__/gatsby-node.js | 52 ++-- packages/gatsby-plugin-utils/README.md | 3 +- .../__tests__/test-plugin-options-schema.ts | 76 +++--- .../src/__tests__/gatsby-node.js | 24 +- .../src/__tests__/gatsby-node.js | 225 +++++++++++------- .../__tests__/plugin-options-schema.test.js | 13 +- .../src/__tests__/gatsby-node.js | 50 ++-- 18 files changed, 552 insertions(+), 426 deletions(-) diff --git a/docs/docs/how-to/plugins-and-themes/configuring-usage-with-plugin-options.md b/docs/docs/how-to/plugins-and-themes/configuring-usage-with-plugin-options.md index 3557a89dee7a8..bf21107a2a588 100644 --- a/docs/docs/how-to/plugins-and-themes/configuring-usage-with-plugin-options.md +++ b/docs/docs/how-to/plugins-and-themes/configuring-usage-with-plugin-options.md @@ -246,17 +246,19 @@ describe(`pluginOptionsSchema`, () => { message: 123, // Should be a string optionB: `not a boolean`, // Should be a boolean } + const expectedErrors = [ + `"optionA" is required`, + `"message" must be a string`, + `"optionB" must be a boolean`, + ] + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, options ) expect(isValid).toBe(false) - expect(errors).toEqual([ - `"optionA" is required`, - `"message" must be a string`, - `"optionB" must be a boolean`, - ]) + expect(errors).toEqual(expectedErrors) }) it(`should validate correct options`, async () => { diff --git a/packages/gatsby-plugin-cxs/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-cxs/src/__tests__/gatsby-node.js index 8494980faf068..28a8a417c155b 100644 --- a/packages/gatsby-plugin-cxs/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-cxs/src/__tests__/gatsby-node.js @@ -5,10 +5,14 @@ import { pluginOptionsSchema } from "../gatsby-node" it(`should provide meaningful errors when fields are invalid`, async () => { const expectedErrors = [`"optionA" is not allowed`] - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - optionA: `This options shouldn't exist`, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + optionA: `This options shouldn't exist`, + } + ) + expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) @@ -17,10 +21,11 @@ it.each` ${undefined} ${{}} `(`should validate the schema: $options`, async ({ options }) => { - const { isValid } = await testPluginOptionsSchema( + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, options ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) diff --git a/packages/gatsby-plugin-glamor/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-glamor/src/__tests__/gatsby-node.js index feb1332bb6f7d..1ed97dc2ec22c 100644 --- a/packages/gatsby-plugin-glamor/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-glamor/src/__tests__/gatsby-node.js @@ -6,10 +6,14 @@ describe(`pluginOptionsSchema`, () => { it(`should provide meaningful errors when fields are invalid`, async () => { const expectedErrors = [`"optionA" is not allowed`] - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - optionA: `This options shouldn't exist`, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + optionA: `This options shouldn't exist`, + } + ) + expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) @@ -18,11 +22,12 @@ describe(`pluginOptionsSchema`, () => { ${undefined} ${{}} `(`should validate the schema: $options`, async ({ options }) => { - const { isValid } = await testPluginOptionsSchema( + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, options ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) }) diff --git a/packages/gatsby-plugin-google-tagmanager/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-google-tagmanager/src/__tests__/gatsby-node.js index 5315f095b1664..17fccf72c333b 100644 --- a/packages/gatsby-plugin-google-tagmanager/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-google-tagmanager/src/__tests__/gatsby-node.js @@ -3,33 +3,41 @@ import { testPluginOptionsSchema } from "gatsby-plugin-utils" describe(`pluginOptionsSchema`, () => { it(`should validate valid options`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - id: `YOUR_GOOGLE_TAGMANAGER_ID`, - includeInDevelopment: false, - defaultDataLayer: { platform: `gatsby` }, - gtmAuth: `YOUR_GOOGLE_TAGMANAGER_ENVIRONMENT_AUTH_STRING`, - gtmPreview: `YOUR_GOOGLE_TAGMANAGER_ENVIRONMENT_PREVIEW_NAME`, - dataLayerName: `YOUR_DATA_LAYER_NAME`, - routeChangeEventName: `YOUR_ROUTE_CHANGE_EVENT_NAME`, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + id: `YOUR_GOOGLE_TAGMANAGER_ID`, + includeInDevelopment: false, + defaultDataLayer: { platform: `gatsby` }, + gtmAuth: `YOUR_GOOGLE_TAGMANAGER_ENVIRONMENT_AUTH_STRING`, + gtmPreview: `YOUR_GOOGLE_TAGMANAGER_ENVIRONMENT_PREVIEW_NAME`, + dataLayerName: `YOUR_DATA_LAYER_NAME`, + routeChangeEventName: `YOUR_ROUTE_CHANGE_EVENT_NAME`, + } + ) expect(isValid).toEqual(true) + expect(errors).toEqual([]) }) it(`should support defaultDataLayer as a function`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - defaultDataLayer: () => { - return { - originalLocation: - document.location.protocol + - `//` + - document.location.hostname + - document.location.pathname + - document.location.search, - } - }, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + defaultDataLayer: () => { + return { + originalLocation: + document.location.protocol + + `//` + + document.location.hostname + + document.location.pathname + + document.location.search, + } + }, + } + ) expect(isValid).toEqual(true) + expect(errors).toEqual([]) }) }) diff --git a/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js index e9d1b8087969a..a5b65f87335eb 100644 --- a/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js @@ -532,12 +532,12 @@ describe(`Test plugin manifest options`, () => { describe(`pluginOptionsSchema`, () => { it(`validates options correctly`, async () => { - expect(await testPluginOptionsSchema(pluginOptionsSchema, manifestOptions)) - .toMatchInlineSnapshot(` - Object { - "errors": Array [], - "isValid": true, - } - `) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + manifestOptions + ) + + expect(isValid).toBe(true) + expect(errors).toEqual([]) }) }) diff --git a/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js b/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js index 0c7bacc5ae648..132456b45feb0 100644 --- a/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-mdx/__tests__/gatsby-node.js @@ -19,52 +19,60 @@ describe(`pluginOptionsSchema`, () => { `"root" must be a string`, ] - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - extensions: [1, 2, 3], - defaultLayouts: `this should be an object`, - gatsbyRemarkPlugins: [1, { not: `existing prop` }, `valid one`], - remarkPlugins: `this should be an array of object`, - rehypePlugins: `this should be an array of object`, - plugins: [2], - mediaTypes: [1, 2], - shouldBlockNodeFromTransformation: (wrong, number) => null, - root: 1, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + extensions: [1, 2, 3], + defaultLayouts: `this should be an object`, + gatsbyRemarkPlugins: [1, { not: `existing prop` }, `valid one`], + remarkPlugins: `this should be an array of object`, + rehypePlugins: `this should be an array of object`, + plugins: [2], + mediaTypes: [1, 2], + shouldBlockNodeFromTransformation: (wrong, number) => null, + root: 1, + } + ) + expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) it(`should validate the schema`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - extensions: [`.mdx`, `.mdxx`], - defaultLayouts: { - posts: `../post-layout.js`, - default: `../default-layout.js`, - }, - gatsbyRemarkPlugins: [ - { - resolve: `gatsby-remark-images`, - options: { - maxWidth: 590, - }, + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + extensions: [`.mdx`, `.mdxx`], + defaultLayouts: { + posts: `../post-layout.js`, + default: `../default-layout.js`, }, - `gatsby-remark-other-plugin`, - ], - lessBabel: false, - remarkPlugins: [ - require(`../gatsby-node.js`), - [require(`../gatsby-node.js`), { target: false }], - ], - plugins: [{ resolve: `remark-autolink-plugin` }], - rehypePlugins: [ - require(`../gatsby-node.js`), - [require(`../gatsby-node.js`), { behavior: `wrap` }], - ], - mediaTypes: [`text/markdown`, `text/x-markdown`, `custom-media/type`], - shouldBlockNodeFromTransformation: node => Boolean(node), - root: `james-holden`, - }) + gatsbyRemarkPlugins: [ + { + resolve: `gatsby-remark-images`, + options: { + maxWidth: 590, + }, + }, + `gatsby-remark-other-plugin`, + ], + lessBabel: false, + remarkPlugins: [ + require(`../gatsby-node.js`), + [require(`../gatsby-node.js`), { target: false }], + ], + plugins: [{ resolve: `remark-autolink-plugin` }], + rehypePlugins: [ + require(`../gatsby-node.js`), + [require(`../gatsby-node.js`), { behavior: `wrap` }], + ], + mediaTypes: [`text/markdown`, `text/x-markdown`, `custom-media/type`], + shouldBlockNodeFromTransformation: node => Boolean(node), + root: `james-holden`, + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) }) diff --git a/packages/gatsby-plugin-netlify/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-netlify/src/__tests__/gatsby-node.js index 89366303defaa..3db81b9556ff6 100644 --- a/packages/gatsby-plugin-netlify/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-netlify/src/__tests__/gatsby-node.js @@ -13,33 +13,41 @@ describe(`gatsby-node.js`, () => { `"generateMatchPathRewrites" must be a boolean`, ] - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - headers: `this should be an object`, - allPageHeaders: `this should be an array`, - mergeSecurityHeaders: `this should be a boolean`, - mergeLinkHeaders: `this should be a boolean`, - mergeCachingHeaders: `this should be a boolean`, - transformHeaders: (too, many, args) => ``, - generateMatchPathRewrites: `this should be a boolean`, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + headers: `this should be an object`, + allPageHeaders: `this should be an array`, + mergeSecurityHeaders: `this should be a boolean`, + mergeLinkHeaders: `this should be a boolean`, + mergeCachingHeaders: `this should be a boolean`, + transformHeaders: (too, many, args) => ``, + generateMatchPathRewrites: `this should be a boolean`, + } + ) + expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) it(`should validate the schema`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - headers: { - "/some-page": [`Bearer: Some-Magic-Token`], - "/some-other-page": [`some`, `great`, `headers`], - }, - allPageHeaders: [`First header`, `Second header`], - mergeSecurityHeaders: true, - mergeLinkHeaders: false, - mergeCachingHeaders: true, - transformHeaders: () => null, - generateMatchPathRewrites: false, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + headers: { + "/some-page": [`Bearer: Some-Magic-Token`], + "/some-other-page": [`some`, `great`, `headers`], + }, + allPageHeaders: [`First header`, `Second header`], + mergeSecurityHeaders: true, + mergeLinkHeaders: false, + mergeCachingHeaders: true, + transformHeaders: () => null, + generateMatchPathRewrites: false, + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) }) diff --git a/packages/gatsby-plugin-offline/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-offline/src/__tests__/gatsby-node.js index 339ab7233f904..d7739fa6ee712 100644 --- a/packages/gatsby-plugin-offline/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-offline/src/__tests__/gatsby-node.js @@ -133,73 +133,81 @@ describe(`pluginOptionsSchema`, () => { `"workboxConfig.clientsClaim" must be a boolean`, ] - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - precachePages: [1, 2, 3], - appendScript: 1223, - debug: `This should be a boolean`, - workboxConfig: { - importWorkboxFrom: 123, - globDirectory: 456, - globPatterns: [1, 2, 3], - modifyURLPrefix: { - "/": 123, - }, - cacheId: 123, - dontCacheBustURLsMatching: `This should be a regexp`, - runtimeCaching: [ - { - urlPattern: /(\.js$|\.css$|static\/)/, - handler: `Something Invalid`, + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + precachePages: [1, 2, 3], + appendScript: 1223, + debug: `This should be a boolean`, + workboxConfig: { + importWorkboxFrom: 123, + globDirectory: 456, + globPatterns: [1, 2, 3], + modifyURLPrefix: { + "/": 123, }, - 2, - 3, - ], - skipWaiting: `This should be a boolean`, - clientsClaim: `This should be a boolean`, - }, - }) + cacheId: 123, + dontCacheBustURLsMatching: `This should be a regexp`, + runtimeCaching: [ + { + urlPattern: /(\.js$|\.css$|static\/)/, + handler: `Something Invalid`, + }, + 2, + 3, + ], + skipWaiting: `This should be a boolean`, + clientsClaim: `This should be a boolean`, + }, + } + ) + expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) it(`should validate the schema`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - precachePages: [`/about-us/`, `/projects/*`], - appendScript: `src/custom-sw-code.js`, - debug: true, - workboxConfig: { - importWorkboxFrom: `local`, - globDirectory: `rootDir`, - globPatterns: [`a`, `b`, `c`], - modifyURLPrefix: { - "/": `pathPrefix/`, - }, - cacheId: `gatsby-plugin-offline`, - dontCacheBustURLsMatching: /(\.js$|\.css$|static\/)/, - maximumFileSizeToCacheInBytes: 4800, - runtimeCaching: [ - { - urlPattern: /(\.js$|\.css$|static\/)/, - handler: `CacheFirst`, - }, - { - urlPattern: /^https?:.*\/page-data\/.*\.json/, - handler: `StaleWhileRevalidate`, - }, - { - urlPattern: /^https?:.*\.(png|jpg|jpeg|webp|svg|gif|tiff|js|woff|woff2|json|css)$/, - handler: `StaleWhileRevalidate`, - }, - { - urlPattern: /^https?:\/\/fonts\.googleapis\.com\/css/, - handler: `StaleWhileRevalidate`, + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + precachePages: [`/about-us/`, `/projects/*`], + appendScript: `src/custom-sw-code.js`, + debug: true, + workboxConfig: { + importWorkboxFrom: `local`, + globDirectory: `rootDir`, + globPatterns: [`a`, `b`, `c`], + modifyURLPrefix: { + "/": `pathPrefix/`, }, - ], - skipWaiting: true, - clientsClaim: true, - }, - }) + cacheId: `gatsby-plugin-offline`, + dontCacheBustURLsMatching: /(\.js$|\.css$|static\/)/, + maximumFileSizeToCacheInBytes: 4800, + runtimeCaching: [ + { + urlPattern: /(\.js$|\.css$|static\/)/, + handler: `CacheFirst`, + }, + { + urlPattern: /^https?:.*\/page-data\/.*\.json/, + handler: `StaleWhileRevalidate`, + }, + { + urlPattern: /^https?:.*\.(png|jpg|jpeg|webp|svg|gif|tiff|js|woff|woff2|json|css)$/, + handler: `StaleWhileRevalidate`, + }, + { + urlPattern: /^https?:\/\/fonts\.googleapis\.com\/css/, + handler: `StaleWhileRevalidate`, + }, + ], + skipWaiting: true, + clientsClaim: true, + }, + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) }) diff --git a/packages/gatsby-plugin-sass/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-sass/src/__tests__/gatsby-node.js index 373fa2b35bb02..a9799225ccad2 100644 --- a/packages/gatsby-plugin-sass/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-sass/src/__tests__/gatsby-node.js @@ -98,82 +98,94 @@ describe(`pluginOptionsSchema`, () => { `"sassOptions.sourceMapRoot" must be a string`, ] - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - implementation: `This should be a require() thing`, - postCssPlugins: `This should be an array of postCss plugins`, - cssLoaderOptions: `This should be an object of css-loader options`, - sassRuleTest: `This should be a regexp`, - sassRuleModulesTest: `This should be a regexp`, - useResolveUrlLoader: `This should be a boolean`, - sassOptions: { - file: 123, // should be a string - data: 123, // should be a string - importer: `This should be a function`, - functions: `This should be an object of { string: function }`, - includePaths: 123, // should be an array of string - indentedSyntax: `"useResolveUrlLoader" must be a boolean`, - indentType: 123, // this should be a string - indentWidth: 40, - linefeed: `This should be cr, crlf, lf or lfcr`, - omitSourceMapUrl: `This should be a boolean`, - outFile: 123, // This should be a string - outputStyle: `This should be nested, expanded, compact or compressed`, - precision: `This should be a number`, - sourceComments: `This should be a boolean`, - sourceMap: 123, // This should be a string or a boolean - sourceMapContents: `This should be a boolean`, - sourceMapEmbed: `This should be a boolean`, - sourceMapRoot: 123, // This should be a string - }, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + implementation: `This should be a require() thing`, + postCssPlugins: `This should be an array of postCss plugins`, + cssLoaderOptions: `This should be an object of css-loader options`, + sassRuleTest: `This should be a regexp`, + sassRuleModulesTest: `This should be a regexp`, + useResolveUrlLoader: `This should be a boolean`, + sassOptions: { + file: 123, // should be a string + data: 123, // should be a string + importer: `This should be a function`, + functions: `This should be an object of { string: function }`, + includePaths: 123, // should be an array of string + indentedSyntax: `"useResolveUrlLoader" must be a boolean`, + indentType: 123, // this should be a string + indentWidth: 40, + linefeed: `This should be cr, crlf, lf or lfcr`, + omitSourceMapUrl: `This should be a boolean`, + outFile: 123, // This should be a string + outputStyle: `This should be nested, expanded, compact or compressed`, + precision: `This should be a number`, + sourceComments: `This should be a boolean`, + sourceMap: 123, // This should be a string or a boolean + sourceMapContents: `This should be a boolean`, + sourceMapEmbed: `This should be a boolean`, + sourceMapRoot: 123, // This should be a string + }, + } + ) + expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) it(`should validate the schema`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - implementation: require(`../gatsby-node.js`), - cssLoaderOptions: { camelCase: false }, - postCssPlugins: [require(`autoprefixer`)], - sassRuleTest: /\.global\.s(a|c)ss$/, - sassRuleModulesTest: /\.mod\.s(a|c)ss$/, - useResolveUrlLoader: false, - sassOptions: { - file: `../path-to-file`, - data: `{ some: data }`, - importer: function () { - return { file: `path-to-file`, contents: `data` } - }, - functions: { - "headings($from: 0, $to: 6)": function () { - return [] + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + implementation: require(`../gatsby-node.js`), + cssLoaderOptions: { camelCase: false }, + postCssPlugins: [require(`autoprefixer`)], + sassRuleTest: /\.global\.s(a|c)ss$/, + sassRuleModulesTest: /\.mod\.s(a|c)ss$/, + useResolveUrlLoader: false, + sassOptions: { + file: `../path-to-file`, + data: `{ some: data }`, + importer: function () { + return { file: `path-to-file`, contents: `data` } + }, + functions: { + "headings($from: 0, $to: 6)": function () { + return [] + }, }, + includePaths: [`some`, `path`], + indentedSyntax: true, + indentType: `tabs`, + indentWidth: 7, + linefeed: `crlf`, + omitSourceMapUrl: true, + outFile: `somewhere-around.css`, + outputStyle: `expanded`, + precision: 12, + sourceComments: true, + sourceMap: true, + sourceMapContents: true, + sourceMapEmbed: true, + sourceMapRoot: `some-source-map-root`, }, - includePaths: [`some`, `path`], - indentedSyntax: true, - indentType: `tabs`, - indentWidth: 7, - linefeed: `crlf`, - omitSourceMapUrl: true, - outFile: `somewhere-around.css`, - outputStyle: `expanded`, - precision: 12, - sourceComments: true, - sourceMap: true, - sourceMapContents: true, - sourceMapEmbed: true, - sourceMapRoot: `some-source-map-root`, - }, - }) + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) it(`should allow unknown options`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - webpackImporter: `unknown option`, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + webpackImporter: `unknown option`, + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) }) diff --git a/packages/gatsby-plugin-sharp/src/__tests__/plugin-options.ts b/packages/gatsby-plugin-sharp/src/__tests__/plugin-options.ts index e9d74afa5fcf5..34a914a33ddff 100644 --- a/packages/gatsby-plugin-sharp/src/__tests__/plugin-options.ts +++ b/packages/gatsby-plugin-sharp/src/__tests__/plugin-options.ts @@ -34,12 +34,7 @@ describe(`pluginOptionsSchema`, () => { avifOptions: 1, }, } - const { isValid, errors } = await testPluginOptionsSchema( - pluginOptionsSchema, - options - ) - expect(isValid).toBe(false) - expect(errors).toEqual([ + const expectedErrors = [ `"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`, @@ -51,16 +46,25 @@ describe(`pluginOptionsSchema`, () => { `"defaults.jpgOptions" must be of type object`, `"defaults.pngOptions" must be of type object`, `"defaults.avifOptions" must be of type object`, - ]) + ] + + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + options + ) + + expect(isValid).toBe(false) + expect(errors).toEqual(expectedErrors) }) it(`should accept correct options`, async () => { const options = { defaults } - const { isValid } = await testPluginOptionsSchema( + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, options ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) }) diff --git a/packages/gatsby-plugin-twitter/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-twitter/src/__tests__/gatsby-node.js index 8494980faf068..28a8a417c155b 100644 --- a/packages/gatsby-plugin-twitter/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-twitter/src/__tests__/gatsby-node.js @@ -5,10 +5,14 @@ import { pluginOptionsSchema } from "../gatsby-node" it(`should provide meaningful errors when fields are invalid`, async () => { const expectedErrors = [`"optionA" is not allowed`] - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - optionA: `This options shouldn't exist`, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + optionA: `This options shouldn't exist`, + } + ) + expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) @@ -17,10 +21,11 @@ it.each` ${undefined} ${{}} `(`should validate the schema: $options`, async ({ options }) => { - const { isValid } = await testPluginOptionsSchema( + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, options ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) diff --git a/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js index 989f0c17446f9..741873f5d95cc 100644 --- a/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-typescript/src/__tests__/gatsby-node.js @@ -81,36 +81,50 @@ describe(`gatsby-plugin-typescript`, () => { `"allExtensions" must be a boolean`, ] - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - isTSX: `this should be a boolean`, - jsxPragma: 123, - allExtensions: `this should be a boolean`, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + isTSX: `this should be a boolean`, + jsxPragma: 123, + allExtensions: `this should be a boolean`, + } + ) + expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) it(`should validate the schema`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - isTSX: false, - jsxPragma: `ReactFunction`, - allExtensions: false, - allowNamespaces: false, - allowDeclareFields: false, - onlyRemoveTypeImports: false, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + isTSX: false, + jsxPragma: `ReactFunction`, + allExtensions: false, + allowNamespaces: false, + allowDeclareFields: false, + onlyRemoveTypeImports: false, + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) it(`should break when isTSX doesn't match allExtensions`, async () => { - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - isTSX: true, - jsxPragma: `ReactFunction`, - allExtensions: false, - }) + const expectedErrors = [`"allExtensions" must be [true]`] + + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + isTSX: true, + jsxPragma: `ReactFunction`, + allExtensions: false, + } + ) - expect(errors).toEqual([`"allExtensions" must be [true]`]) + expect(isValid).toBe(false) + expect(errors).toEqual(expectedErrors) }) }) }) diff --git a/packages/gatsby-plugin-utils/README.md b/packages/gatsby-plugin-utils/README.md index b49e2753eeb70..19d3774916cc5 100644 --- a/packages/gatsby-plugin-utils/README.md +++ b/packages/gatsby-plugin-utils/README.md @@ -34,6 +34,7 @@ it(`should partially validate one value of a schema`, async () => { someOtherValue: Joi.string(), toVerify: Joi.boolean(), }) + const expectedErrors = [`"toVerify" must be a boolean`] // Only the "toVerify" key of the schema will be verified in this test const { isValid, errors } = await testPluginOptionsSchema(pluginSchema, { @@ -41,6 +42,6 @@ it(`should partially validate one value of a schema`, async () => { }) expect(isValid).toBe(false) - expect(errors).toEqual([`"toVerify" must be a boolean`]) + expect(errors).toEqual(expectedErrors) }) ``` diff --git a/packages/gatsby-plugin-utils/src/__tests__/test-plugin-options-schema.ts b/packages/gatsby-plugin-utils/src/__tests__/test-plugin-options-schema.ts index 610947ea94025..77666ccd1e303 100644 --- a/packages/gatsby-plugin-utils/src/__tests__/test-plugin-options-schema.ts +++ b/packages/gatsby-plugin-utils/src/__tests__/test-plugin-options-schema.ts @@ -9,17 +9,14 @@ describe(`testPluginOptionsSchema`, () => { nb: Joi.number(), toVerify: Joi.boolean(), }) + const expectedErrors = [`"toVerify" must be a boolean`] const { isValid, errors } = await testPluginOptionsSchema(pluginSchema, { toVerify: `abcd`, }) expect(isValid).toBe(false) - expect(errors).toMatchInlineSnapshot(` - Array [ - "\\"toVerify\\" must be a boolean", - ] - `) + expect(errors).toEqual(expectedErrors) }) it(`should partially validate multiples value of a schema`, async () => { @@ -29,6 +26,10 @@ describe(`testPluginOptionsSchema`, () => { nb: Joi.number(), toVerify: Joi.boolean(), }) + const expectedErrors = [ + `"nb" must be a number`, + `"toVerify" must be a boolean`, + ] const { isValid, errors } = await testPluginOptionsSchema(pluginSchema, { toVerify: `abcd`, @@ -36,12 +37,7 @@ describe(`testPluginOptionsSchema`, () => { }) expect(isValid).toBe(false) - expect(errors).toMatchInlineSnapshot(` - Array [ - "\\"nb\\" must be a number", - "\\"toVerify\\" must be a boolean", - ] - `) + expect(errors).toEqual(expectedErrors) }) it(`should validate half of a real world plugin schema`, async () => { @@ -84,6 +80,15 @@ describe(`testPluginOptionsSchema`, () => { siteSpeedSampleRate: Joi.number(), cookieDomain: Joi.string(), }) + const expectedErrors = [ + `"trackingId" is required`, + `"head" must be a boolean`, + `"anonymize" must be a boolean`, + `"respectDNT" must be a boolean`, + `"exclude[0]" must be a string`, + `"exclude[1]" must be a string`, + `"exclude[2]" must be a string`, + ] const { isValid, errors } = await testPluginOptionsSchema(pluginSchema, { trackingId: undefined, @@ -94,17 +99,7 @@ describe(`testPluginOptionsSchema`, () => { }) expect(isValid).toBe(false) - expect(errors).toMatchInlineSnapshot(` - Array [ - "\\"trackingId\\" is required", - "\\"head\\" must be a boolean", - "\\"anonymize\\" must be a boolean", - "\\"respectDNT\\" must be a boolean", - "\\"exclude[0]\\" must be a string", - "\\"exclude[1]\\" must be a string", - "\\"exclude[2]\\" must be a string", - ] - `) + expect(errors).toEqual(expectedErrors) }) it(`should validate an entire real world plugin schema`, async () => { @@ -147,6 +142,23 @@ describe(`testPluginOptionsSchema`, () => { siteSpeedSampleRate: Joi.number(), cookieDomain: Joi.string(), }) + const expectedErrors = [ + `"trackingId" is required`, + `"head" must be a boolean`, + `"anonymize" must be a boolean`, + `"respectDNT" must be a boolean`, + `"exclude[0]" must be a string`, + `"exclude[1]" must be a string`, + `"exclude[2]" must be a string`, + `"pageTransitionDelay" must be a number`, + `"optimizeId" must be a string`, + `"experimentId" must be a string`, + `"variationId" must be a string`, + `"defer" must be a boolean`, + `"sampleRate" must be a number`, + `"siteSpeedSampleRate" must be a number`, + `"cookieDomain" must be a string`, + ] const { isValid, errors } = await testPluginOptionsSchema(pluginSchema, { trackingId: undefined, @@ -165,25 +177,7 @@ describe(`testPluginOptionsSchema`, () => { }) expect(isValid).toBe(false) - expect(errors).toMatchInlineSnapshot(` - Array [ - "\\"trackingId\\" is required", - "\\"head\\" must be a boolean", - "\\"anonymize\\" must be a boolean", - "\\"respectDNT\\" must be a boolean", - "\\"exclude[0]\\" must be a string", - "\\"exclude[1]\\" must be a string", - "\\"exclude[2]\\" must be a string", - "\\"pageTransitionDelay\\" must be a number", - "\\"optimizeId\\" must be a string", - "\\"experimentId\\" must be a string", - "\\"variationId\\" must be a string", - "\\"defer\\" must be a boolean", - "\\"sampleRate\\" must be a number", - "\\"siteSpeedSampleRate\\" must be a number", - "\\"cookieDomain\\" must be a string", - ] - `) + expect(errors).toEqual(expectedErrors) }) it(`should check the validity of a schema`, async () => { diff --git a/packages/gatsby-remark-autolink-headers/src/__tests__/gatsby-node.js b/packages/gatsby-remark-autolink-headers/src/__tests__/gatsby-node.js index 5e9f87a880cec..3041fabd335c7 100644 --- a/packages/gatsby-remark-autolink-headers/src/__tests__/gatsby-node.js +++ b/packages/gatsby-remark-autolink-headers/src/__tests__/gatsby-node.js @@ -35,6 +35,17 @@ describe(`pluginOptionsSchema`, () => { }) it(`should invalidate an invalid config`, async () => { + const expectedErrors = [ + `"offsetY" must be a number`, + `"icon" must be one of [string, boolean]`, + `"className" must be a string`, + `"maintainCase" must be a boolean`, + `"removeAccents" must be a boolean`, + `"isIconAfterHeader" must be a boolean`, + `"elements[0]" must be a string`, + `"elements[1]" must be a string`, + ] + // Only the "toVerify" key of the schema will be verified in this test const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, @@ -50,17 +61,6 @@ describe(`pluginOptionsSchema`, () => { ) expect(isValid).toBe(false) - expect(errors).toMatchInlineSnapshot(` - Array [ - "\\"offsetY\\" must be a number", - "\\"icon\\" must be one of [string, boolean]", - "\\"className\\" must be a string", - "\\"maintainCase\\" must be a boolean", - "\\"removeAccents\\" must be a boolean", - "\\"isIconAfterHeader\\" must be a boolean", - "\\"elements[0]\\" must be a string", - "\\"elements[1]\\" must be a string", - ] - `) + expect(errors).toEqual(expectedErrors) }) }) diff --git a/packages/gatsby-remark-images/src/__tests__/gatsby-node.js b/packages/gatsby-remark-images/src/__tests__/gatsby-node.js index d89b6d6c4c417..a1941b447a171 100644 --- a/packages/gatsby-remark-images/src/__tests__/gatsby-node.js +++ b/packages/gatsby-remark-images/src/__tests__/gatsby-node.js @@ -21,86 +21,118 @@ describe(`pluginOptionsSchema`, () => { `"srcSetBreakpoints" must be an array`, ] - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - maxWidth: `This should be a number`, - linkImagesToOriginal: `This should be a boolean`, - showCaptions: `This should be a boolean`, - markdownCaptions: `This should be a boolean`, - sizeByPixelDensity: `This should be a boolean`, - wrapperStyle: true, - backgroundColor: 123, - quality: `This should be a number`, - 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`, - disableBgImage: `This should be a boolean`, - srcSetBreakpoints: `This should be an array`, - }) - + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + maxWidth: `This should be a number`, + linkImagesToOriginal: `This should be a boolean`, + showCaptions: `This should be a boolean`, + markdownCaptions: `This should be a boolean`, + sizeByPixelDensity: `This should be a boolean`, + wrapperStyle: true, + backgroundColor: 123, + quality: `This should be a number`, + 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`, + disableBgImage: `This should be a boolean`, + srcSetBreakpoints: `This should be an array`, + } + ) + + expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) it(`should validate the schema`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - maxWidth: 700, - linkImagesToOriginal: false, - showCaptions: true, - markdownCaptions: true, - sizeByPixelDensity: true, - wrapperStyle: { marginTop: `1rem`, padding: `1.5rem`, color: `blue` }, - backgroundColor: `red`, - quality: 77, - withWebp: true, - tracedSVG: true, - loading: `eager`, - disableBgImageOnAlpha: true, - disableBgImage: true, - srcSetBreakpoints: [400, 600, 800], - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + maxWidth: 700, + linkImagesToOriginal: false, + showCaptions: true, + markdownCaptions: true, + sizeByPixelDensity: true, + wrapperStyle: { marginTop: `1rem`, padding: `1.5rem`, color: `blue` }, + backgroundColor: `red`, + quality: 77, + withWebp: true, + tracedSVG: true, + loading: `eager`, + disableBgImageOnAlpha: true, + disableBgImage: true, + srcSetBreakpoints: [400, 600, 800], + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) it(`should validate the withWebp prop`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - withWebp: { quality: 100 }, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + withWebp: { quality: 100 }, + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) describe(`allow to use array of valid strings for "showCaptions"`, () => { it(`["title", "alt"]`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - showCaptions: [`title`, `alt`], - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + showCaptions: [`title`, `alt`], + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) it(`["title"]`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - showCaptions: [`title`], - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + showCaptions: [`title`], + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) it(`["alt"]`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - showCaptions: [`alt`], - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + showCaptions: [`alt`], + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) it(`["not valid"] (should fail validation)`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - showCaptions: [`not valid`], - }) + const expectedErrors = [ + `"showCaptions[0]" does not match any of the allowed types`, + ] + + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + showCaptions: [`not valid`], + } + ) expect(isValid).toBe(false) + expect(errors).toEqual(expectedErrors) }) }) @@ -110,52 +142,66 @@ describe(`pluginOptionsSchema`, () => { [`true`, true], [`false`, false], ])(`%s`, async (_title, booleanValue) => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - tracedSVG: booleanValue, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + tracedSVG: booleanValue, + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) }) describe(`supports object notation`, () => { it(`should validate when all fields are set`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - tracedSVG: { - turnPolicy: Potrace.TURNPOLICY_RIGHT, - turdSize: 50, - alphaMax: 0.5, - optCurve: false, - optTolerance: 0.9, - threshold: 230, - blackOnWhite: false, - color: `red`, - background: `green`, - }, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + tracedSVG: { + turnPolicy: Potrace.TURNPOLICY_RIGHT, + turdSize: 50, + alphaMax: 0.5, + optCurve: false, + optTolerance: 0.9, + threshold: 230, + blackOnWhite: false, + color: `red`, + background: `green`, + }, + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) it(`should validate when some fields are set`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - tracedSVG: { - turnPolicy: Potrace.TURNPOLICY_RIGHT, - turdSize: 50, - // alphaMax: 0.5, - // optCurve: 0.2, - // optTolerance: 0.9, - // threshold: 230, - // blackOnWhite: false, - color: `red`, - background: `green`, - }, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + tracedSVG: { + turnPolicy: Potrace.TURNPOLICY_RIGHT, + turdSize: 50, + // alphaMax: 0.5, + // optCurve: 0.2, + // optTolerance: 0.9, + // threshold: 230, + // blackOnWhite: false, + color: `red`, + background: `green`, + }, + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) it(`should fail validation when unknown fields are set`, async () => { + const expectedErrors = [`"tracedSVG.foo" is not allowed`] + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, { @@ -166,11 +212,7 @@ describe(`pluginOptionsSchema`, () => { ) expect(isValid).toBe(false) - expect(errors).toMatchInlineSnapshot(` - Array [ - "\\"tracedSVG.foo\\" is not allowed", - ] - `) + expect(errors).toEqual(expectedErrors) }) describe(`turnPolicy variants`, () => { @@ -182,7 +224,7 @@ describe(`pluginOptionsSchema`, () => { `TURNPOLICY_MINORITY`, `TURNPOLICY_MAJORITY`, ])(`supports setting by policy name (%s)`, async name => { - const { isValid } = await testPluginOptionsSchema( + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, { tracedSVG: { turnPolicy: name }, @@ -190,6 +232,7 @@ describe(`pluginOptionsSchema`, () => { ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) it.each([ @@ -200,7 +243,7 @@ describe(`pluginOptionsSchema`, () => { Potrace.TURNPOLICY_MINORITY, Potrace.TURNPOLICY_MAJORITY, ])(`supports setting by policy value (%s)`, async value => { - const { isValid } = await testPluginOptionsSchema( + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, { tracedSVG: { turnPolicy: value }, @@ -208,9 +251,14 @@ describe(`pluginOptionsSchema`, () => { ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) it(`Doesn't support arbitrary string values`, async () => { + const expectedErrors = [ + `"tracedSVG.turnPolicy" must be one of [TURNPOLICY_BLACK, TURNPOLICY_WHITE, TURNPOLICY_LEFT, TURNPOLICY_RIGHT, TURNPOLICY_MINORITY, TURNPOLICY_MAJORITY, black, white, left, right, minority, majority]`, + ] + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, { @@ -219,11 +267,7 @@ describe(`pluginOptionsSchema`, () => { ) expect(isValid).toBe(false) - expect(errors).toMatchInlineSnapshot(` - Array [ - "\\"tracedSVG.turnPolicy\\" must be one of [TURNPOLICY_BLACK, TURNPOLICY_WHITE, TURNPOLICY_LEFT, TURNPOLICY_RIGHT, TURNPOLICY_MINORITY, TURNPOLICY_MAJORITY, black, white, left, right, minority, majority]", - ] - `) + expect(errors).toEqual(expectedErrors) }) }) @@ -261,7 +305,7 @@ describe(`pluginOptionsSchema`, () => { value = titleAndMaybeValue } - const { isValid } = await testPluginOptionsSchema( + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, { tracedSVG: { threshold: value }, @@ -269,6 +313,7 @@ describe(`pluginOptionsSchema`, () => { ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) // invalid settings diff --git a/packages/gatsby-source-wordpress/__tests__/plugin-options-schema.test.js b/packages/gatsby-source-wordpress/__tests__/plugin-options-schema.test.js index 6335466205e09..262c38256f03d 100644 --- a/packages/gatsby-source-wordpress/__tests__/plugin-options-schema.test.js +++ b/packages/gatsby-source-wordpress/__tests__/plugin-options-schema.test.js @@ -3,25 +3,24 @@ import { pluginOptionsSchema } from "gatsby-source-wordpress/dist/steps/declare- describe(`pluginOptionsSchema`, () => { it(`should validate a minimal, valid config`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { + const { isValid, errors } = await testPluginOptionsSchema(pluginOptionsSchema, { url: `http://localhost:8000/graphql`, }) expect(isValid).toEqual(true) + expect(errors).toEqual([]) }) it(`should invalidate a config missing required vars`, async () => { + const expectedErrors = [`"url" is required`,] + const { isValid, errors } = await testPluginOptionsSchema( pluginOptionsSchema, {} ) expect(isValid).toEqual(false) - expect(errors).toMatchInlineSnapshot(` - Array [ - "\\"url\\" is required", - ] - `) + expect(errors).toEqual(expectedErrors) }) it(`should validate a fully custom config`, async () => { @@ -106,7 +105,7 @@ describe(`pluginOptionsSchema`, () => { } ) - expect(errors).toEqual([]) expect(isValid).toEqual(true) + expect(errors).toEqual([]) }) }) diff --git a/packages/gatsby-transformer-remark/src/__tests__/gatsby-node.js b/packages/gatsby-transformer-remark/src/__tests__/gatsby-node.js index c6f5af36e83a2..a93ec003b4c25 100644 --- a/packages/gatsby-transformer-remark/src/__tests__/gatsby-node.js +++ b/packages/gatsby-transformer-remark/src/__tests__/gatsby-node.js @@ -11,34 +11,42 @@ describe(`gatsby-node.js`, () => { `"plugins" must be an array`, ] - const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { - commonmark: `this should be a boolean`, - footnotes: `this should be a boolean`, - pedantic: `this should be a boolean`, - gfm: `this should be a boolean`, - plugins: `this should be an array`, - }) + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + commonmark: `this should be a boolean`, + footnotes: `this should be a boolean`, + pedantic: `this should be a boolean`, + gfm: `this should be a boolean`, + plugins: `this should be an array`, + } + ) + expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) it(`should validate the schema`, async () => { - const { isValid } = await testPluginOptionsSchema(pluginOptionsSchema, { - commonmark: false, - footnotes: false, - pedantic: false, - gfm: false, - plugins: [ - `gatsby-remark-copy-linked-files`, - { - resolve: `gatsby-remark-images`, - options: { - maxWidth: 756, + const { isValid, errors } = await testPluginOptionsSchema( + pluginOptionsSchema, + { + commonmark: false, + footnotes: false, + pedantic: false, + gfm: false, + plugins: [ + `gatsby-remark-copy-linked-files`, + { + resolve: `gatsby-remark-images`, + options: { + maxWidth: 756, + }, }, - }, - ], - }) + ], + } + ) expect(isValid).toBe(true) + expect(errors).toEqual([]) }) }) From 7bc9f9c99540c1235b6003065d6ccdb099f35285 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Wed, 23 Nov 2022 14:42:10 +0100 Subject: [PATCH 2/3] revert change --- .../src/__tests__/gatsby-node.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/deprecated-packages/gatsby-plugin-glamor/src/__tests__/gatsby-node.js b/deprecated-packages/gatsby-plugin-glamor/src/__tests__/gatsby-node.js index 1ed97dc2ec22c..feb1332bb6f7d 100644 --- a/deprecated-packages/gatsby-plugin-glamor/src/__tests__/gatsby-node.js +++ b/deprecated-packages/gatsby-plugin-glamor/src/__tests__/gatsby-node.js @@ -6,14 +6,10 @@ describe(`pluginOptionsSchema`, () => { it(`should provide meaningful errors when fields are invalid`, async () => { const expectedErrors = [`"optionA" is not allowed`] - const { isValid, errors } = await testPluginOptionsSchema( - pluginOptionsSchema, - { - optionA: `This options shouldn't exist`, - } - ) + const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { + optionA: `This options shouldn't exist`, + }) - expect(isValid).toBe(false) expect(errors).toEqual(expectedErrors) }) @@ -22,12 +18,11 @@ describe(`pluginOptionsSchema`, () => { ${undefined} ${{}} `(`should validate the schema: $options`, async ({ options }) => { - const { isValid, errors } = await testPluginOptionsSchema( + const { isValid } = await testPluginOptionsSchema( pluginOptionsSchema, options ) expect(isValid).toBe(true) - expect(errors).toEqual([]) }) }) From 0be0b3abb4e2a36cacbd259378321c6a5ef24e19 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Wed, 23 Nov 2022 14:47:07 +0100 Subject: [PATCH 3/3] merge error --- .../src/__tests__/gatsby-node.js | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/packages/gatsby-plugin-offline/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-offline/src/__tests__/gatsby-node.js index b0e44333f8313..b264416d5b07e 100644 --- a/packages/gatsby-plugin-offline/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-offline/src/__tests__/gatsby-node.js @@ -205,30 +205,6 @@ describe(`pluginOptionsSchema`, () => { skipWaiting: true, clientsClaim: true, }, - cacheId: `gatsby-plugin-offline`, - dontCacheBustURLsMatching: /(\.js$|\.css$|static\/)/, - maximumFileSizeToCacheInBytes: 4800, - runtimeCaching: [ - { - urlPattern: /(\.js$|\.css$|static\/)/, - handler: `CacheFirst`, - }, - { - urlPattern: /^https?:.*\/page-data\/.*\.json/, - handler: `StaleWhileRevalidate`, - }, - { - urlPattern: - /^https?:.*\.(png|jpg|jpeg|webp|svg|gif|tiff|js|woff|woff2|json|css)$/, - handler: `StaleWhileRevalidate`, - }, - { - urlPattern: /^https?:\/\/fonts\.googleapis\.com\/css/, - handler: `StaleWhileRevalidate`, - }, - ], - skipWaiting: true, - clientsClaim: true, } )