Skip to content

Commit

Permalink
add assertions for sitemap
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed May 9, 2024
1 parent 6086d55 commit 11378c3
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions test/e2e/app-dir/dynamic-in-generate-params/index.test.ts
Original file line number Diff line number Diff line change
@@ -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>([^<]+)<\/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 () => {
Expand All @@ -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)
})
})

0 comments on commit 11378c3

Please sign in to comment.