Skip to content

Commit 8c58cf4

Browse files
committed
Fix GitHub tests to mock httpRequest correctly
Update mock configuration to use vi.fn() directly in factory and import from source files. Resolves vitest hoisting issues with CommonJS compiled output.
1 parent 21947ea commit 8c58cf4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

test/registry/github.test.mts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,22 @@ import path from 'node:path'
55
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
66

77
// Mock the httpRequest module before importing github module.
8-
const mockHttpRequest = vi.fn()
9-
vi.mock('../../registry/dist/lib/http-request', () => ({
10-
httpRequest: mockHttpRequest,
11-
}))
8+
vi.mock('../../registry/src/lib/http-request', () => {
9+
return {
10+
httpRequest: vi.fn(),
11+
}
12+
})
1213

1314
import {
1415
clearRefCache,
1516
fetchGitHub,
1617
getGitHubToken,
1718
getRefCacheSize,
1819
resolveRefToSha,
19-
} from '../../registry/dist/lib/github'
20+
} from '../../registry/src/lib/github'
21+
import { httpRequest as httpRequestActual } from '../../registry/src/lib/http-request'
2022

21-
const httpRequest = mockHttpRequest
23+
const httpRequest = httpRequestActual as unknown as ReturnType<typeof vi.fn>
2224

2325
describe('github module', () => {
2426
let originalEnv: NodeJS.ProcessEnv

0 commit comments

Comments
 (0)