Commit cb8ccd5c authored by Janka Uryga's avatar Janka Uryga

test: convert metadata-warnings/index.test.ts to nextTestSetup

parent 336019b8
import { createNextDescribe } from 'e2e-utils' import { nextTestSetup } from 'e2e-utils'
const METADATA_BASE_WARN_STRING = const METADATA_BASE_WARN_STRING =
'metadataBase property in metadata export is not set for resolving social open graph or twitter images,' 'metadataBase property in metadata export is not set for resolving social open graph or twitter images,'
createNextDescribe( describe('app dir - metadata missing metadataBase', () => {
'app dir - metadata missing metadataBase', const { next, isNextDev, skipped } = nextTestSetup({
{
files: __dirname, files: __dirname,
skipDeployment: true, skipDeployment: true,
}, })
({ next, isNextDev }) => {
// If it's start mode, we get the whole logs since they're from build process. if (skipped) {
// If it's development mode, we get the logs after request return
function getCliOutput(logStartPosition: number) { }
return isNextDev ? next.cliOutput.slice(logStartPosition) : next.cliOutput
} // If it's start mode, we get the whole logs since they're from build process.
// If it's development mode, we get the logs after request
if (isNextDev) { function getCliOutput(logStartPosition: number) {
it('should not warn metadataBase is missing if there is only absolute url', async () => { return isNextDev ? next.cliOutput.slice(logStartPosition) : next.cliOutput
const logStartPosition = next.cliOutput.length }
await next.fetch('/absolute-url-og')
const output = getCliOutput(logStartPosition)
expect(output).not.toInclude(METADATA_BASE_WARN_STRING)
})
}
it('should fallback to localhost if metadataBase is missing for absolute urls resolving', async () => {
const logStartPosition = next.cliOutput.length
await next.fetch('/og-image-convention')
const output = getCliOutput(logStartPosition)
expect(output).toInclude(METADATA_BASE_WARN_STRING)
expect(output).toMatch(/using "http:\/\/localhost:\d+/)
expect(output).toInclude(
'. See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase'
)
})
it('should warn for unsupported metadata properties', async () => { if (isNextDev) {
it('should not warn metadataBase is missing if there is only absolute url', async () => {
const logStartPosition = next.cliOutput.length const logStartPosition = next.cliOutput.length
await next.fetch('/unsupported-metadata') await next.fetch('/absolute-url-og')
const output = getCliOutput(logStartPosition) const output = getCliOutput(logStartPosition)
expect(output).toInclude( expect(output).not.toInclude(METADATA_BASE_WARN_STRING)
'Unsupported metadata themeColor is configured in metadata export in /unsupported-metadata. Please move it to viewport'
)
expect(output).toInclude(
'Read more: https://nextjs.org/docs/app/api-reference/functions/generate-viewport'
)
})
it('should not warn for viewport properties during manually merging metadata', async () => {
const outputLength = next.cliOutput.length
await next.fetch('/merge')
// Should not log the unsupported metadata viewport warning in the output
// during merging the metadata, if the value is still nullable.
const output = next.cliOutput.slice(outputLength)
expect(output).not.toContain('Unsupported metadata viewport')
}) })
} }
)
it('should fallback to localhost if metadataBase is missing for absolute urls resolving', async () => {
const logStartPosition = next.cliOutput.length
await next.fetch('/og-image-convention')
const output = getCliOutput(logStartPosition)
expect(output).toInclude(METADATA_BASE_WARN_STRING)
expect(output).toMatch(/using "http:\/\/localhost:\d+/)
expect(output).toInclude(
'. See https://nextjs.org/docs/app/api-reference/functions/generate-metadata#metadatabase'
)
})
it('should warn for unsupported metadata properties', async () => {
const logStartPosition = next.cliOutput.length
await next.fetch('/unsupported-metadata')
const output = getCliOutput(logStartPosition)
expect(output).toInclude(
'Unsupported metadata themeColor is configured in metadata export in /unsupported-metadata. Please move it to viewport'
)
expect(output).toInclude(
'Read more: https://nextjs.org/docs/app/api-reference/functions/generate-viewport'
)
})
it('should not warn for viewport properties during manually merging metadata', async () => {
const outputLength = next.cliOutput.length
await next.fetch('/merge')
// Should not log the unsupported metadata viewport warning in the output
// during merging the metadata, if the value is still nullable.
const output = next.cliOutput.slice(outputLength)
expect(output).not.toContain('Unsupported metadata viewport')
})
})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment