Skip to content

Commit 7aafd4a

Browse files
authored
fix(tests): update mocks for resolveBvid and Windows platform guards (#749)
- bilibili subtitle/comments tests: use importOriginal to include resolveBvid in utils mock - comments test: use valid BV ID format for aid-resolution error test - launcher test: skip pgrep test on win32 (detectProcess early-returns)
1 parent a5abd37 commit 7aafd4a

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

src/clis/bilibili/comments.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ const { mockApiGet } = vi.hoisted(() => ({
44
mockApiGet: vi.fn(),
55
}));
66

7-
vi.mock('./utils.js', () => ({
7+
vi.mock('./utils.js', async (importOriginal) => ({
8+
...(await importOriginal<typeof import('./utils.js')>()),
89
apiGet: mockApiGet,
910
}));
1011

@@ -58,8 +59,8 @@ describe('bilibili comments', () => {
5859
it('throws when aid cannot be resolved', async () => {
5960
mockApiGet.mockResolvedValueOnce({ data: {} }); // no aid
6061

61-
await expect(command!.func!({} as any, { bvid: 'BV_invalid', limit: 5 })).rejects.toThrow(
62-
'Cannot resolve aid for bvid: BV_invalid',
62+
await expect(command!.func!({} as any, { bvid: 'BVinvalid123', limit: 5 })).rejects.toThrow(
63+
'Cannot resolve aid for bvid: BVinvalid123',
6364
);
6465
});
6566

src/clis/bilibili/subtitle.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const { mockApiGet } = vi.hoisted(() => ({
66
mockApiGet: vi.fn(),
77
}));
88

9-
vi.mock('./utils.js', () => ({
9+
vi.mock('./utils.js', async (importOriginal) => ({
10+
...(await importOriginal<typeof import('./utils.js')>()),
1011
apiGet: mockApiGet,
1112
}));
1213

src/launcher.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ describe('detectProcess', () => {
3434
expect(result).toBe(false);
3535
});
3636

37-
it('returns true when pgrep finds a process', () => {
37+
it.skipIf(process.platform === 'win32')('returns true when pgrep finds a process', () => {
3838
cp.execFileSync.mockReturnValue('12345\n');
3939
const result = detectProcess('Cursor');
4040
expect(result).toBe(true);

0 commit comments

Comments
 (0)