diff --git a/__tests__/github/github.test.itg.ts b/__tests__/github/github.test.itg.ts new file mode 100644 index 0000000..8c0baa4 --- /dev/null +++ b/__tests__/github/github.test.itg.ts @@ -0,0 +1,41 @@ +/** + * Copyright 2026 actions-toolkit authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {describe, expect, it} from 'vitest'; + +import {GitHub} from '../../src/github/github.js'; + +describe('repoData', () => { + it('returns docker/actions-toolkit', async () => { + if (!process.env.GITHUB_TOKEN) { + console.log(`GitHub token not available, skipping test`); + return; + } + const originalEnv = process.env; + process.env = { + ...originalEnv, + GITHUB_REPOSITORY: 'docker/actions-toolkit' + }; + try { + const github = new GitHub({token: process.env.GITHUB_TOKEN}); + const repo = await github.repoData(); + const fullName = repo.full_name ?? `${repo.owner?.login}/${repo.name}`; + expect(fullName).toEqual('docker/actions-toolkit'); + } finally { + process.env = originalEnv; + } + }); +}); diff --git a/__tests__/github/github.test.ts b/__tests__/github/github.test.ts index 9610d47..61b6d56 100644 --- a/__tests__/github/github.test.ts +++ b/__tests__/github/github.test.ts @@ -26,6 +26,14 @@ import repoFixture from '../.fixtures/github-repo.json' with {type: 'json'}; const fixturesDir = path.join(__dirname, '..', '.fixtures'); +vi.mock('@actions/core', async () => { + const actual = await vi.importActual('@actions/core'); + return { + ...actual, + info: vi.fn() + }; +}); + describe('repoData', () => { it('returns GitHub repo data', async () => { vi.spyOn(GitHub.prototype, 'repoData').mockImplementation((): Promise => { @@ -36,32 +44,6 @@ describe('repoData', () => { }); }); -describe('repoData (api)', () => { - it('returns docker/actions-toolkit', async () => { - if (!process.env.GITHUB_TOKEN) { - return; - } - - const originalEnv = process.env; - process.env = { - ...originalEnv, - GITHUB_REPOSITORY: 'docker/actions-toolkit' - }; - - try { - vi.resetModules(); - vi.unmock('@actions/github'); - const {GitHub} = await import('../../src/github/github.js'); - const github = new GitHub({token: process.env.GITHUB_TOKEN}); - const repo = await github.repoData(); - const fullName = repo.full_name ?? `${repo.owner?.login}/${repo.name}`; - expect(fullName).toEqual('docker/actions-toolkit'); - } finally { - process.env = originalEnv; - } - }); -}); - describe('context', () => { it('returns repository name from payload', async () => { expect(GitHub.context.payload.repository?.name).toEqual('test-docker-action'); @@ -201,7 +183,7 @@ describe('printActionsRuntimeTokenACs', () => { await expect(GitHub.printActionsRuntimeTokenACs()).rejects.toThrow(new Error('Cannot parse GitHub Actions Runtime Token: Invalid token specified: missing part #2')); }); it('refs/heads/master', async () => { - const infoSpy = vi.spyOn(core, 'info'); + const infoSpy = vi.mocked(core.info); process.env.ACTIONS_RUNTIME_TOKEN = fs.readFileSync(path.join(fixturesDir, 'runtimeToken.txt')).toString().trim(); await GitHub.printActionsRuntimeTokenACs(); expect(infoSpy).toHaveBeenCalledTimes(1);