Unverified Commit ac00e864 authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub
parent 823fe7ff
...@@ -8,6 +8,23 @@ function accumulateMetadata(metadataItems: MetadataItems) { ...@@ -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('accumulateMetadata', () => {
describe('typing', () => { describe('typing', () => {
it('should support both sync and async metadata', async () => { it('should support both sync and async metadata', async () => {
...@@ -192,12 +209,14 @@ describe('accumulateMetadata', () => { ...@@ -192,12 +209,14 @@ describe('accumulateMetadata', () => {
], ],
] ]
const metadata = await accumulateMetadata(metadataItems) const metadata = await accumulateMetadata(metadataItems)
expect(metadata).toMatchObject({ expect(mapUrlsToStrings(metadata)).toMatchObject(
metadataBase: new URL('http://test.com/base'), mapUrlsToStrings({
itunes: { metadataBase: new URL('http://test.com/base'),
appArgument: new URL('http://test.com/base/test/native/app'), itunes: {
}, appArgument: new URL('http://test.com/base/test/native/app'),
}) },
})
)
}) })
}) })
...@@ -217,11 +236,13 @@ describe('accumulateMetadata', () => { ...@@ -217,11 +236,13 @@ describe('accumulateMetadata', () => {
{ {
openGraph: { openGraph: {
type: 'music.song', 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', () => { ...@@ -256,7 +277,9 @@ describe('accumulateMetadata', () => {
const metadata = await accumulateMetadata( const metadata = await accumulateMetadata(
configuredMetadata.map((m) => [m, null]) configuredMetadata.map((m) => [m, null])
) )
expect(metadata).toMatchObject(result) expect(mapUrlsToStrings(metadata)).toMatchObject(
mapUrlsToStrings(result)
)
}) })
}) })
...@@ -349,12 +372,14 @@ describe('accumulateMetadata', () => { ...@@ -349,12 +372,14 @@ describe('accumulateMetadata', () => {
], ],
] ]
const metadata = await accumulateMetadata(metadataItems) const metadata = await accumulateMetadata(metadataItems)
expect(metadata).toMatchObject({ expect(mapUrlsToStrings(metadata)).toMatchObject(
metadataBase: new URL('http://test.com/base'), mapUrlsToStrings({
openGraph: { metadataBase: new URL('http://test.com/base'),
url: new URL('http://test.com/base/test/abc'), 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 () => { 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