Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/__test__/github-api-helper.test.ts
diff options
context:
space:
mode:
authorAiqiao Yan <55104035+aiqiaoy@users.noreply.github.com>2026-06-16 17:10:58 -0400
committerGitHub <noreply@github.com>2026-06-16 17:10:58 -0400
commitc68c2101c254470055e8aa38730553d71a47bc7b (patch)
tree3d9a1c982fc2d3aed23e80a58d221942ac249155 /__test__/github-api-helper.test.ts
parent6e97fb5586f435ba4f325b363a1c7329470cebf6 (diff)
upgrade module to esm and update dependencies (#2463)
* upgrade module to esm so I can update dependencies * fix ci failures
Diffstat (limited to '__test__/github-api-helper.test.ts')
-rw-r--r--__test__/github-api-helper.test.ts44
1 files changed, 29 insertions, 15 deletions
diff --git a/__test__/github-api-helper.test.ts b/__test__/github-api-helper.test.ts
index 6319e20..3470f20 100644
--- a/__test__/github-api-helper.test.ts
+++ b/__test__/github-api-helper.test.ts
@@ -1,11 +1,25 @@
-import * as core from '@actions/core'
-import * as github from '@actions/github'
-import * as githubApiHelper from '../lib/github-api-helper'
+import {jest, describe, it, expect, beforeEach, afterEach} from '@jest/globals'
+
+// Mock @actions/core
+const mockDebug = jest.fn()
+jest.unstable_mockModule('@actions/core', () => ({
+ debug: mockDebug,
+ info: jest.fn(),
+ warning: jest.fn(),
+ error: jest.fn()
+}))
+
+// Mock @actions/github
+const mockGetOctokit = jest.fn()
+jest.unstable_mockModule('@actions/github', () => ({
+ getOctokit: mockGetOctokit
+}))
+
+// Dynamic imports after mocking
+const githubApiHelper = await import('../src/github-api-helper.js')
describe('github-api-helper object format', () => {
- let getOctokitSpy: jest.SpyInstance
- let debugSpy: jest.SpyInstance
- let request: jest.Mock
+ let request: jest.Mock<any>
function mockHashAlgorithmApi(hashAlgorithm: string): void {
request = jest.fn(async () => ({
@@ -13,17 +27,18 @@ describe('github-api-helper object format', () => {
hash_algorithm: hashAlgorithm
}
}))
- getOctokitSpy = jest.spyOn(github, 'getOctokit').mockReturnValue({
+ mockGetOctokit.mockReturnValue({
request
} as any)
}
beforeEach(() => {
- debugSpy = jest.spyOn(core, 'debug').mockImplementation(jest.fn())
+ mockDebug.mockClear()
+ mockGetOctokit.mockClear()
})
afterEach(() => {
- jest.restoreAllMocks()
+ jest.clearAllMocks()
})
it('detects SHA-256 from the repository hash algorithm endpoint', async () => {
@@ -33,7 +48,7 @@ describe('github-api-helper object format', () => {
githubApiHelper.tryGetRepositoryObjectFormat('token', 'owner', 'repo')
).resolves.toEqual({format: 'sha256', succeeded: true})
- expect(getOctokitSpy).toHaveBeenCalledWith(
+ expect(mockGetOctokit).toHaveBeenCalledWith(
'token',
expect.objectContaining({baseUrl: 'https://api.github.com'})
)
@@ -54,7 +69,6 @@ describe('github-api-helper object format', () => {
it('detects object format from an existing commit without API calls', async () => {
const commitSha =
'9422233ca7ee1b17f1e905d0e141faf0c401556c41cdc6acd71c6bd685da2e92'
- getOctokitSpy = jest.spyOn(github, 'getOctokit')
await expect(
githubApiHelper.tryGetRepositoryObjectFormat(
@@ -66,7 +80,7 @@ describe('github-api-helper object format', () => {
)
).resolves.toEqual({format: 'sha256', succeeded: true})
- expect(getOctokitSpy).not.toHaveBeenCalled()
+ expect(mockGetOctokit).not.toHaveBeenCalled()
})
it('returns unsuccessful when the hash algorithm endpoint value is not recognized', async () => {
@@ -75,7 +89,7 @@ describe('github-api-helper object format', () => {
await expect(
githubApiHelper.tryGetRepositoryObjectFormat('token', 'owner', 'repo')
).resolves.toEqual({format: '', succeeded: false})
- expect(debugSpy).toHaveBeenCalledWith(
+ expect(mockDebug).toHaveBeenCalledWith(
'Unable to determine repository object format from hash-algorithm endpoint'
)
})
@@ -84,14 +98,14 @@ describe('github-api-helper object format', () => {
request = jest.fn(async () => {
throw new Error('not found')
})
- jest.spyOn(github, 'getOctokit').mockReturnValue({
+ mockGetOctokit.mockReturnValue({
request
} as any)
await expect(
githubApiHelper.tryGetRepositoryObjectFormat('token', 'owner', 'repo')
).resolves.toEqual({format: '', succeeded: false})
- expect(debugSpy).toHaveBeenCalledWith(
+ expect(mockDebug).toHaveBeenCalledWith(
'Unable to determine repository object format from hash-algorithm endpoint: not found'
)
})