Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mxstbr committed Nov 13, 2020
1 parent 65697f9 commit dde4eac
Show file tree
Hide file tree
Showing 9 changed files with 301 additions and 247 deletions.
9 changes: 6 additions & 3 deletions packages/gatsby-plugin-cxs/src/__tests__/gatsby-node.js
Expand Up @@ -5,9 +5,12 @@ import { pluginOptionsSchema } from "../gatsby-node"
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 { isValid, errors } = await testPluginOptionsSchema(
pluginOptionsSchema,
{
optionA: `This options shouldn't exist`,
}
)

expect(isValid).toBe(false)
expect(errors).toEqual(expectedErrors)
Expand Down
5 changes: 4 additions & 1 deletion packages/gatsby-plugin-manifest/src/__tests__/gatsby-node.js
Expand Up @@ -532,7 +532,10 @@ describe(`Test plugin manifest options`, () => {

describe(`pluginOptionsSchema`, () => {
it(`validates options correctly`, async () => {
const { isValid, errors } = await testPluginOptionsSchema(pluginOptionsSchema, manifestOptions)
const { isValid, errors } = await testPluginOptionsSchema(
pluginOptionsSchema,
manifestOptions
)

expect(isValid).toBe(true)
expect(errors).toEqual([])
Expand Down
78 changes: 42 additions & 36 deletions packages/gatsby-plugin-mdx/__tests__/gatsby-node.js
Expand Up @@ -18,49 +18,55 @@ describe(`pluginOptionsSchema`, () => {
`"shouldBlockNodeFromTransformation" must have an arity lesser or equal to 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,
})
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,
}
)

expect(isValid).toBe(false)
expect(errors).toEqual(expectedErrors)
})

it(`should validate the schema`, async () => {
const { isValid, errors } = 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`,
],
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),
})
gatsbyRemarkPlugins: [
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 590,
},
},
`gatsby-remark-other-plugin`,
],
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),
}
)

expect(isValid).toBe(true)
expect(errors).toEqual([])
Expand Down
48 changes: 27 additions & 21 deletions packages/gatsby-plugin-netlify/src/__tests__/gatsby-node.js
Expand Up @@ -13,33 +13,39 @@ describe(`gatsby-node.js`, () => {
`"generateMatchPathRewrites" must 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`,
})
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, 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,
})
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([])
Expand Down
122 changes: 64 additions & 58 deletions packages/gatsby-plugin-offline/src/__tests__/gatsby-node.js
Expand Up @@ -133,72 +133,78 @@ describe(`pluginOptionsSchema`, () => {
`"workboxConfig.clientsClaim" must be a boolean`,
]

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,
},
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, 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/`,
},
cacheId: `gatsby-plugin-offline`,
dontCacheBustURLsMatching: /(\.js$|\.css$|static\/)/,
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\/)/,
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([])
Expand Down

0 comments on commit dde4eac

Please sign in to comment.