-
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.
- Loading branch information
Showing
8 changed files
with
83 additions
and
77 deletions.
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
18 changes: 0 additions & 18 deletions
18
packages/gatsby-plugin-sitemap/src/__tests__/__snapshots__/options-validation.js.snap
This file was deleted.
Oops, something went wrong.
12 changes: 6 additions & 6 deletions
12
packages/gatsby-plugin-sitemap/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
52 changes: 38 additions & 14 deletions
52
packages/gatsby-plugin-sitemap/src/__tests__/options-validation.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 |
---|---|---|
@@ -1,22 +1,46 @@ | ||
import { pluginOptionsSchema } from "../options-validation" | ||
import Joi from "joi" | ||
import { testPluginOptionsSchema, Joi } from "gatsby-plugin-utils" | ||
|
||
const schema = pluginOptionsSchema({ Joi }) | ||
describe(`pluginOptionsSchema`, () => { | ||
it(`should provide meaningful errors when fields are invalid`, async () => { | ||
const expectedErrors = [`"wrong" is not allowed`] | ||
|
||
describe(`gatsby-plugin-sitemap: options-validation tests`, () => { | ||
describe(`validateOptions`, () => { | ||
it(`creates correct defaults`, async () => { | ||
const pluginOptions = await schema.validateAsync({}) | ||
|
||
expect(pluginOptions).toMatchSnapshot() | ||
const { errors } = await testPluginOptionsSchema(pluginOptionsSchema, { | ||
wrong: `test`, | ||
}) | ||
|
||
it(`errors on invalid options`, async () => { | ||
try { | ||
await schema.validateAsync({ wrong: `test` }) | ||
} catch (error) { | ||
expect(error).toMatchSnapshot() | ||
expect(errors).toEqual(expectedErrors) | ||
}) | ||
|
||
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 } = await testPluginOptionsSchema( | ||
pluginOptionsSchema, | ||
options | ||
) | ||
|
||
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
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
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
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