rsnext/test/e2e/app-dir/metadata-missing-metadata-base/index.test.ts
Jiachi Liu 3f75387bf1
Fallback to localhost for metadataBase when it's used and missing (#47910)
[slack
thread](https://vercel.slack.com/archives/C04G5LHAVAR/p1680106437791819?thread_ts=1680013412.588999&cid=C04G5LHAVAR)

When `metadataBase` is missing and used for resolving og/tw image urls,
we'll fallback to localhost for it to always safely resolve the url
instead of erroring. Instead, we give a warning in console for which url
is resolved but with fallback `metadataBase`.

Once they found the warning and it's not expected, they need to update
the `metadataBase` to a proper URL for giving the right domain.

Another minor change is always resolve canonical with current pathname
if it's a URL instance.
Remove `resolveStringUrl` as it's not required anymore, the default
`pathname` for `resolveUrl` is '', so no trailing slash needs to be
removed
2023-04-05 15:39:29 +00:00

31 lines
996 B
TypeScript

import { createNext, FileRef } from 'e2e-utils'
import { NextInstance } from 'test/lib/next-modes/base'
import { fetchViaHTTP } from 'next-test-utils'
describe('app dir - metadata missing metadataBase', () => {
let next: NextInstance
if ((global as any).isNextDeploy) {
return it('should skip for deploy', () => {})
}
beforeAll(async () => {
next = await createNext({
skipStart: true,
files: new FileRef(__dirname),
})
})
afterAll(() => next.destroy())
it('should fallback to localhost if metadataBase is missing for absolute urls resolving', async () => {
await next.start()
await fetchViaHTTP(next.url, '/blog')
expect(next.cliOutput).toInclude(
'metadata.metadataBase is not set for resolving url "/blog/opengraph-image?'
)
expect(next.cliOutput).toInclude(', fallbacks to "http://localhost:')
expect(next.cliOutput).toInclude(
'. See https://beta.nextjs.org/docs/api-reference/metadata#metadatabase'
)
})
})