From 11378c3d6fca5a01a2b41446aab27a648e6b9edf Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 9 May 2024 09:50:47 +0200 Subject: [PATCH] add assertions for sitemap --- .../dynamic-in-generate-params/index.test.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/test/e2e/app-dir/dynamic-in-generate-params/index.test.ts b/test/e2e/app-dir/dynamic-in-generate-params/index.test.ts index fbe5238839555..751315c3309de 100644 --- a/test/e2e/app-dir/dynamic-in-generate-params/index.test.ts +++ b/test/e2e/app-dir/dynamic-in-generate-params/index.test.ts @@ -1,13 +1,20 @@ import { type NextInstance, nextTestSetup } from 'e2e-utils' +import type { Response } from 'node-fetch' async function getLastModifiedTime(next: NextInstance, pathname: string) { const content = await (await next.fetch(pathname)).text() return content.match(/([^<]+)<\/lastmod>/)[1] } +function assertSitemapResponse(res: Response) { + expect(res.status).toBe(200) + expect(res.headers.get('content-type')).toContain('application/xml') +} + describe('app-dir - dynamic in generate params', () => { const { next } = nextTestSetup({ files: __dirname, + skipDeployment: true, }) it('should render sitemap with generateSitemaps in force-dynamic config dynamically', async () => { @@ -18,12 +25,16 @@ describe('app-dir - dynamic in generate params', () => { }) it('should be able to call while generating multiple dynamic sitemaps', async () => { - expect((await next.fetch('sitemap/0')).status).toBe(200) - expect((await next.fetch('sitemap/1')).status).toBe(200) + const res0 = await next.fetch('sitemap/0') + const res1 = await next.fetch('sitemap/1') + assertSitemapResponse(res0) + assertSitemapResponse(res1) }) it('should be able to call fetch while generating multiple dynamic pages', async () => { - expect((await next.fetch('/dynamic/0')).status).toBe(200) - expect((await next.fetch('/dynamic/1')).status).toBe(200) + const res0 = await next.fetch('dynamic/0') + const res1 = await next.fetch('dynamic/1') + assertSitemapResponse(res0) + assertSitemapResponse(res1) }) })