@jackwener/opencli 1.7.8 → 1.7.10
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/README.md +49 -14
- package/README.zh-CN.md +30 -10
- package/cli-manifest.json +646 -30
- package/clis/36kr/news.js +1 -1
- package/clis/apple-podcasts/commands.test.js +4 -4
- package/clis/apple-podcasts/episodes.js +1 -1
- package/clis/apple-podcasts/search.js +1 -1
- package/clis/apple-podcasts/top.js +1 -1
- package/clis/arxiv/paper.js +1 -1
- package/clis/arxiv/search.js +1 -1
- package/clis/band/mentions.js +3 -3
- package/clis/bbc/news.js +1 -1
- package/clis/bilibili/subtitle.js +2 -2
- package/clis/bloomberg/businessweek.js +1 -1
- package/clis/bloomberg/economics.js +1 -1
- package/clis/bloomberg/industries.js +1 -1
- package/clis/bloomberg/main.js +1 -1
- package/clis/bloomberg/markets.js +1 -1
- package/clis/bloomberg/opinions.js +1 -1
- package/clis/bloomberg/politics.js +1 -1
- package/clis/bloomberg/tech.js +1 -1
- package/clis/boss/search.js +49 -8
- package/clis/boss/search.test.js +78 -0
- package/clis/boss/send.js +3 -3
- package/clis/chatgpt/image.js +37 -8
- package/clis/chatgpt/image.test.js +92 -0
- package/clis/chatgpt/utils.js +39 -6
- package/clis/chatgpt/utils.test.js +63 -0
- package/clis/chatgpt-app/ask.js +1 -1
- package/clis/chatgpt-app/ax.js +4 -2
- package/clis/chatgpt-app/ax.test.js +12 -0
- package/clis/chatgpt-app/model.js +1 -1
- package/clis/chatgpt-app/new.js +1 -1
- package/clis/chatgpt-app/read.js +1 -1
- package/clis/chatgpt-app/send.js +1 -1
- package/clis/chatgpt-app/status.js +1 -1
- package/clis/chatwise/ask.js +2 -2
- package/clis/chatwise/model.js +2 -2
- package/clis/chatwise/send.js +2 -2
- package/clis/claude/ask.js +128 -0
- package/clis/claude/ask.test.js +338 -0
- package/clis/claude/commands.test.js +118 -0
- package/clis/claude/detail.js +29 -0
- package/clis/claude/history.js +31 -0
- package/clis/claude/new.js +21 -0
- package/clis/claude/read.js +24 -0
- package/clis/claude/send.js +41 -0
- package/clis/claude/status.js +24 -0
- package/clis/claude/utils.js +440 -0
- package/clis/claude/utils.test.js +148 -0
- package/clis/codex/ask.js +2 -2
- package/clis/codex/send.js +2 -2
- package/clis/ctrip/search.js +1 -1
- package/clis/ctrip/search.test.js +4 -4
- package/clis/cursor/ask.js +2 -2
- package/clis/cursor/composer.js +2 -2
- package/clis/cursor/send.js +2 -2
- package/clis/deepseek/ask.js +17 -4
- package/clis/deepseek/ask.test.js +46 -0
- package/clis/deepseek/utils.js +55 -16
- package/clis/deepseek/utils.test.js +124 -5
- package/clis/doubao/utils.js +53 -11
- package/clis/doubao/utils.test.js +22 -2
- package/clis/eastmoney/announcement.js +1 -1
- package/clis/eastmoney/convertible.js +1 -1
- package/clis/eastmoney/etf.js +1 -1
- package/clis/eastmoney/holders.js +1 -1
- package/clis/eastmoney/index-board.js +1 -1
- package/clis/eastmoney/kline.js +1 -1
- package/clis/eastmoney/kuaixun.js +1 -1
- package/clis/eastmoney/longhu.js +1 -1
- package/clis/eastmoney/money-flow.js +1 -1
- package/clis/eastmoney/northbound.js +1 -1
- package/clis/eastmoney/quote.js +1 -1
- package/clis/eastmoney/rank.js +1 -1
- package/clis/eastmoney/sectors.js +1 -1
- package/clis/facebook/marketplace-inbox.js +83 -0
- package/clis/facebook/marketplace-listings.js +83 -0
- package/clis/facebook/marketplace.test.js +91 -0
- package/clis/google/news.js +1 -1
- package/clis/google/suggest.js +1 -1
- package/clis/google/trends.js +1 -1
- package/clis/google-scholar/cite.js +74 -0
- package/clis/google-scholar/cite.test.js +47 -0
- package/clis/google-scholar/profile.js +92 -0
- package/clis/google-scholar/profile.test.js +49 -0
- package/clis/google-scholar/search.js +1 -1
- package/clis/google-scholar/search.test.js +15 -0
- package/clis/hf/top.js +1 -1
- package/clis/instagram/collection-create.js +57 -0
- package/clis/instagram/saved.js +21 -7
- package/clis/jd/item.js +679 -47
- package/clis/jd/item.test.js +318 -7
- package/clis/jd/item.test.ts +517 -0
- package/clis/lesswrong/comments.js +1 -1
- package/clis/lesswrong/curated.js +1 -1
- package/clis/lesswrong/frontpage.js +1 -1
- package/clis/lesswrong/new.js +1 -1
- package/clis/lesswrong/read.js +1 -1
- package/clis/lesswrong/sequences.js +1 -1
- package/clis/lesswrong/shortform.js +1 -1
- package/clis/lesswrong/tag.js +1 -1
- package/clis/lesswrong/tags.js +1 -1
- package/clis/lesswrong/top-month.js +1 -1
- package/clis/lesswrong/top-week.js +1 -1
- package/clis/lesswrong/top-year.js +1 -1
- package/clis/lesswrong/top.js +1 -1
- package/clis/lesswrong/user-posts.js +1 -1
- package/clis/lesswrong/user.js +1 -1
- package/clis/paperreview/commands.test.js +6 -6
- package/clis/paperreview/feedback.js +1 -1
- package/clis/paperreview/review.js +1 -1
- package/clis/paperreview/submit.js +1 -1
- package/clis/producthunt/posts.js +1 -1
- package/clis/producthunt/today.js +1 -1
- package/clis/sinablog/search.js +1 -1
- package/clis/sinafinance/news.js +1 -1
- package/clis/sinafinance/stock.js +1 -1
- package/clis/sinafinance/stock.test.js +2 -2
- package/clis/spotify/spotify.js +6 -6
- package/clis/substack/search.js +1 -1
- package/clis/toutiao/articles.js +5 -6
- package/clis/toutiao/articles.test.js +22 -15
- package/clis/twitter/followers.js +2 -2
- package/clis/twitter/following.js +224 -73
- package/clis/twitter/following.test.js +277 -0
- package/clis/twitter/post.js +184 -47
- package/clis/twitter/post.test.js +114 -34
- package/clis/uiverse/_shared.js +63 -4
- package/clis/uiverse/_shared.test.js +7 -0
- package/clis/uiverse/code.js +1 -0
- package/clis/uiverse/navigation.test.js +12 -0
- package/clis/uiverse/preview.js +1 -0
- package/clis/web/read.js +319 -81
- package/clis/web/read.test.js +221 -5
- package/clis/weibo/favorites.js +169 -0
- package/clis/weibo/favorites.test.js +114 -0
- package/clis/weibo/publish.js +282 -0
- package/clis/weibo/publish.test.js +183 -0
- package/clis/weread/ranking.js +1 -1
- package/clis/weread/search-regression.test.js +8 -8
- package/clis/weread/search.js +1 -1
- package/clis/wikipedia/random.js +1 -1
- package/clis/wikipedia/search.js +1 -1
- package/clis/wikipedia/summary.js +1 -1
- package/clis/wikipedia/trending.js +1 -1
- package/clis/xianyu/chat.js +3 -3
- package/clis/xianyu/item.js +2 -2
- package/clis/xianyu/item.test.js +3 -3
- package/clis/xiaohongshu/search.js +17 -2
- package/clis/xiaohongshu/search.test.js +37 -1
- package/clis/xiaoyuzhou/download.js +1 -1
- package/clis/xiaoyuzhou/download.test.js +3 -3
- package/clis/xiaoyuzhou/episode.js +1 -1
- package/clis/xiaoyuzhou/podcast-episodes.js +1 -1
- package/clis/xiaoyuzhou/podcast-episodes.test.js +2 -2
- package/clis/xiaoyuzhou/podcast.js +1 -1
- package/clis/xiaoyuzhou/transcript.js +1 -1
- package/clis/xiaoyuzhou/transcript.test.js +5 -5
- package/clis/yollomi/models.js +1 -1
- package/clis/youtube/channel.js +24 -1
- package/clis/youtube/channel.test.js +59 -0
- package/clis/zhihu/answer.js +21 -162
- package/clis/zhihu/answer.test.js +26 -53
- package/clis/zhihu/collection.js +197 -0
- package/clis/zhihu/collection.test.js +290 -0
- package/clis/zhihu/collections.js +127 -0
- package/clis/zhihu/collections.test.js +182 -0
- package/clis/zhihu/comment.js +24 -305
- package/clis/zhihu/comment.test.js +31 -35
- package/clis/zhihu/favorite.js +44 -182
- package/clis/zhihu/favorite.test.js +30 -167
- package/clis/zhihu/follow.js +25 -56
- package/clis/zhihu/follow.test.js +20 -23
- package/clis/zhihu/like.js +22 -67
- package/clis/zhihu/like.test.js +19 -42
- package/clis/zhihu/search.js +3 -2
- package/clis/zhihu/write-shared.js +8 -1
- package/clis/zhihu/write-shared.test.js +1 -0
- package/clis/zlibrary/commands.test.js +75 -0
- package/clis/zlibrary/info.js +47 -0
- package/clis/zlibrary/search.js +46 -0
- package/clis/zlibrary/utils.js +136 -0
- package/dist/src/adapter-source.d.ts +11 -0
- package/dist/src/adapter-source.js +24 -0
- package/dist/src/adapter-source.test.js +29 -0
- package/dist/src/browser/base-page.d.ts +3 -1
- package/dist/src/browser/base-page.js +76 -1
- package/dist/src/browser/base-page.test.d.ts +1 -0
- package/dist/src/browser/base-page.test.js +74 -0
- package/dist/src/browser/bridge.d.ts +1 -2
- package/dist/src/browser/bridge.js +40 -41
- package/dist/src/browser/cdp.d.ts +1 -0
- package/dist/src/browser/cdp.js +3 -3
- package/dist/src/browser/daemon-client.d.ts +38 -4
- package/dist/src/browser/daemon-client.js +24 -7
- package/dist/src/browser/daemon-client.test.js +49 -0
- package/dist/src/browser/daemon-lifecycle.d.ts +23 -0
- package/dist/src/browser/daemon-lifecycle.js +67 -0
- package/dist/src/browser/daemon-version.d.ts +4 -0
- package/dist/src/browser/daemon-version.js +12 -0
- package/dist/src/browser/errors.js +3 -0
- package/dist/src/browser/errors.test.js +3 -0
- package/dist/src/browser/network-cache.d.ts +1 -0
- package/dist/src/browser/page.d.ts +3 -1
- package/dist/src/browser/page.js +10 -2
- package/dist/src/browser/profile.d.ts +14 -0
- package/dist/src/browser/profile.js +85 -0
- package/dist/src/build-manifest.d.ts +2 -0
- package/dist/src/build-manifest.js +13 -3
- package/dist/src/build-manifest.test.js +20 -2
- package/dist/src/cli.d.ts +6 -0
- package/dist/src/cli.js +477 -35
- package/dist/src/cli.test.js +303 -2
- package/dist/src/commanderAdapter.js +17 -9
- package/dist/src/commanderAdapter.test.js +67 -2
- package/dist/src/commands/daemon.d.ts +2 -0
- package/dist/src/commands/daemon.js +42 -1
- package/dist/src/commands/daemon.test.js +103 -2
- package/dist/src/completion-shared.js +1 -2
- package/dist/src/completion.test.js +3 -2
- package/dist/src/daemon.js +125 -41
- package/dist/src/doctor.d.ts +5 -6
- package/dist/src/doctor.js +77 -19
- package/dist/src/doctor.test.js +117 -0
- package/dist/src/engine.test.js +6 -5
- package/dist/src/errors.d.ts +14 -8
- package/dist/src/errors.js +36 -30
- package/dist/src/errors.test.js +5 -5
- package/dist/src/execution.d.ts +4 -0
- package/dist/src/execution.js +173 -25
- package/dist/src/execution.test.js +171 -1
- package/dist/src/main.js +10 -0
- package/dist/src/observation/artifact.d.ts +16 -0
- package/dist/src/observation/artifact.js +260 -0
- package/dist/src/observation/artifact.test.d.ts +1 -0
- package/dist/src/observation/artifact.test.js +121 -0
- package/dist/src/observation/events.d.ts +89 -0
- package/dist/src/observation/events.js +1 -0
- package/dist/src/observation/index.d.ts +7 -0
- package/dist/src/observation/index.js +7 -0
- package/dist/src/observation/manager.d.ts +9 -0
- package/dist/src/observation/manager.js +27 -0
- package/dist/src/observation/manager.test.d.ts +1 -0
- package/dist/src/observation/manager.test.js +13 -0
- package/dist/src/observation/redaction.d.ts +11 -0
- package/dist/src/observation/redaction.js +81 -0
- package/dist/src/observation/redaction.test.d.ts +1 -0
- package/dist/src/observation/redaction.test.js +32 -0
- package/dist/src/observation/retention.d.ts +32 -0
- package/dist/src/observation/retention.js +160 -0
- package/dist/src/observation/retention.test.d.ts +1 -0
- package/dist/src/observation/retention.test.js +118 -0
- package/dist/src/observation/ring-buffer.d.ts +22 -0
- package/dist/src/observation/ring-buffer.js +45 -0
- package/dist/src/observation/ring-buffer.test.d.ts +1 -0
- package/dist/src/observation/ring-buffer.test.js +22 -0
- package/dist/src/observation/session.d.ts +25 -0
- package/dist/src/observation/session.js +50 -0
- package/dist/src/pipeline/executor.test.js +1 -0
- package/dist/src/pipeline/steps/download.test.js +1 -0
- package/dist/src/pipeline/steps/fetch.js +1 -21
- package/dist/src/pipeline/steps/fetch.test.js +6 -12
- package/dist/src/plugin-scaffold.js +1 -1
- package/dist/src/plugin-scaffold.test.js +1 -1
- package/dist/src/registry.d.ts +40 -9
- package/dist/src/registry.js +3 -1
- package/dist/src/runtime-detect.d.ts +10 -0
- package/dist/src/runtime-detect.js +19 -0
- package/dist/src/runtime-detect.test.js +12 -1
- package/dist/src/runtime.d.ts +2 -0
- package/dist/src/runtime.js +1 -0
- package/dist/src/types.d.ts +22 -0
- package/dist/src/update-check.d.ts +31 -1
- package/dist/src/update-check.js +62 -16
- package/dist/src/update-check.test.js +86 -1
- package/package.json +1 -1
- package/dist/src/diagnostic.d.ts +0 -63
- package/dist/src/diagnostic.js +0 -292
- package/dist/src/diagnostic.test.js +0 -302
- /package/dist/src/{diagnostic.test.d.ts → adapter-source.test.d.ts} +0 -0
package/clis/jd/item.test.js
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { JSDOM } from 'jsdom';
|
|
2
3
|
import { getRegistry } from '@jackwener/opencli/registry';
|
|
4
|
+
import { AuthRequiredError } from '@jackwener/opencli/errors';
|
|
3
5
|
import { __test__ } from './item.js';
|
|
4
6
|
import './item.js';
|
|
7
|
+
const originalPerformance = globalThis.performance;
|
|
8
|
+
const originalWindow = globalThis.window;
|
|
9
|
+
const originalDocument = globalThis.document;
|
|
10
|
+
function restoreGlobals() {
|
|
11
|
+
globalThis.performance = originalPerformance;
|
|
12
|
+
globalThis.window = originalWindow;
|
|
13
|
+
globalThis.document = originalDocument;
|
|
14
|
+
}
|
|
5
15
|
describe('jd item adapter', () => {
|
|
6
16
|
const command = getRegistry().get('jd/item');
|
|
7
17
|
it('registers the command with correct shape', () => {
|
|
@@ -18,15 +28,79 @@ describe('jd item adapter', () => {
|
|
|
18
28
|
expect(skuArg.required).toBe(true);
|
|
19
29
|
expect(skuArg.positional).toBe(true);
|
|
20
30
|
});
|
|
21
|
-
it('has images arg with default
|
|
31
|
+
it('has images arg with default 200', () => {
|
|
22
32
|
const imagesArg = command.args.find((a) => a.name === 'images');
|
|
23
33
|
expect(imagesArg).toBeDefined();
|
|
24
|
-
expect(imagesArg.default).toBe(
|
|
34
|
+
expect(imagesArg.default).toBe(200);
|
|
35
|
+
});
|
|
36
|
+
it('fails fast when JD blocks the item page', async () => {
|
|
37
|
+
const page = {
|
|
38
|
+
evaluate: vi.fn()
|
|
39
|
+
.mockResolvedValueOnce('https://item.jd.com/100328272886.html')
|
|
40
|
+
.mockResolvedValueOnce({ looksBlocked: true })
|
|
41
|
+
.mockResolvedValueOnce({
|
|
42
|
+
error: 'JD page is blocked by login/security verification',
|
|
43
|
+
pageState: { looksBlocked: true },
|
|
44
|
+
}),
|
|
45
|
+
goto: vi.fn(),
|
|
46
|
+
wait: vi.fn(),
|
|
47
|
+
};
|
|
48
|
+
await expect(command.func(page, { sku: '100328272886', images: 5 })).rejects.toBeInstanceOf(AuthRequiredError);
|
|
49
|
+
expect(page.goto).not.toHaveBeenCalled();
|
|
50
|
+
});
|
|
51
|
+
it('fails fast when a loaded product page has no detail images', async () => {
|
|
52
|
+
const page = {
|
|
53
|
+
evaluate: vi.fn()
|
|
54
|
+
.mockResolvedValueOnce('https://item.jd.com/100328272886.html')
|
|
55
|
+
.mockResolvedValueOnce({ looksBlocked: false })
|
|
56
|
+
.mockResolvedValueOnce(undefined)
|
|
57
|
+
.mockResolvedValueOnce(null)
|
|
58
|
+
.mockResolvedValueOnce({
|
|
59
|
+
title: 'JD product',
|
|
60
|
+
price: '100',
|
|
61
|
+
shop: '京东自营',
|
|
62
|
+
specs: {},
|
|
63
|
+
mainImages: ['https://img10.360buyimg.com/pcpubliccms/jfs/t1/main.jpg'],
|
|
64
|
+
detailImages: [],
|
|
65
|
+
pageState: { isProductPage: true, looksBlocked: false },
|
|
66
|
+
}),
|
|
67
|
+
goto: vi.fn(),
|
|
68
|
+
wait: vi.fn(),
|
|
69
|
+
};
|
|
70
|
+
await expect(command.func(page, { sku: '100328272886', images: 5 })).rejects.toThrow('JD item detail images were not found');
|
|
71
|
+
});
|
|
72
|
+
it('allows zero-image requests to skip detail image fail-fast', async () => {
|
|
73
|
+
const data = {
|
|
74
|
+
title: 'JD product',
|
|
75
|
+
price: '100',
|
|
76
|
+
shop: '京东自营',
|
|
77
|
+
specs: {},
|
|
78
|
+
mainImages: [],
|
|
79
|
+
detailImages: [],
|
|
80
|
+
pageState: { isProductPage: true, looksBlocked: false },
|
|
81
|
+
};
|
|
82
|
+
const page = {
|
|
83
|
+
evaluate: vi.fn()
|
|
84
|
+
.mockResolvedValueOnce('https://item.jd.com/100328272886.html')
|
|
85
|
+
.mockResolvedValueOnce({ looksBlocked: false })
|
|
86
|
+
.mockResolvedValueOnce(undefined)
|
|
87
|
+
.mockResolvedValueOnce(null)
|
|
88
|
+
.mockResolvedValueOnce(data),
|
|
89
|
+
goto: vi.fn(),
|
|
90
|
+
wait: vi.fn(),
|
|
91
|
+
};
|
|
92
|
+
await expect(command.func(page, { sku: '100328272886', images: 0 })).resolves.toEqual([data]);
|
|
93
|
+
});
|
|
94
|
+
it('normalizes JD item URL input to a SKU before building selectors', () => {
|
|
95
|
+
expect(__test__.normalizeJdSkuInput('100328272886')).toBe('100328272886');
|
|
96
|
+
expect(__test__.normalizeJdSkuInput('https://item.jd.com/100328272886.html?purchasetab=gfgm')).toBe('100328272886');
|
|
97
|
+
expect(__test__.normalizeJdSkuInput('skuId=10218494560141')).toBe('10218494560141');
|
|
25
98
|
});
|
|
26
99
|
it('includes expected columns', () => {
|
|
27
|
-
expect(command.columns).toEqual(expect.arrayContaining(['title', 'price', 'shop', 'specs', '
|
|
100
|
+
expect(command.columns).toEqual(expect.arrayContaining(['title', 'price', 'shop', 'specs', 'mainImages', 'detailImages']));
|
|
101
|
+
expect(command.columns).not.toContain('avifImages');
|
|
28
102
|
});
|
|
29
|
-
it('extracts only
|
|
103
|
+
it('extracts only detail avif images and respects the limit', () => {
|
|
30
104
|
const result = __test__.extractAvifImages([
|
|
31
105
|
'https://img14.360buyimg.com/n1/jfs/t1/normal.jpg',
|
|
32
106
|
'https://img10.360buyimg.com/imgzone/jfs/t1/detail.avif',
|
|
@@ -36,8 +110,245 @@ describe('jd item adapter', () => {
|
|
|
36
110
|
'https://example.com/not-jd.avif',
|
|
37
111
|
], 2);
|
|
38
112
|
expect(result).toEqual([
|
|
39
|
-
'https://
|
|
40
|
-
'https://pcpubliccms.jd.com/image2.avif?x=1',
|
|
113
|
+
'https://img10.360buyimg.com/imgzone/jfs/t1/detail.avif',
|
|
41
114
|
]);
|
|
42
115
|
});
|
|
116
|
+
it('treats WareGraphic sku images as detail images only for WareGraphic fallback', () => {
|
|
117
|
+
expect(__test__.isJdDetailImage('https://img10.360buyimg.com/sku/jfs/t1/color-option.gif')).toBe(false);
|
|
118
|
+
expect(__test__.isJdWareGraphicDetailImage('https://img10.360buyimg.com/sku/jfs/t1/ware-graphic.jpg')).toBe(true);
|
|
119
|
+
expect(__test__.isJdWareGraphicDetailImage('https://img10.360buyimg.com/sku/s228x228_jfs/t1/thumb.jpg')).toBe(false);
|
|
120
|
+
});
|
|
121
|
+
it('keeps main gallery images while ignoring unrelated contexts for detail images', () => {
|
|
122
|
+
const dom = new JSDOM(`
|
|
123
|
+
<div class="_gallery_116km_1">
|
|
124
|
+
<img src="https://img10.360buyimg.com/pcpubliccms/jfs/t1/main-a.jpg" />
|
|
125
|
+
<img data-src="//img10.360buyimg.com/n1/jfs/t1/main-b.jpg" />
|
|
126
|
+
</div>
|
|
127
|
+
<div class="recommend">
|
|
128
|
+
<img src="https://img10.360buyimg.com/imgzone/jfs/t1/recommend.jpg.avif" />
|
|
129
|
+
</div>
|
|
130
|
+
<div class="detail-content-wrap">
|
|
131
|
+
<img src="https://img10.360buyimg.com/imgzone/jfs/t1/detail-a.jpg.avif" />
|
|
132
|
+
</div>
|
|
133
|
+
`);
|
|
134
|
+
const previousDocument = globalThis.document;
|
|
135
|
+
globalThis.document = dom.window.document;
|
|
136
|
+
try {
|
|
137
|
+
expect(__test__.extractMainImages(10)).toEqual([
|
|
138
|
+
'https://img10.360buyimg.com/pcpubliccms/jfs/t1/main-a.jpg',
|
|
139
|
+
'https://img10.360buyimg.com/n1/jfs/t1/main-b.jpg',
|
|
140
|
+
]);
|
|
141
|
+
expect(__test__.extractDetailImagesFromDom(10)).toEqual([
|
|
142
|
+
'https://img10.360buyimg.com/imgzone/jfs/t1/detail-a.jpg.avif',
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
globalThis.document = previousDocument;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
it('collects JD detail images from computed background images', () => {
|
|
150
|
+
const dom = new JSDOM(`
|
|
151
|
+
<div id="J-detail">
|
|
152
|
+
<div class="ssd-module computed-bg"></div>
|
|
153
|
+
<div class="ssd-module ignored-bg"></div>
|
|
154
|
+
</div>
|
|
155
|
+
`);
|
|
156
|
+
const previousDocument = globalThis.document;
|
|
157
|
+
const previousGetComputedStyle = globalThis.getComputedStyle;
|
|
158
|
+
globalThis.document = dom.window.document;
|
|
159
|
+
globalThis.getComputedStyle = ((element) => ({
|
|
160
|
+
background: '',
|
|
161
|
+
backgroundImage: element.classList.contains('computed-bg')
|
|
162
|
+
? 'url("//img10.360buyimg.com/imgzone/jfs/t1/computed-detail.jpg.avif")'
|
|
163
|
+
: 'none',
|
|
164
|
+
}));
|
|
165
|
+
try {
|
|
166
|
+
expect(__test__.extractDetailImagesFromDom(10)).toEqual([
|
|
167
|
+
'https://img10.360buyimg.com/imgzone/jfs/t1/computed-detail.jpg.avif',
|
|
168
|
+
]);
|
|
169
|
+
}
|
|
170
|
+
finally {
|
|
171
|
+
globalThis.document = previousDocument;
|
|
172
|
+
globalThis.getComputedStyle = previousGetComputedStyle;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
it('collects JD detail images from inline JSON-like script text', () => {
|
|
176
|
+
const dom = new JSDOM(`
|
|
177
|
+
<h2 id="SPXQ-title">商品详情</h2>
|
|
178
|
+
<script>
|
|
179
|
+
window.__DETAIL_DATA__ = {
|
|
180
|
+
images: [
|
|
181
|
+
"https://img10.360buyimg.com/imgzone/jfs/t1/script-detail-a.jpg.avif",
|
|
182
|
+
"//img11.360buyimg.com/imgzone/jfs/t1/script-detail-b.gif"
|
|
183
|
+
]
|
|
184
|
+
};
|
|
185
|
+
</script>
|
|
186
|
+
`);
|
|
187
|
+
const previousDocument = globalThis.document;
|
|
188
|
+
globalThis.document = dom.window.document;
|
|
189
|
+
try {
|
|
190
|
+
expect(__test__.extractDetailImagesFromDom(10)).toEqual([
|
|
191
|
+
'https://img10.360buyimg.com/imgzone/jfs/t1/script-detail-a.jpg.avif',
|
|
192
|
+
'https://img11.360buyimg.com/imgzone/jfs/t1/script-detail-b.gif',
|
|
193
|
+
]);
|
|
194
|
+
}
|
|
195
|
+
finally {
|
|
196
|
+
globalThis.document = previousDocument;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
it('collects JD detail images from same-origin iframe content', () => {
|
|
200
|
+
const dom = new JSDOM(`
|
|
201
|
+
<h2 id="SPXQ-title">商品详情</h2>
|
|
202
|
+
<iframe id="detail-frame"></iframe>
|
|
203
|
+
`, { url: 'https://item.jd.com/100328272886.html' });
|
|
204
|
+
const frameDom = new JSDOM(`
|
|
205
|
+
<div id="J-detail">
|
|
206
|
+
<img src="https://img10.360buyimg.com/imgzone/jfs/t1/frame-detail-a.jpg.avif" />
|
|
207
|
+
<div style="background-image:url(//img11.360buyimg.com/cms/jfs/t1/frame-detail-b.jpg.avif)"></div>
|
|
208
|
+
</div>
|
|
209
|
+
`, { url: 'https://item.jd.com/detail-frame.html' });
|
|
210
|
+
const iframe = dom.window.document.getElementById('detail-frame');
|
|
211
|
+
Object.defineProperty(iframe, 'contentDocument', { value: frameDom.window.document, configurable: true });
|
|
212
|
+
Object.defineProperty(iframe, 'contentWindow', { value: frameDom.window, configurable: true });
|
|
213
|
+
const previousDocument = globalThis.document;
|
|
214
|
+
globalThis.document = dom.window.document;
|
|
215
|
+
try {
|
|
216
|
+
expect(__test__.extractDetailImagesFromDom(10)).toEqual([
|
|
217
|
+
'https://img10.360buyimg.com/imgzone/jfs/t1/frame-detail-a.jpg.avif',
|
|
218
|
+
'https://img11.360buyimg.com/cms/jfs/t1/frame-detail-b.jpg.avif',
|
|
219
|
+
]);
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
globalThis.document = previousDocument;
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
it('collects JD detail images from page data objects', async () => {
|
|
226
|
+
const dom = new JSDOM(`
|
|
227
|
+
<h2 id="SPXQ-title">商品详情</h2>
|
|
228
|
+
`);
|
|
229
|
+
globalThis.document = dom.window.document;
|
|
230
|
+
globalThis.window = dom.window;
|
|
231
|
+
globalThis.__PAGE_DATA__ = {
|
|
232
|
+
detail: {
|
|
233
|
+
images: [
|
|
234
|
+
'https://img10.360buyimg.com/imgzone/jfs/t1/page-data-a.jpg.avif',
|
|
235
|
+
{ src: '//img11.360buyimg.com/imgzone/jfs/t1/page-data-b.webp' },
|
|
236
|
+
],
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
try {
|
|
240
|
+
await expect(__test__.extractDetailImagesFromPage(10)).resolves.toEqual([
|
|
241
|
+
'https://img10.360buyimg.com/imgzone/jfs/t1/page-data-a.jpg.avif',
|
|
242
|
+
'https://img11.360buyimg.com/imgzone/jfs/t1/page-data-b.webp',
|
|
243
|
+
]);
|
|
244
|
+
}
|
|
245
|
+
finally {
|
|
246
|
+
delete globalThis.__PAGE_DATA__;
|
|
247
|
+
restoreGlobals();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
it('collects JD detail images from network resource text', async () => {
|
|
251
|
+
const dom = new JSDOM(`
|
|
252
|
+
<h2 id="SPXQ-title">商品详情</h2>
|
|
253
|
+
`);
|
|
254
|
+
const previousFetch = globalThis.fetch;
|
|
255
|
+
globalThis.document = dom.window.document;
|
|
256
|
+
globalThis.window = dom.window;
|
|
257
|
+
globalThis.performance = {
|
|
258
|
+
getEntriesByType: () => [{ name: 'https://cdn.jd.com/detail/data.json' }],
|
|
259
|
+
now: () => 0,
|
|
260
|
+
};
|
|
261
|
+
globalThis.fetch = (async () => ({
|
|
262
|
+
ok: true,
|
|
263
|
+
headers: { get: () => 'application/json' },
|
|
264
|
+
text: async () => JSON.stringify({
|
|
265
|
+
detail: {
|
|
266
|
+
imgs: ['https://img10.360buyimg.com/imgzone/jfs/t1/network-detail-a.jpg.avif'],
|
|
267
|
+
},
|
|
268
|
+
}),
|
|
269
|
+
}));
|
|
270
|
+
try {
|
|
271
|
+
await expect(__test__.extractDetailImagesFromPage(10)).resolves.toEqual([
|
|
272
|
+
'https://img10.360buyimg.com/imgzone/jfs/t1/network-detail-a.jpg.avif',
|
|
273
|
+
]);
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
globalThis.fetch = previousFetch;
|
|
277
|
+
restoreGlobals();
|
|
278
|
+
}
|
|
279
|
+
});
|
|
280
|
+
it('collects JD detail images from WareGraphic graphicContent', async () => {
|
|
281
|
+
const dom = new JSDOM(`
|
|
282
|
+
<h2 id="SPXQ-title">商品详情</h2>
|
|
283
|
+
`);
|
|
284
|
+
const previousFetch = globalThis.fetch;
|
|
285
|
+
globalThis.document = dom.window.document;
|
|
286
|
+
globalThis.window = dom.window;
|
|
287
|
+
globalThis.performance = {
|
|
288
|
+
getEntriesByType: () => [
|
|
289
|
+
{ name: 'https://api.m.jd.com/client.action?functionId=pc_item_getWareGraphic&skuId=100328272886' },
|
|
290
|
+
],
|
|
291
|
+
now: () => 0,
|
|
292
|
+
};
|
|
293
|
+
globalThis.fetch = (async () => ({
|
|
294
|
+
ok: true,
|
|
295
|
+
headers: { get: () => 'application/json' },
|
|
296
|
+
text: async () => JSON.stringify({
|
|
297
|
+
data: {
|
|
298
|
+
graphicContent: `
|
|
299
|
+
<div style="background-image:url(//img30.360buyimg.com/sku/jfs/t1/ware-a.jpg)"></div>
|
|
300
|
+
<img src="https://img30.360buyimg.com/sku/jfs/t1/ware-b.png" />
|
|
301
|
+
<a href="https://item.jd.com/100328272886.html">not image</a>
|
|
302
|
+
`,
|
|
303
|
+
},
|
|
304
|
+
}),
|
|
305
|
+
}));
|
|
306
|
+
try {
|
|
307
|
+
await expect(__test__.extractDetailImagesFromPage(10)).resolves.toEqual([
|
|
308
|
+
'https://img30.360buyimg.com/sku/jfs/t1/ware-a.jpg',
|
|
309
|
+
'https://img30.360buyimg.com/sku/jfs/t1/ware-b.png',
|
|
310
|
+
]);
|
|
311
|
+
}
|
|
312
|
+
finally {
|
|
313
|
+
globalThis.fetch = previousFetch;
|
|
314
|
+
restoreGlobals();
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
it('extracts selected specs from the newer JD spec-list DOM', () => {
|
|
318
|
+
const dom = new JSDOM(`
|
|
319
|
+
<div id="spec-list" class="page-right-spec">
|
|
320
|
+
<div class="horizontal-layout specification-series-layout">
|
|
321
|
+
<div class="layout-label">系列品</div>
|
|
322
|
+
<div class="layout-content">
|
|
323
|
+
<div class="specification-series-item specification-series-item--selected">
|
|
324
|
+
<span class="specification-series-item-text">【年度新品】玉兔3.0pro 12kg</span>
|
|
325
|
+
</div>
|
|
326
|
+
<div class="specification-series-item"><span class="specification-series-item-text">其他系列</span></div>
|
|
327
|
+
</div>
|
|
328
|
+
</div>
|
|
329
|
+
<div class="specifications-panel-content">
|
|
330
|
+
<div class="specification-group">
|
|
331
|
+
<div class="specification-group-label">款式</div>
|
|
332
|
+
<div class="specification-group-content">
|
|
333
|
+
<div class="specification-item-sku has-image specification-item-sku--selected" title="">
|
|
334
|
+
<img class="specification-item-sku-image" alt="洗烘套装" src="https://img13.360buyimg.com/pcpubliccms/s48x48_jfs/t1/spec.jpg.avif" />
|
|
335
|
+
<span class="specification-item-sku-text">洗烘套装</span>
|
|
336
|
+
</div>
|
|
337
|
+
<div class="specification-item-sku has-image"><span class="specification-item-sku-text">滚筒单洗</span></div>
|
|
338
|
+
</div>
|
|
339
|
+
</div>
|
|
340
|
+
</div>
|
|
341
|
+
</div>
|
|
342
|
+
`);
|
|
343
|
+
globalThis.document = dom.window.document;
|
|
344
|
+
try {
|
|
345
|
+
expect(__test__.extractSpecs()).toEqual({
|
|
346
|
+
系列品: '【年度新品】玉兔3.0pro 12kg',
|
|
347
|
+
款式: '洗烘套装',
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
finally {
|
|
351
|
+
restoreGlobals();
|
|
352
|
+
}
|
|
353
|
+
});
|
|
43
354
|
});
|