Skip to content

Commit

Permalink
test(sitemap): add test for sitemap.xml string generator
Browse files Browse the repository at this point in the history
  • Loading branch information
yoshinorin committed Jan 16, 2024
1 parent 0710872 commit 5fa575a
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions __tests__/unit/services/sitemap.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { expect, test } from 'vitest'
import { generateSitemapString } from '../../../src/services/sitemap';
import { Sitemap } from '../../../src/models/sitemap';

test('generate sitemap.xml', async () => {

const data: Array<Sitemap> = [
{
loc: '/articles/abc',
lastMod: '2020-01-01'
},
{
loc: '/articles/def',
lastMod: '2022-02-02'
},
{
loc: '/diary/',
lastMod: '2023-03-03'
}
]

const result = await generateSitemapString('https://example.com', data);
expect(result.replace(/\s/g,"")).toEqual(
`<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://example.com/articles/abc</loc>
<lastmod>2020-01-01</lastmod>
</url>
<url>
<loc>https://example.com/articles/def</loc>
<lastmod>2022-02-02</lastmod>
</url>
<url>
<loc>https://example.com/diary/</loc>
<lastmod>2023-03-03</lastmod>
</url>
</urlset>
`.replace(/\s/g,"")
);
});

0 comments on commit 5fa575a

Please sign in to comment.