Unverified Commit ac00e864 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub
parent 823fe7ff
......@@ -8,6 +8,23 @@ function accumulateMetadata(metadataItems: MetadataItems) {
})
}
function mapUrlsToStrings(obj: any) {
if (typeof obj === 'object') {
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
if (obj[key] instanceof URL) {
// If the property is a URL instance, convert it to a string
obj[key] = obj[key].href
} else if (typeof obj[key] === 'object') {
// Recursively process nested objects
obj[key] = mapUrlsToStrings(obj[key])
}
}
}
}
return obj
}
describe('accumulateMetadata', () => {
describe('typing', () => {
it('should support both sync and async metadata', async () => {
......@@ -192,12 +209,14 @@ describe('accumulateMetadata', () => {
],
]
const metadata = await accumulateMetadata(metadataItems)
expect(metadata).toMatchObject({
metadataBase: new URL('http://test.com/base'),
itunes: {
appArgument: new URL('http://test.com/base/test/native/app'),
},
})
expect(mapUrlsToStrings(metadata)).toMatchObject(
mapUrlsToStrings({
metadataBase: new URL('http://test.com/base'),
itunes: {
appArgument: new URL('http://test.com/base/test/native/app'),
},
})
)
})
})
......@@ -217,11 +236,13 @@ describe('accumulateMetadata', () => {
{
openGraph: {
type: 'music.song',
images: new URL('https://test3.com'),
images: new URL('https://test-og-3.com'),
},
},
],
{ openGraph: { images: [new URL('https://test3.com')] } },
{
openGraph: { images: [{ url: new URL('https://test-og-3.com') }] },
},
],
[
[
......@@ -256,7 +277,9 @@ describe('accumulateMetadata', () => {
const metadata = await accumulateMetadata(
configuredMetadata.map((m) => [m, null])
)
expect(metadata).toMatchObject(result)
expect(mapUrlsToStrings(metadata)).toMatchObject(
mapUrlsToStrings(result)
)
})
})
......@@ -349,12 +372,14 @@ describe('accumulateMetadata', () => {
],
]
const metadata = await accumulateMetadata(metadataItems)
expect(metadata).toMatchObject({
metadataBase: new URL('http://test.com/base'),
openGraph: {
url: new URL('http://test.com/base/test/abc'),
},
})
expect(mapUrlsToStrings(metadata)).toMatchObject(
mapUrlsToStrings({
metadataBase: new URL('http://test.com/base'),
openGraph: {
url: new URL('http://test.com/base/test/abc'),
},
})
)
})
it('should override openGraph or twitter images when current layer specifies social images properties', async () => {
......
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