Skip to content

Commit

Permalink
fix review & add test
Browse files Browse the repository at this point in the history
  • Loading branch information
wardpeet committed Apr 5, 2019
1 parent f3b9235 commit 9f79efa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
4 changes: 0 additions & 4 deletions packages/gatsby-plugin-sitemap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ plugins: [`gatsby-plugin-sitemap`]
Above is the minimal configuration required to have it work. By default, the
generated sitemap will include all of your site's pages, except the ones you exclude.

## Note

`siteUrl` is required with `gatsby-plugin-sitemap`.

## Options

The `defaultOptions` [here](https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby-plugin-sitemap/src/internals.js#L34) can be overridden.
Expand Down
14 changes: 14 additions & 0 deletions packages/gatsby-plugin-sitemap/src/__tests__/internals.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ describe(`results using default settings`, () => {

verifyUrlsExistInResults(urls, [`http://dummy.url${pathPrefix}/page-1`])
})

it(`should fail when siteUrl is not set`, async () => {
const graphql = () =>
Promise.resolve(generateQueryResultsMock({ siteUrl: null }))
expect.assertions(1)

try {
await runQuery(graphql, ``, [], pathPrefix)
} catch (err) {
expect(err.message).toEqual(
expect.stringContaining(`SiteMetaData 'siteUrl' property is required`)
)
}
})
}

describe(`no path-prefix`, () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sitemap/src/internals.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const runQuery = (handler, query, excludes, pathPrefix) =>

if (!r.data.site.siteMetadata.siteUrl) {
throw new Error(
`SiteMetaData 'siteUrl' property is required. (https://www.gatsbyjs.org/packages/gatsby-plugin-sitemap/#how-to-use)`
`SiteMetaData 'siteUrl' property is required. Check out the documentation to see a working example: https://www.gatsbyjs.org/packages/gatsby-plugin-sitemap/#how-to-use`
)
}

Expand Down

0 comments on commit 9f79efa

Please sign in to comment.