-
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.
feat(gatsby-plugin-sitemap): sanitize siteUrl (#12613)
## Description For sitemap plugin Add code to remove trailing slash of siteUrl. ## Related Issues Fix #12590
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
const { | ||
runQuery, | ||
defaultOptions: { serialize }, | ||
} = require(`../internals`) | ||
|
||
describe(`results using default settings`, () => { | ||
const generateQueryResultsMock = ( | ||
{ siteUrl } = { siteUrl: `http://dummy.url` } | ||
) => { | ||
return { | ||
data: { | ||
site: { | ||
siteMetadata: { | ||
siteUrl: siteUrl, | ||
}, | ||
}, | ||
allSitePage: { | ||
edges: [ | ||
{ | ||
node: { | ||
path: `/page-1`, | ||
}, | ||
}, | ||
{ | ||
node: { | ||
path: `/page-2`, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
const verifyUrlsExistInResults = (results, urls) => { | ||
expect(results.map(result => result.url)).toEqual(urls) | ||
} | ||
|
||
const runTests = (pathPrefix = ``) => { | ||
it(`prepares all urls correctly`, async () => { | ||
const graphql = () => Promise.resolve(generateQueryResultsMock()) | ||
const queryRecords = await runQuery(graphql, ``, [], pathPrefix) | ||
const urls = serialize(queryRecords) | ||
|
||
verifyUrlsExistInResults(urls, [ | ||
`http://dummy.url${pathPrefix}/page-1`, | ||
`http://dummy.url${pathPrefix}/page-2`, | ||
]) | ||
}) | ||
|
||
it(`sanitize siteUrl`, async () => { | ||
const graphql = () => | ||
Promise.resolve( | ||
generateQueryResultsMock({ siteUrl: `http://dummy.url/` }) | ||
) | ||
const queryRecords = await runQuery(graphql, ``, [], pathPrefix) | ||
const urls = serialize(queryRecords) | ||
|
||
verifyUrlsExistInResults(urls, [ | ||
`http://dummy.url${pathPrefix}/page-1`, | ||
`http://dummy.url${pathPrefix}/page-2`, | ||
]) | ||
}) | ||
|
||
it(`excludes pages`, async () => { | ||
const graphql = () => Promise.resolve(generateQueryResultsMock()) | ||
const queryRecords = await runQuery(graphql, ``, [`/page-2`], pathPrefix) | ||
const urls = serialize(queryRecords) | ||
|
||
verifyUrlsExistInResults(urls, [`http://dummy.url${pathPrefix}/page-1`]) | ||
}) | ||
} | ||
|
||
describe(`no path-prefix`, () => { | ||
runTests() | ||
}) | ||
|
||
describe(`with path-prefix`, () => { | ||
runTests(`/path-prefix`) | ||
}) | ||
}) |
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