test: check upstream content-type

This commit is contained in:
Acid Chicken (硫酸鶏) 2024-05-28 16:50:10 +09:00
parent 79d0dafaa2
commit eaeb855fa9
No known key found for this signature in database
GPG Key ID: 3E87B98A3F6BAB99
4 changed files with 33 additions and 4 deletions

View File

@ -50,6 +50,7 @@ if (import.meta.vitest) {
[
"the simple UTF-8 encoded website",
"https://example.com/",
"text/html; charset=UTF-8",
{
title: "Example Domain",
thumbnail: null,
@ -70,6 +71,7 @@ if (import.meta.vitest) {
[
"the simple Shift_JIS encoded website",
"http://abehiroshi.la.coocan.jp/",
"text/html",
{
title: "阿部寛のホームページ",
thumbnail: null,
@ -90,6 +92,7 @@ if (import.meta.vitest) {
[
"the simple EUC-JP encoded website",
"https://www.postgresql.jp/document/pg632doc/tutorial/f01.htm",
"text/html; charset=EUC-JP",
{
title: "概要",
thumbnail: null,
@ -110,6 +113,7 @@ if (import.meta.vitest) {
[
"the Shift_JIS encoded website with thumbnail",
"https://store.shochiku.co.jp/shop/g/g23080501/",
"text/html; charset=shift_jis",
{
title: "アイドルマスター ミリオンライブ! 第1幕 パンフレット",
thumbnail: "https://store.shochiku.co.jp/img/goods/S/23080501s.jpg",
@ -127,9 +131,31 @@ if (import.meta.vitest) {
url: "https://store.shochiku.co.jp/shop/g/g23080501/",
},
],
[
"the EUC-JP encoded website with thumbnail",
"https://news.livedoor.com/article/detail/24612811/",
"text/html; charset=euc-jp",
{
description: "コミッションサービス「Skeb」を提供するSkebは7月14日、Twitterに投稿する形で、分散型SNS「Misskey」のスポンサーになったと発表した。Skebが分散型SNS「Misskey」のスポンサーにMisskeyとは、分散型プロトコル",
icon: "https://parts.news.livedoor.com/img/favicon.ico?20230601",
large: true,
player: {
allow: [],
height: null,
url: null,
width: null,
},
sensitive: false,
sitename: "ライブドアニュース",
thumbnail: "https://image.news.livedoor.com/newsimage/stf/5/4/54209_1223_0ecb92105835b40f6ff567ce15c8e39e.jpg",
title: "Skebが分散型SNS「Misskey」のスポンサーに",
url: "https://news.livedoor.com/article/detail/24612811/",
},
],
[
"the UTF-8 encoded website with oEmbed",
"https://open.spotify.com/intl-ja/track/5Odr16TvEN4my22K9nbH7l",
"text/html; charset=utf-8",
{
description: "May'n · Song · 2012",
icon: "https://open.spotifycdn.com/cdn/images/favicon.0f31d2ea.ico",
@ -147,9 +173,12 @@ if (import.meta.vitest) {
url: "https://open.spotify.com/track/5Odr16TvEN4my22K9nbH7l",
},
],
])("should return summary of %s <%s>", async (_, url, expected) => {
])("should return summary of %s <%s>", async (_, url, contentType, expected) => {
const request = new Request(`https://fakehost/url?${new URLSearchParams({ url })}`)
const ctx = createExecutionContext()
const preconnect = await fetch(url, fetchOptions)
expect(preconnect.status).toBe(200)
expect(preconnect.headers.get("content-type")).toBe(contentType)
const response = await app.fetch(request, env, ctx)
await waitOnExecutionContext(ctx)
expect(response.status).toBe(200)

View File

@ -14,7 +14,7 @@ export default function general(url: URL, html: HTMLRewriter) {
const image = getImage(url, html)
const player = Promise.all([card, getPlayer(url, html)]).then<Player>(([card, parsedPlayer]) => {
return {
url: card !== "summary_large_image" && parsedPlayer.urlGeneral || parsedPlayer.urlCommon,
url: (card !== "summary_large_image" && parsedPlayer.urlGeneral) || parsedPlayer.urlCommon,
width: parsedPlayer.width,
height: parsedPlayer.height,
allow: parsedPlayer.allow,

View File

@ -103,7 +103,7 @@ export default function getPlayerOEmbed(url: URL, html: HTMLRewriter) {
headers: {
"Content-Type": "text/html; charset=UTF-8",
},
})
}),
)
.body?.getReader()
while (reader != null && !(await reader.read()).done);

View File

@ -1,4 +1,4 @@
name = "summerflare"
main = "src/index.ts"
compatibility_date = "2024-05-13"
compatibility_date = "2024-04-04"
compatibility_flags = ["nodejs_compat"]