javdict 1.2.4 → 1.2.6
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/LICENSE +21 -0
- package/package.json +1 -1
- package/test/display.test.js +1 -4
- package/test/fetcher.test.js +53 -52
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 gdjdkid
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
package/test/display.test.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
1
|
+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
2
|
import { display } from '../lib/display.js';
|
|
3
3
|
|
|
4
|
-
// 完整的 mock 数据
|
|
5
4
|
const MOCK_INFO = {
|
|
6
5
|
id: 'SSIS-001',
|
|
7
6
|
title: '测试标题',
|
|
@@ -20,7 +19,6 @@ const MOCK_INFO = {
|
|
|
20
19
|
|
|
21
20
|
describe('display.js', () => {
|
|
22
21
|
beforeEach(() => {
|
|
23
|
-
// 拦截 console.log,不真正打印,但可以断言调用内容
|
|
24
22
|
vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
25
23
|
});
|
|
26
24
|
|
|
@@ -47,7 +45,6 @@ describe('display.js', () => {
|
|
|
47
45
|
it('display:raw 模式输出 JSON 字符串', () => {
|
|
48
46
|
display(MOCK_INFO, true);
|
|
49
47
|
const allOutput = console.log.mock.calls.flat().join(' ');
|
|
50
|
-
// raw 模式应该输出可解析的 JSON
|
|
51
48
|
expect(() => JSON.parse(allOutput)).not.toThrow();
|
|
52
49
|
});
|
|
53
50
|
|
package/test/fetcher.test.js
CHANGED
|
@@ -1,49 +1,55 @@
|
|
|
1
1
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
2
|
|
|
3
|
-
// mock
|
|
4
|
-
vi.mock('
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
},
|
|
3
|
+
// mock execSync,避免真实的 curl 网络请求
|
|
4
|
+
vi.mock('child_process', () => ({
|
|
5
|
+
execSync: vi.fn(),
|
|
6
|
+
spawnSync: vi.fn(),
|
|
8
7
|
}));
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
// mock cache,避免缓存干扰测试结果
|
|
10
|
+
vi.mock('../lib/cache.js', () => ({
|
|
11
|
+
getCache: vi.fn().mockReturnValue(null),
|
|
12
|
+
setCache: vi.fn(),
|
|
13
|
+
getConfig: vi.fn().mockReturnValue({ session: 'mock_session' }),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
import { execSync } from 'child_process';
|
|
11
17
|
import { search } from '../lib/fetcher.js';
|
|
12
18
|
|
|
13
|
-
//
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
// 模拟 JAVBUS 详情页 HTML
|
|
20
|
+
const MOCK_JAVBUS_HTML = `
|
|
21
|
+
<html>
|
|
22
|
+
<head><title>SSIS-001</title></head>
|
|
23
|
+
<body>
|
|
24
|
+
<div class="container">
|
|
25
|
+
<div class="row">
|
|
26
|
+
<h3>SSIS-001 测试标题</h3>
|
|
27
|
+
<div class="screencap">
|
|
28
|
+
<img src="https://example.com/cover.jpg" />
|
|
29
|
+
</div>
|
|
30
|
+
<div class="info">
|
|
31
|
+
<p><span class="header">發行日期:</span> 2021-01-01</p>
|
|
32
|
+
<p><span class="header">長度:</span> 150分鐘</p>
|
|
33
|
+
<p><span class="header">導演:</span> <a>导演A</a></p>
|
|
34
|
+
<p><span class="header">製作商:</span> <a>SOD Create</a></p>
|
|
35
|
+
<p><span class="header">發行商:</span> <a>SOD</a></p>
|
|
36
|
+
<p><span class="header">系列:</span> <a>系列A</a></p>
|
|
37
|
+
</div>
|
|
38
|
+
<span class="genre"><a>独占</a></span>
|
|
39
|
+
<span class="genre"><a>美少女</a></span>
|
|
40
|
+
<div class="star-name"><a>天使もえ</a></div>
|
|
41
|
+
</div>
|
|
20
42
|
</div>
|
|
21
|
-
</
|
|
43
|
+
</body>
|
|
44
|
+
</html>
|
|
22
45
|
`;
|
|
23
46
|
|
|
24
|
-
//
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
<
|
|
28
|
-
<
|
|
29
|
-
|
|
30
|
-
<div class="panel-block">
|
|
31
|
-
<strong>日期:</strong>
|
|
32
|
-
<span class="value">2021-01-01</span>
|
|
33
|
-
</div>
|
|
34
|
-
<div class="panel-block">
|
|
35
|
-
<strong>演員:</strong>
|
|
36
|
-
<span class="value"><a>天使もえ</a></span>
|
|
37
|
-
</div>
|
|
38
|
-
<div class="panel-block">
|
|
39
|
-
<strong>片商:</strong>
|
|
40
|
-
<span class="value">SOD Create</span>
|
|
41
|
-
</div>
|
|
42
|
-
<div class="panel-block">
|
|
43
|
-
<strong>時長:</strong>
|
|
44
|
-
<span class="value">120分钟</span>
|
|
45
|
-
</div>
|
|
46
|
-
</div>
|
|
47
|
+
// 模拟 404 页面
|
|
48
|
+
const MOCK_404_HTML = `
|
|
49
|
+
<html>
|
|
50
|
+
<head><title>404</title></head>
|
|
51
|
+
<body></body>
|
|
52
|
+
</html>
|
|
47
53
|
`;
|
|
48
54
|
|
|
49
55
|
describe('fetcher.js', () => {
|
|
@@ -52,41 +58,36 @@ describe('fetcher.js', () => {
|
|
|
52
58
|
});
|
|
53
59
|
|
|
54
60
|
it('search:正常番号能返回结构完整的对象', async () => {
|
|
55
|
-
|
|
56
|
-
axios.get
|
|
57
|
-
.mockResolvedValueOnce({ data: MOCK_SEARCH_HTML })
|
|
58
|
-
.mockResolvedValueOnce({ data: MOCK_DETAIL_HTML });
|
|
61
|
+
execSync.mockReturnValue(Buffer.from(MOCK_JAVBUS_HTML));
|
|
59
62
|
|
|
60
63
|
const result = await search('SSIS-001');
|
|
61
64
|
|
|
62
65
|
expect(result).not.toBeNull();
|
|
63
66
|
expect(result.id).toBe('SSIS-001');
|
|
64
|
-
expect(result.
|
|
67
|
+
expect(result.source).toBe('JAVBUS');
|
|
65
68
|
expect(result.actresses).toContain('天使もえ');
|
|
66
69
|
expect(result.releaseDate).toBe('2021-01-01');
|
|
67
70
|
expect(result.studio).toBe('SOD Create');
|
|
68
|
-
expect(result.duration).toBe('120分钟');
|
|
69
|
-
expect(result.coverUrl).toBe('https://example.com/cover.jpg');
|
|
70
71
|
});
|
|
71
72
|
|
|
72
73
|
it('search:搜索结果为空时返回 null', async () => {
|
|
73
|
-
|
|
74
|
-
axios.get.mockResolvedValueOnce({ data: '<div class="movie-list"></div>' });
|
|
74
|
+
execSync.mockReturnValue(Buffer.from(MOCK_404_HTML));
|
|
75
75
|
|
|
76
76
|
const result = await search('INVALID-999');
|
|
77
77
|
expect(result).toBeNull();
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
-
it('search
|
|
81
|
-
|
|
80
|
+
it('search:网络请求失败时返回 null', async () => {
|
|
81
|
+
execSync.mockImplementation(() => {
|
|
82
|
+
throw new Error('Network Error');
|
|
83
|
+
});
|
|
82
84
|
|
|
83
|
-
await
|
|
85
|
+
const result = await search('SSIS-001');
|
|
86
|
+
expect(result).toBeNull();
|
|
84
87
|
});
|
|
85
88
|
|
|
86
89
|
it('search:返回对象包含所有预期字段', async () => {
|
|
87
|
-
|
|
88
|
-
.mockResolvedValueOnce({ data: MOCK_SEARCH_HTML })
|
|
89
|
-
.mockResolvedValueOnce({ data: MOCK_DETAIL_HTML });
|
|
90
|
+
execSync.mockReturnValue(Buffer.from(MOCK_JAVBUS_HTML));
|
|
90
91
|
|
|
91
92
|
const result = await search('SSIS-001');
|
|
92
93
|
const expectedFields = [
|