|
| 1 | +import type { NextAdapter } from 'next' |
| 2 | +import { nextTestSetup } from 'e2e-utils' |
| 3 | + |
| 4 | +describe('adapter-dynamic-metadata', () => { |
| 5 | + const { next, isNextDev, isNextDeploy } = nextTestSetup({ |
| 6 | + files: __dirname, |
| 7 | + }) |
| 8 | + |
| 9 | + if (isNextDev) { |
| 10 | + it('should skip next dev', () => {}) |
| 11 | + return |
| 12 | + } |
| 13 | + |
| 14 | + if (!isNextDeploy) { |
| 15 | + it('should classify dynamic metadata routes as app routes in adapter outputs', async () => { |
| 16 | + const { outputs }: Parameters<NextAdapter['onBuildComplete']>[0] = |
| 17 | + await next.readJSON('build-complete.json') |
| 18 | + |
| 19 | + const expectedDynamicMetadataRoutes = [ |
| 20 | + '/robots.txt', |
| 21 | + '/sitemap.xml', |
| 22 | + '/favicon.ico', |
| 23 | + ] |
| 24 | + const staticFilePathnames = outputs.staticFiles.map( |
| 25 | + (item) => item.pathname |
| 26 | + ) |
| 27 | + const prerenderPathnames = outputs.prerenders.map((item) => item.pathname) |
| 28 | + const appRoutePathnames = outputs.appRoutes.map((item) => item.pathname) |
| 29 | + |
| 30 | + expect(staticFilePathnames).toEqual( |
| 31 | + expect.not.arrayContaining(expectedDynamicMetadataRoutes) |
| 32 | + ) |
| 33 | + expect(prerenderPathnames).toEqual( |
| 34 | + expect.not.arrayContaining(expectedDynamicMetadataRoutes) |
| 35 | + ) |
| 36 | + expect(appRoutePathnames).toEqual( |
| 37 | + expect.arrayContaining(expectedDynamicMetadataRoutes) |
| 38 | + ) |
| 39 | + |
| 40 | + for (const pathname of expectedDynamicMetadataRoutes) { |
| 41 | + const appRoute = outputs.appRoutes.find( |
| 42 | + (item) => item.pathname === pathname |
| 43 | + ) |
| 44 | + expect(appRoute?.runtime).toBe('nodejs') |
| 45 | + } |
| 46 | + }) |
| 47 | + } |
| 48 | + |
| 49 | + it('should serve dynamic metadata routes', async () => { |
| 50 | + const robots = await next.fetch('/robots.txt') |
| 51 | + expect(robots.status).toBe(200) |
| 52 | + expect(robots.headers.get('content-type')).toContain('text/plain') |
| 53 | + expect(await robots.text()).toContain('User-Agent: *') |
| 54 | + |
| 55 | + const sitemap = await next.fetch('/sitemap.xml') |
| 56 | + expect(sitemap.status).toBe(200) |
| 57 | + expect(sitemap.headers.get('content-type')).toBe('application/xml') |
| 58 | + expect(await sitemap.text()).toContain('<urlset') |
| 59 | + |
| 60 | + const favicon = await next.fetch('/favicon.ico') |
| 61 | + expect(favicon.status).toBe(200) |
| 62 | + expect(favicon.headers.get('content-type')).toContain('image/x-icon') |
| 63 | + expect(await favicon.text()).toContain('dynamic favicon') |
| 64 | + }) |
| 65 | +}) |
0 commit comments