docusaurus/v2/test/core/sitemap.test.js
Endilie Yacop Sucipto fd780f19a2
feat(v2): generate sitemap (#1065)
* feat(v2): generate sitemap

* cannot snapshot sitemap because xml generated in different order
2018-10-25 21:47:13 +08:00

44 lines
2.5 KiB
JavaScript

import '@babel/polyfill';
import createSitemap from '@lib/core/sitemap';
import loadSetup from '../loadSetup';
describe('sitemap', () => {
test('simple site', async () => {
const props = await loadSetup('simple');
const sitemap = await createSitemap(props);
expect(sitemap).toContain(
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`,
);
});
test('translated site', async () => {
const props = await loadSetup('translated');
const sitemap = await createSitemap(props);
expect(sitemap).toContain(
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`,
);
});
test('versioned site', async () => {
const props = await loadSetup('versioned');
const sitemap = await createSitemap(props);
expect(sitemap).toContain(
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`,
);
});
test('translated + versioned site', async () => {
const props = await loadSetup('transversioned');
const sitemap = await createSitemap(props);
expect(sitemap).toContain(
`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">`,
);
});
test('empty site', async () => {
const props = await loadSetup('empty');
expect(createSitemap(props)).rejects.toThrowErrorMatchingInlineSnapshot(
`"Url in siteConfig.js cannot be empty/undefined"`,
);
});
});