javdict 1.3.2 → 1.3.3
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/.github/workflows/ci.yml +5 -5
- package/package.json +1 -1
- package/test/fetcher.test.js +32 -4
- package/vitest.config.js +9 -0
package/.github/workflows/ci.yml
CHANGED
|
@@ -12,7 +12,7 @@ jobs:
|
|
|
12
12
|
|
|
13
13
|
strategy:
|
|
14
14
|
matrix:
|
|
15
|
-
node-version: [
|
|
15
|
+
node-version: [20.x, 22.x] # ← 只保留 20 和 22,放弃 18
|
|
16
16
|
|
|
17
17
|
steps:
|
|
18
18
|
- name: Checkout code
|
|
@@ -22,7 +22,7 @@ jobs:
|
|
|
22
22
|
uses: actions/setup-node@v4
|
|
23
23
|
with:
|
|
24
24
|
node-version: ${{ matrix.node-version }}
|
|
25
|
-
cache: 'npm'
|
|
25
|
+
cache: 'npm'
|
|
26
26
|
|
|
27
27
|
- name: Install dependencies
|
|
28
28
|
run: npm ci
|
|
@@ -30,6 +30,6 @@ jobs:
|
|
|
30
30
|
- name: Run tests
|
|
31
31
|
run: npm test
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
- name: Show detailed test output
|
|
34
|
+
if: always()
|
|
35
|
+
run: npm test -- --reporter=verbose
|
package/package.json
CHANGED
package/test/fetcher.test.js
CHANGED
|
@@ -1,12 +1,41 @@
|
|
|
1
|
+
// 为 Node 18 提供 Web API polyfill
|
|
2
|
+
import { beforeAll } from 'vitest';
|
|
3
|
+
|
|
4
|
+
beforeAll(() => {
|
|
5
|
+
if (typeof global.File === 'undefined') {
|
|
6
|
+
global.File = class File {
|
|
7
|
+
constructor(bits, name, options = {}) {
|
|
8
|
+
this.bits = bits;
|
|
9
|
+
this.name = name;
|
|
10
|
+
this.type = options.type || '';
|
|
11
|
+
this.size = bits?.length || 0;
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof global.FormData === 'undefined') {
|
|
17
|
+
global.FormData = class FormData {
|
|
18
|
+
constructor() {
|
|
19
|
+
this.data = new Map();
|
|
20
|
+
}
|
|
21
|
+
append(key, value) {
|
|
22
|
+
this.data.set(key, value);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// =====================================================
|
|
29
|
+
|
|
1
30
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
31
|
|
|
3
|
-
//
|
|
32
|
+
// Mock child_process
|
|
4
33
|
vi.mock('child_process', () => ({
|
|
5
34
|
execSync: vi.fn(),
|
|
6
35
|
spawnSync: vi.fn(),
|
|
7
36
|
}));
|
|
8
37
|
|
|
9
|
-
//
|
|
38
|
+
// Mock cache
|
|
10
39
|
vi.mock('../lib/cache.js', () => ({
|
|
11
40
|
getCache: vi.fn().mockReturnValue(null),
|
|
12
41
|
setCache: vi.fn(),
|
|
@@ -16,7 +45,7 @@ vi.mock('../lib/cache.js', () => ({
|
|
|
16
45
|
import { execSync } from 'child_process';
|
|
17
46
|
import { search } from '../lib/fetcher.js';
|
|
18
47
|
|
|
19
|
-
// 模拟
|
|
48
|
+
// 模拟 HTML 数据
|
|
20
49
|
const MOCK_JAVBUS_HTML = `
|
|
21
50
|
<html>
|
|
22
51
|
<head><title>SSIS-001</title></head>
|
|
@@ -44,7 +73,6 @@ const MOCK_JAVBUS_HTML = `
|
|
|
44
73
|
</html>
|
|
45
74
|
`;
|
|
46
75
|
|
|
47
|
-
// 模拟 404 页面
|
|
48
76
|
const MOCK_404_HTML = `
|
|
49
77
|
<html>
|
|
50
78
|
<head><title>404</title></head>
|