From 5fa575a1a01278921a8029e04581890c2d19904b Mon Sep 17 00:00:00 2001 From: yoshinorin Date: Tue, 16 Jan 2024 23:17:39 +0900 Subject: [PATCH] test(sitemap): add test for `sitemap.xml` string generator --- __tests__/unit/services/sitemap.test.ts | 40 +++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 __tests__/unit/services/sitemap.test.ts diff --git a/__tests__/unit/services/sitemap.test.ts b/__tests__/unit/services/sitemap.test.ts new file mode 100644 index 0000000..79b3b3d --- /dev/null +++ b/__tests__/unit/services/sitemap.test.ts @@ -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 = [ + { + 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( + ` + + https://example.com/articles/abc + 2020-01-01 + + + https://example.com/articles/def + 2022-02-02 + + + https://example.com/diary/ + 2023-03-03 + + + `.replace(/\s/g,"") + ); +});