forked from gatsbyjs/gatsby
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options-validation.js
64 lines (54 loc) 路 1.72 KB
/
options-validation.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
54
55
56
57
58
59
60
61
62
63
64
import { pluginOptionsSchema } from "../options-validation"
import { testPluginOptionsSchema, Joi } from "gatsby-plugin-utils"
describe(`pluginOptionsSchema`, () => {
it(`should provide meaningful errors when fields are invalid`, async () => {
const expectedErrors = [`"output" must be a string`]
const { isValid, errors } = await testPluginOptionsSchema(
pluginOptionsSchema,
{
output: 123,
}
)
expect(isValid).toBe(false)
expect(errors).toEqual(expectedErrors)
})
it(`should provide warning for deprecated "exclude" option`, async () => {
const expectedWarnings = [`"exclude" is not allowed`]
const { warnings, hasWarnings } = await testPluginOptionsSchema(
pluginOptionsSchema,
{
exclude: [`test`],
}
)
expect(hasWarnings).toBe(true)
expect(warnings).toEqual(expectedWarnings)
})
it(`creates correct defaults`, async () => {
const pluginOptions = await pluginOptionsSchema({ Joi }).validateAsync({})
expect(pluginOptions).toMatchInlineSnapshot(`
Object {
"createLinkInHead": true,
"entryLimit": 45000,
"excludes": Array [],
"filterPages": [Function],
"output": "/sitemap",
"query": "{ site { siteMetadata { siteUrl } } allSitePage { nodes { path } } }",
"resolvePagePath": [Function],
"resolvePages": [Function],
"resolveSiteUrl": [Function],
"serialize": [Function],
}
`)
})
it.each`
options
${undefined}
${{}}
`(`should validate the schema: $options`, async ({ options }) => {
const { isValid, errors } = await testPluginOptionsSchema(
pluginOptionsSchema,
options
)
expect(isValid).toBe(true)
})
})