|
| 1 | +import { nextTestSetup } from 'e2e-utils' |
| 2 | + |
| 3 | +const METADATA_BASE_WARN_STRING = |
| 4 | + 'metadataBase property in metadata export is not set for resolving social open graph or twitter images,' |
| 5 | + |
| 6 | +describe('app dir - metadata missing metadataBase', () => { |
| 7 | + const { next, isNextDev, skipped } = nextTestSetup({ |
| 8 | + files: __dirname, |
| 9 | + skipDeployment: true, |
| 10 | + overrideFiles: { |
| 11 | + 'app/layout.js': ` |
| 12 | + export default function Layout({ children }) { |
| 13 | + return ( |
| 14 | + <div> |
| 15 | + {children} |
| 16 | + </div> |
| 17 | + ) |
| 18 | + } |
| 19 | + |
| 20 | + export const metadata = { |
| 21 | + metadataBase: new URL('https://example.com'), |
| 22 | + } |
| 23 | + `, |
| 24 | + }, |
| 25 | + }) |
| 26 | + |
| 27 | + if (skipped) { |
| 28 | + return |
| 29 | + } |
| 30 | + |
| 31 | + // If it's start mode, we get the whole logs since they're from build process. |
| 32 | + // If it's development mode, we get the logs after request |
| 33 | + function getCliOutput(logStartPosition: number) { |
| 34 | + return isNextDev ? next.cliOutput.slice(logStartPosition) : next.cliOutput |
| 35 | + } |
| 36 | + |
| 37 | + it('should not show warning in vercel deployment output in default build output mode', async () => { |
| 38 | + const logStartPosition = next.cliOutput.length |
| 39 | + await next.fetch('/og-image-convention') |
| 40 | + const output = getCliOutput(logStartPosition) |
| 41 | + |
| 42 | + expect(output).not.toInclude(METADATA_BASE_WARN_STRING) |
| 43 | + }) |
| 44 | + |
| 45 | + it('should not warn metadataBase is missing and a relative URL is used', async () => { |
| 46 | + const logStartPosition = next.cliOutput.length |
| 47 | + await next.fetch('/relative-url-og') |
| 48 | + const output = getCliOutput(logStartPosition) |
| 49 | + |
| 50 | + expect(output).not.toInclude(METADATA_BASE_WARN_STRING) |
| 51 | + }) |
| 52 | + |
| 53 | + it('should warn for unsupported metadata properties', async () => { |
| 54 | + const logStartPosition = next.cliOutput.length |
| 55 | + await next.fetch('/unsupported-metadata') |
| 56 | + const output = getCliOutput(logStartPosition) |
| 57 | + expect(output).toInclude( |
| 58 | + 'Unsupported metadata themeColor is configured in metadata export in /unsupported-metadata. Please move it to viewport' |
| 59 | + ) |
| 60 | + expect(output).toInclude( |
| 61 | + 'Read more: https://nextjs.org/docs/app/api-reference/functions/generate-viewport' |
| 62 | + ) |
| 63 | + }) |
| 64 | + |
| 65 | + it('should not warn for viewport properties during manually merging metadata', async () => { |
| 66 | + const outputLength = next.cliOutput.length |
| 67 | + await next.fetch('/merge') |
| 68 | + // Should not log the unsupported metadata viewport warning in the output |
| 69 | + // during merging the metadata, if the value is still nullable. |
| 70 | + const output = next.cliOutput.slice(outputLength) |
| 71 | + expect(output).not.toContain('Unsupported metadata viewport') |
| 72 | + }) |
| 73 | +}) |
0 commit comments