-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(gatsby-plugin-netlify): add pluginOptionsSchema export (#27420)
- Loading branch information
Marvin Frachet
authored
Oct 13, 2020
1 parent
a8a5d48
commit 5243025
Showing
3 changed files
with
83 additions
and
1 deletion.
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
45 changes: 45 additions & 0 deletions
45
packages/gatsby-plugin-netlify/src/__tests__/gatsby-node.js
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,45 @@ | ||
import { testPluginOptionsSchema } from "gatsby-plugin-utils" | ||
import { pluginOptionsSchema } from "../gatsby-node" | ||
|
||
describe(`gatsby-node.js`, () => { | ||
it(`should provide meaningful errors when fields are invalid`, () => { | ||
const expectedErrors = [ | ||
`"headers" must be of type object`, | ||
`"allPageHeaders" must be an array`, | ||
`"mergeSecurityHeaders" must be a boolean`, | ||
`"mergeLinkHeaders" must be a boolean`, | ||
`"mergeCachingHeaders" must be a boolean`, | ||
`"transformHeaders" must have an arity lesser or equal to 2`, | ||
`"generateMatchPathRewrites" must be a boolean`, | ||
] | ||
|
||
const { errors } = 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(errors).toEqual(expectedErrors) | ||
}) | ||
|
||
it(`should validate the schema`, () => { | ||
const { isValid } = 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) | ||
}) | ||
}) |
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