-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
gatsby-node.js
53 lines (48 loc) · 1.77 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { testPluginOptionsSchema } from "gatsby-plugin-utils"
import { pluginOptionsSchema } from "../gatsby-node"
describe(`gatsby-node.js`, () => {
it(`should provide meaningful errors when fields are invalid`, async () => {
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 { 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,
}
)
expect(isValid).toBe(true)
expect(errors).toEqual([])
})
})