rsshub 1.0.0-master.f71451d → 1.0.0-master.f75997f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config.ts +14 -0
- package/lib/errors/index.test.ts +2 -2
- package/lib/middleware/template.tsx +12 -3
- package/lib/routes/0x80/index.ts +87 -0
- package/lib/routes/0x80/namespace.ts +7 -0
- package/lib/routes/aljazeera/index.ts +17 -14
- package/lib/routes/apple/podcast.ts +64 -0
- package/lib/routes/bilibili/cache.ts +1 -1
- package/lib/routes/bing/daily-wallpaper.ts +9 -8
- package/lib/routes/byau/namespace.ts +6 -0
- package/lib/routes/byau/xinwen/index.ts +72 -0
- package/lib/routes/cpcaauto/index.ts +255 -0
- package/lib/routes/cpcaauto/namespace.ts +8 -0
- package/lib/routes/dehenglaw/index.ts +128 -0
- package/lib/routes/dehenglaw/namespace.ts +8 -0
- package/lib/routes/dehenglaw/templates/description.art +7 -0
- package/lib/routes/gov/stats/index.ts +25 -22
- package/lib/routes/gxmzu/ai.ts +1 -1
- package/lib/routes/gxmzu/lib.ts +9 -26
- package/lib/routes/gxmzu/utils/index.ts +31 -13
- package/lib/routes/gxmzu/yjs.ts +1 -1
- package/lib/routes/jou/utils/index.ts +35 -25
- package/lib/routes/lofter/tag.ts +3 -3
- package/lib/routes/lofter/user.ts +3 -3
- package/lib/routes/njxzc/utils/index.ts +31 -13
- package/lib/routes/qingting/podcast.ts +61 -39
- package/lib/routes/reuters/common.ts +2 -2
- package/lib/routes/sara/index.ts +66 -0
- package/lib/routes/sara/namespace.ts +6 -0
- package/lib/routes/tencent/news/author.ts +13 -11
- package/lib/routes/test/index.ts +11 -1
- package/lib/routes/twitter/api/mobile-api/login.ts +29 -28
- package/lib/routes/twitter/namespace.ts +2 -2
- package/lib/routes/twitter/user.ts +5 -0
- package/lib/routes/u3c3/index.ts +1 -1
- package/lib/routes/u3c3/namespace.ts +1 -1
- package/lib/routes/u9a9/index.ts +2 -2
- package/lib/routes/u9a9/namespace.ts +1 -1
- package/lib/routes/zsxq/group.ts +63 -0
- package/lib/routes/zsxq/namespace.ts +6 -0
- package/lib/routes/zsxq/types.ts +149 -0
- package/lib/routes/zsxq/user.ts +58 -0
- package/lib/routes/zsxq/utils.ts +70 -0
- package/lib/setup.test.ts +183 -12
- package/lib/utils/render.ts +1 -1
- package/lib/utils/request-rewriter/get.ts +8 -1
- package/lib/utils/wechat-mp.test.ts +411 -32
- package/lib/utils/wechat-mp.ts +447 -76
- package/lib/views/{rss3-ums.ts → rss3.ts} +2 -2
- package/package.json +14 -14
|
@@ -1,6 +1,29 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { describe, expect, it, vi, afterEach } from 'vitest';
|
|
2
2
|
import { load } from 'cheerio';
|
|
3
|
-
import
|
|
3
|
+
import Parser from 'rss-parser';
|
|
4
|
+
import InvalidParameterError from '@/errors/types/invalid-parameter';
|
|
5
|
+
import { exportedForTestingOnly, WeChatMpError, fetchArticle, finishArticleItem, fixArticleContent, normalizeUrl } from '@/utils/wechat-mp';
|
|
6
|
+
const { toggleWerror, ExtractMetadata, showTypeMapReverse } = exportedForTestingOnly;
|
|
7
|
+
|
|
8
|
+
vi.mock('@/utils/request-rewriter', () => ({ default: null }));
|
|
9
|
+
const { default: app } = await import('@/app');
|
|
10
|
+
const parser = new Parser();
|
|
11
|
+
|
|
12
|
+
afterEach(() => toggleWerror(false));
|
|
13
|
+
|
|
14
|
+
const expectedItem: {
|
|
15
|
+
title: string;
|
|
16
|
+
summary: string;
|
|
17
|
+
author: string;
|
|
18
|
+
mpName: string;
|
|
19
|
+
link: string;
|
|
20
|
+
} = {
|
|
21
|
+
title: 'title',
|
|
22
|
+
summary: 'summary',
|
|
23
|
+
author: 'author',
|
|
24
|
+
mpName: 'mpName',
|
|
25
|
+
link: '', // to be filled
|
|
26
|
+
};
|
|
4
27
|
|
|
5
28
|
// date from the cache will be an ISO8601 string, so we need to use this function
|
|
6
29
|
const compareDate = (date1, date2) => {
|
|
@@ -8,8 +31,227 @@ const compareDate = (date1, date2) => {
|
|
|
8
31
|
date2 = typeof date2 === 'string' ? new Date(date2) : date2;
|
|
9
32
|
return date1.getTime() === date2.getTime();
|
|
10
33
|
};
|
|
34
|
+
const genScriptHtmlStr = (script: string) => `
|
|
35
|
+
<html lang="">
|
|
36
|
+
<script type="text/javascript" nonce="123456789">
|
|
37
|
+
${script}
|
|
38
|
+
</script>
|
|
39
|
+
</html>
|
|
40
|
+
`;
|
|
41
|
+
const testFetchArticleFinishArticleItem = async (path: string, { setMpNameAsAuthor = false, skipLink = false } = {}) => {
|
|
42
|
+
const ct = 1_636_626_300;
|
|
43
|
+
const httpsUrl = `https://mp.weixin.qq.com/rsshub_test${path}`;
|
|
44
|
+
const httpUrl = 'http' + httpsUrl.slice(5);
|
|
45
|
+
|
|
46
|
+
const expectedDate = new Date(ct * 1000);
|
|
47
|
+
|
|
48
|
+
const expectedItem_ = {
|
|
49
|
+
...expectedItem,
|
|
50
|
+
link: httpsUrl,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const fetchArticleItem = await fetchArticle(httpUrl);
|
|
54
|
+
expect(compareDate(fetchArticleItem.pubDate, expectedDate)).toBe(true);
|
|
55
|
+
expect(fetchArticleItem).toMatchObject(expectedItem_);
|
|
56
|
+
|
|
57
|
+
const ToBeFinishedArticleItem = { link: httpUrl };
|
|
58
|
+
const expectedFinishedArticleItem = { ...fetchArticleItem };
|
|
59
|
+
expectedFinishedArticleItem.author = setMpNameAsAuthor ? <string>expectedFinishedArticleItem.mpName : expectedFinishedArticleItem.author;
|
|
60
|
+
expectedFinishedArticleItem.link = skipLink ? ToBeFinishedArticleItem.link : expectedFinishedArticleItem.link;
|
|
61
|
+
|
|
62
|
+
const finishedArticleItem = await finishArticleItem(ToBeFinishedArticleItem, setMpNameAsAuthor, skipLink);
|
|
63
|
+
expect(compareDate(finishedArticleItem.pubDate, fetchArticleItem.pubDate)).toBe(true);
|
|
64
|
+
delete expectedFinishedArticleItem.pubDate;
|
|
65
|
+
expect(finishedArticleItem).toMatchObject(expectedFinishedArticleItem);
|
|
66
|
+
|
|
67
|
+
return fetchArticleItem;
|
|
68
|
+
};
|
|
11
69
|
|
|
12
70
|
describe('wechat-mp', () => {
|
|
71
|
+
it('ExtractMetadata.common', () => {
|
|
72
|
+
expect(ExtractMetadata.common(load(''))).toStrictEqual({});
|
|
73
|
+
|
|
74
|
+
expect(
|
|
75
|
+
ExtractMetadata.common(
|
|
76
|
+
load(
|
|
77
|
+
genScriptHtmlStr(`
|
|
78
|
+
window.fake_item_show_type = '5' || '';
|
|
79
|
+
window.fake_real_item_show_type = '5' || '';
|
|
80
|
+
window.fake_ct = '1713009660' || '';
|
|
81
|
+
`)
|
|
82
|
+
)
|
|
83
|
+
)
|
|
84
|
+
).toMatchObject({});
|
|
85
|
+
|
|
86
|
+
expect(
|
|
87
|
+
ExtractMetadata.common(
|
|
88
|
+
load(
|
|
89
|
+
genScriptHtmlStr(`
|
|
90
|
+
window.item_show_type = '5' || '';
|
|
91
|
+
window.real_item_show_type = '5' || '';
|
|
92
|
+
window.ct = '1713009660' || '';
|
|
93
|
+
`)
|
|
94
|
+
)
|
|
95
|
+
)
|
|
96
|
+
).toMatchObject({
|
|
97
|
+
showType: showTypeMapReverse['5'],
|
|
98
|
+
realShowType: showTypeMapReverse['5'],
|
|
99
|
+
createTime: '1713009660',
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(
|
|
103
|
+
ExtractMetadata.common(
|
|
104
|
+
load(
|
|
105
|
+
genScriptHtmlStr(`
|
|
106
|
+
var item_show_type = "5";
|
|
107
|
+
var real_item_show_type = "5";
|
|
108
|
+
var ct = "1713009660";
|
|
109
|
+
var msg_source_url = 'https://mp.weixin.qq.com/rsshub_test/fake';
|
|
110
|
+
`)
|
|
111
|
+
)
|
|
112
|
+
)
|
|
113
|
+
).toMatchObject({
|
|
114
|
+
showType: showTypeMapReverse['5'],
|
|
115
|
+
realShowType: showTypeMapReverse['5'],
|
|
116
|
+
createTime: '1713009660',
|
|
117
|
+
sourceUrl: 'https://mp.weixin.qq.com/rsshub_test/fake',
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
expect(
|
|
121
|
+
ExtractMetadata.common(
|
|
122
|
+
load(
|
|
123
|
+
genScriptHtmlStr(`
|
|
124
|
+
var item_show_type = "998877665544332211";
|
|
125
|
+
var real_item_show_type = "112233445566778899";
|
|
126
|
+
var ct = "1713009660";
|
|
127
|
+
`)
|
|
128
|
+
)
|
|
129
|
+
)
|
|
130
|
+
).toMatchObject({
|
|
131
|
+
showType: '998877665544332211',
|
|
132
|
+
realShowType: '112233445566778899',
|
|
133
|
+
createTime: '1713009660',
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
it('ExtractMetadata.img', () => {
|
|
137
|
+
expect(ExtractMetadata.img(load(''))).toStrictEqual({});
|
|
138
|
+
|
|
139
|
+
expect(
|
|
140
|
+
ExtractMetadata.img(
|
|
141
|
+
load(
|
|
142
|
+
genScriptHtmlStr(`
|
|
143
|
+
window.picture_page_info_list = [
|
|
144
|
+
{
|
|
145
|
+
cdn_url: 'https://mmbiz.qpic.cn/rsshub_test/fake_img_1/0?wx_fmt=jpeg',
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
cdn_url: 'https://mmbiz.qpic.cn/rsshub_test/fake_img_2/0?wx_fmt=jpeg',
|
|
149
|
+
},
|
|
150
|
+
].slice(0, 20);
|
|
151
|
+
`)
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
).toMatchObject({
|
|
155
|
+
imgUrls: ['https://mmbiz.qpic.cn/rsshub_test/fake_img_1/0?wx_fmt=jpeg', 'https://mmbiz.qpic.cn/rsshub_test/fake_img_2/0?wx_fmt=jpeg'],
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
it('ExtractMetadata.audio', () => {
|
|
159
|
+
expect(ExtractMetadata.audio(load(''))).toStrictEqual({});
|
|
160
|
+
|
|
161
|
+
expect(
|
|
162
|
+
ExtractMetadata.audio(
|
|
163
|
+
load(
|
|
164
|
+
genScriptHtmlStr(`
|
|
165
|
+
reportOpt = {
|
|
166
|
+
voiceid: "",
|
|
167
|
+
uin: "",
|
|
168
|
+
biz: "",
|
|
169
|
+
mid: "",
|
|
170
|
+
idx: ""
|
|
171
|
+
};
|
|
172
|
+
`)
|
|
173
|
+
)
|
|
174
|
+
)
|
|
175
|
+
).toMatchObject({});
|
|
176
|
+
|
|
177
|
+
expect(
|
|
178
|
+
ExtractMetadata.audio(
|
|
179
|
+
load(
|
|
180
|
+
genScriptHtmlStr(`
|
|
181
|
+
window.cgiData = {
|
|
182
|
+
voiceid: "rsshub_test_voiceid_1",
|
|
183
|
+
duration: "6567" * 1,
|
|
184
|
+
};
|
|
185
|
+
`)
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
).toMatchObject({
|
|
189
|
+
voiceId: 'rsshub_test_voiceid_1',
|
|
190
|
+
duration: '6567',
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
expect(
|
|
194
|
+
ExtractMetadata.audio(
|
|
195
|
+
load(
|
|
196
|
+
genScriptHtmlStr(`
|
|
197
|
+
window.cgiData = {
|
|
198
|
+
voiceid: "rsshub_test_voiceid_1",
|
|
199
|
+
};
|
|
200
|
+
`)
|
|
201
|
+
)
|
|
202
|
+
)
|
|
203
|
+
).toMatchObject({
|
|
204
|
+
voiceId: 'rsshub_test_voiceid_1',
|
|
205
|
+
duration: null,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
expect(
|
|
209
|
+
ExtractMetadata.audio(
|
|
210
|
+
load(
|
|
211
|
+
genScriptHtmlStr(`
|
|
212
|
+
reportOpt = {
|
|
213
|
+
voiceid: "",
|
|
214
|
+
uin: "",
|
|
215
|
+
biz: "",
|
|
216
|
+
mid: "",
|
|
217
|
+
idx: ""
|
|
218
|
+
};
|
|
219
|
+
window.cgiData = {
|
|
220
|
+
voiceid: "rsshub_test_voiceid_1",
|
|
221
|
+
duration: "6567" * 1,
|
|
222
|
+
};
|
|
223
|
+
`)
|
|
224
|
+
)
|
|
225
|
+
)
|
|
226
|
+
).toMatchObject({
|
|
227
|
+
voiceId: 'rsshub_test_voiceid_1',
|
|
228
|
+
duration: '6567',
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
it('ExtractMetadata.location', () => {
|
|
232
|
+
expect(ExtractMetadata.location(load(''))).toStrictEqual({});
|
|
233
|
+
|
|
234
|
+
expect(
|
|
235
|
+
ExtractMetadata.location(
|
|
236
|
+
load(
|
|
237
|
+
genScriptHtmlStr(`
|
|
238
|
+
window.ip_wording = {
|
|
239
|
+
countryName: '中国',
|
|
240
|
+
countryId: '156',
|
|
241
|
+
provinceName: '广东',
|
|
242
|
+
provinceId: '',
|
|
243
|
+
cityName: '',
|
|
244
|
+
cityId: ''
|
|
245
|
+
};
|
|
246
|
+
`)
|
|
247
|
+
)
|
|
248
|
+
)
|
|
249
|
+
).toMatchObject({
|
|
250
|
+
countryName: '中国',
|
|
251
|
+
provinceName: '广东',
|
|
252
|
+
cityName: '',
|
|
253
|
+
});
|
|
254
|
+
});
|
|
13
255
|
it('fixArticleContent', () => {
|
|
14
256
|
const divHeader = '<div class="rich_media_content " id="js_content">';
|
|
15
257
|
const divFooter = '</div>';
|
|
@@ -84,41 +326,178 @@ describe('wechat-mp', () => {
|
|
|
84
326
|
expect(normalizeUrl(somethingElseWithHash.replace('https://', 'http://'))).toBe(somethingElse);
|
|
85
327
|
|
|
86
328
|
const notWechatMp = 'https://im.not.wechat.mp/and/an/error/is/expected';
|
|
87
|
-
expect(() => normalizeUrl(notWechatMp)).toThrow();
|
|
329
|
+
expect(() => normalizeUrl(notWechatMp)).toThrow('URL host must be "mp.weixin.qq.com"');
|
|
88
330
|
expect(normalizeUrl(notWechatMp, true)).toBe(notWechatMp);
|
|
331
|
+
|
|
332
|
+
const unknownSearchParam = mpArticleRoot + '?unknown=param';
|
|
333
|
+
toggleWerror(false);
|
|
334
|
+
expect(normalizeUrl(unknownSearchParam)).toBe(unknownSearchParam);
|
|
335
|
+
toggleWerror(true);
|
|
336
|
+
expect(() => normalizeUrl(unknownSearchParam)).toThrow('WarningAsError: unknown URL search parameters');
|
|
337
|
+
|
|
338
|
+
const unknownPath = mpRoot + '/unknown/path';
|
|
339
|
+
toggleWerror(false);
|
|
340
|
+
expect(normalizeUrl(unknownPath)).toBe(unknownPath);
|
|
341
|
+
toggleWerror(true);
|
|
342
|
+
expect(() => normalizeUrl(unknownPath, true)).toThrow('WarningAsError: unknown URL path');
|
|
343
|
+
|
|
344
|
+
const ampEscapedUrl = longUrl.replaceAll('&', '&');
|
|
345
|
+
expect(normalizeUrl(ampEscapedUrl)).toBe(longUrlShortened);
|
|
89
346
|
});
|
|
90
347
|
|
|
91
|
-
it('fetchArticle_&
|
|
92
|
-
const
|
|
93
|
-
const
|
|
94
|
-
|
|
348
|
+
it('fetchArticle_&_finishArticleItem_appMsg', async () => {
|
|
349
|
+
const fetchArticleItem = await testFetchArticleFinishArticleItem('/appMsg');
|
|
350
|
+
const $ = load(fetchArticleItem.description);
|
|
351
|
+
expect($('iframe').attr()).toMatchObject({
|
|
352
|
+
src:
|
|
353
|
+
'https://v.qq.com/txp/iframe/player.html?origin=https%3A%2F%2Fmp.weixin.qq.com' +
|
|
354
|
+
'&containerId=js_tx_video_container_0.3863487104715233&vid=fake&width=677&height=380.8125' +
|
|
355
|
+
'&autoplay=false&allowFullScreen=true&chid=17&full=true&show1080p=false&isDebugIframe=false',
|
|
356
|
+
width: '677',
|
|
357
|
+
height: '380.8125',
|
|
358
|
+
});
|
|
359
|
+
expect($('audio').attr()).toMatchObject({
|
|
360
|
+
src: 'https://res.wx.qq.com/voice/getvoice?mediaid=rsshub_test',
|
|
361
|
+
title: 'title',
|
|
362
|
+
});
|
|
363
|
+
expect($('a').attr()).toMatchObject({
|
|
364
|
+
href: 'https://mp.weixin.qq.com/rsshub_test/fake',
|
|
365
|
+
});
|
|
366
|
+
expect(fetchArticleItem.description).toContain('description');
|
|
367
|
+
expect(fetchArticleItem.description).toContain('📍发表于:中国 福建');
|
|
368
|
+
expect(fetchArticleItem.description).toContain('🔗️ 阅读原文');
|
|
369
|
+
});
|
|
95
370
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
371
|
+
it('fetchArticle_&_finishArticleItem_img', async () => {
|
|
372
|
+
const fetchArticleItem = await testFetchArticleFinishArticleItem('/img');
|
|
373
|
+
const $ = load(fetchArticleItem.description);
|
|
374
|
+
expect($.text()).toBe('summary');
|
|
375
|
+
expect($('img:nth-of-type(1)').attr()).toMatchObject({
|
|
376
|
+
src: 'https://mmbiz.qpic.cn/rsshub_test/fake_img_1/0?wx_fmt=jpeg',
|
|
377
|
+
});
|
|
378
|
+
expect($('img:nth-of-type(2)').attr()).toMatchObject({
|
|
379
|
+
src: 'https://mmbiz.qpic.cn/rsshub_test/fake_img_2/0?wx_fmt=jpeg',
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('fetchArticle_&_finishArticleItem_audio', async () => {
|
|
384
|
+
const fetchArticleItem = await testFetchArticleFinishArticleItem('/audio');
|
|
385
|
+
const $ = load(fetchArticleItem.description);
|
|
386
|
+
expect($.text()).toBe('summary');
|
|
387
|
+
expect($('audio').attr()).toMatchObject({
|
|
388
|
+
controls: '',
|
|
389
|
+
src: 'https://res.wx.qq.com/voice/getvoice?mediaid=rsshub_test_voiceid_1',
|
|
390
|
+
style: 'width:100%',
|
|
104
391
|
title: 'title',
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
392
|
+
});
|
|
393
|
+
expect(fetchArticleItem).toMatchObject({
|
|
394
|
+
enclosure_type: 'audio/mp3',
|
|
395
|
+
enclosure_url: 'https://res.wx.qq.com/voice/getvoice?mediaid=rsshub_test_voiceid_1',
|
|
396
|
+
itunes_duration: '6567',
|
|
397
|
+
});
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it('fetchArticle_&_finishArticleItem_video', async () => {
|
|
401
|
+
const fetchArticleItem = await testFetchArticleFinishArticleItem('/video');
|
|
402
|
+
const $ = load(fetchArticleItem.description);
|
|
403
|
+
expect($.text()).toBe('summary');
|
|
404
|
+
expect($('img').attr()).toMatchObject({
|
|
405
|
+
src: 'https://mmbiz.qpic.cn/rsshub_test/og_img_1/0?wx_fmt=jpeg',
|
|
406
|
+
});
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it('fetchArticle_&_finishArticleItem_fallback', async () => {
|
|
410
|
+
const fetchArticleItem = await testFetchArticleFinishArticleItem('/fallback');
|
|
411
|
+
const $ = load(fetchArticleItem.description);
|
|
412
|
+
expect($.text()).toBe('summary');
|
|
413
|
+
expect($('img').attr()).toMatchObject({
|
|
414
|
+
src: 'https://mmbiz.qpic.cn/rsshub_test/og_img_1/0?wx_fmt=jpeg',
|
|
415
|
+
});
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it('finishArticleItem_param', async () => {
|
|
419
|
+
await testFetchArticleFinishArticleItem('/fallback', { setMpNameAsAuthor: false, skipLink: false });
|
|
420
|
+
await testFetchArticleFinishArticleItem('/fallback', { setMpNameAsAuthor: true, skipLink: false });
|
|
421
|
+
await testFetchArticleFinishArticleItem('/fallback', { setMpNameAsAuthor: false, skipLink: true });
|
|
422
|
+
await testFetchArticleFinishArticleItem('/fallback', { setMpNameAsAuthor: true, skipLink: true });
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
it('hit_waf', async () => {
|
|
426
|
+
try {
|
|
427
|
+
await fetchArticle('https://mp.weixin.qq.com/s/rsshub_test_hit_waf');
|
|
428
|
+
expect.unreachable('Should throw an error');
|
|
429
|
+
} catch (error) {
|
|
430
|
+
expect(error).toBeInstanceOf(WeChatMpError);
|
|
431
|
+
expect((<WeChatMpError>error).message).not.toContain('console.log');
|
|
432
|
+
expect((<WeChatMpError>error).message).not.toContain('.style');
|
|
433
|
+
expect((<WeChatMpError>error).message).not.toContain('Consider raise an issue');
|
|
434
|
+
expect((<WeChatMpError>error).message).toContain('request blocked by WAF:');
|
|
435
|
+
expect((<WeChatMpError>error).message).toContain('/mp/rsshub_test/waf');
|
|
436
|
+
expect((<WeChatMpError>error).message).toContain('Title');
|
|
437
|
+
expect((<WeChatMpError>error).message).toContain('环境异常');
|
|
438
|
+
}
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it('unknown_page', async () => {
|
|
442
|
+
const unknownPageUrl = 'https://mp.weixin.qq.com/s/unknown_page';
|
|
443
|
+
try {
|
|
444
|
+
await fetchArticle(unknownPageUrl);
|
|
445
|
+
expect.unreachable('Should throw an error');
|
|
446
|
+
} catch (error) {
|
|
447
|
+
expect(error).toBeInstanceOf(WeChatMpError);
|
|
448
|
+
expect((<WeChatMpError>error).message).not.toContain('console.log');
|
|
449
|
+
expect((<WeChatMpError>error).message).not.toContain('.style');
|
|
450
|
+
expect((<WeChatMpError>error).message).toContain('Consider raise an issue');
|
|
451
|
+
expect((<WeChatMpError>error).message).toContain('unknown page,');
|
|
452
|
+
expect((<WeChatMpError>error).message).toContain('Title Unknown paragraph');
|
|
453
|
+
expect((<WeChatMpError>error).message).toContain(unknownPageUrl);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('deleted_page', async () => {
|
|
458
|
+
const deletedPageUrl = 'https://mp.weixin.qq.com/s/deleted_page';
|
|
459
|
+
|
|
460
|
+
try {
|
|
461
|
+
await fetchArticle(deletedPageUrl);
|
|
462
|
+
expect.unreachable('Should throw an error');
|
|
463
|
+
} catch (error) {
|
|
464
|
+
expect(error).toBeInstanceOf(WeChatMpError);
|
|
465
|
+
expect((<WeChatMpError>error).message).not.toContain('console.log');
|
|
466
|
+
expect((<WeChatMpError>error).message).not.toContain('.style');
|
|
467
|
+
expect((<WeChatMpError>error).message).not.toContain('Consider raise an issue');
|
|
468
|
+
expect((<WeChatMpError>error).message).toContain('deleted by author:');
|
|
469
|
+
expect((<WeChatMpError>error).message).toContain('Title 该内容已被发布者删除');
|
|
470
|
+
expect((<WeChatMpError>error).message).toContain(deletedPageUrl);
|
|
471
|
+
}
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
it('redirect', () => {
|
|
475
|
+
expect(fetchArticle('https://mp.weixin.qq.com/s/rsshub_test_redirect_no_location')).rejects.toThrow('redirect without location');
|
|
476
|
+
expect(fetchArticle('https://mp.weixin.qq.com/s/rsshub_test_recursive_redirect')).rejects.toThrow('too many redirects');
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
it('route_test', async () => {
|
|
480
|
+
try {
|
|
481
|
+
await app.request('/test/wechat-mp');
|
|
482
|
+
} catch (error) {
|
|
483
|
+
expect(error).toBeInstanceOf(InvalidParameterError);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
const responseShort = await app.request('/test/wechat-mp/rsshub_test');
|
|
487
|
+
const parsedShort = await parser.parseString(await responseShort.text());
|
|
488
|
+
const expectedItemShort = {
|
|
489
|
+
author: expectedItem.author,
|
|
490
|
+
title: expectedItem.title,
|
|
491
|
+
link: 'https://mp.weixin.qq.com/s/rsshub_test',
|
|
492
|
+
};
|
|
493
|
+
expect(parsedShort.items[0]).toMatchObject(expectedItemShort);
|
|
494
|
+
|
|
495
|
+
const responseLong = await app.request('/test/wechat-mp/__biz=rsshub_test&mid=1&idx=1&sn=1');
|
|
496
|
+
const parsedLong = await parser.parseString(await responseLong.text());
|
|
497
|
+
const expectedItemLong = {
|
|
498
|
+
...expectedItemShort,
|
|
499
|
+
link: 'https://mp.weixin.qq.com/s?__biz=rsshub_test&mid=1&idx=1&sn=1',
|
|
110
500
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const fetchArticleItem = await fetchArticle(httpUrl);
|
|
114
|
-
expect(compareDate(fetchArticleItem.pubDate, expectedDate)).toBe(true);
|
|
115
|
-
delete fetchArticleItem.pubDate;
|
|
116
|
-
expect(fetchArticleItem).toEqual(expectedItem);
|
|
117
|
-
|
|
118
|
-
delete expectedItem.mpName;
|
|
119
|
-
const finishedArticleItem = await finishArticleItem({ link: httpUrl });
|
|
120
|
-
expect(compareDate(finishedArticleItem.pubDate, expectedDate)).toBe(true);
|
|
121
|
-
delete finishedArticleItem.pubDate;
|
|
122
|
-
expect(finishedArticleItem).toEqual(expectedItem);
|
|
501
|
+
expect(parsedLong.items[0]).toMatchObject(expectedItemLong);
|
|
123
502
|
});
|
|
124
503
|
});
|