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.
@@ -12,7 +12,7 @@ jobs:
12
12
 
13
13
  strategy:
14
14
  matrix:
15
- node-version: [18.x, 20.x, 22.x] # 你的项目要求 >=18,只测这三个就够
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
- # 如果你以后加了 ESLint / Prettier,可以在这里加
34
- # - name: Lint
35
- # run: npm run lint
33
+ - name: Show detailed test output
34
+ if: always()
35
+ run: npm test -- --reporter=verbose
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "javdict",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "AV番号命令行查询工具",
5
5
  "main": "./index.js",
6
6
  "type": "module",
@@ -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
- // mock execSync,避免真实的 curl 网络请求
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
- // mock cache,避免缓存干扰测试结果
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
- // 模拟 JAVBUS 详情页 HTML
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>
@@ -0,0 +1,9 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ environment: 'node',
6
+ include: ['test/**/*.test.js'],
7
+ pool: 'forks',
8
+ },
9
+ });