CrazyMax f939b4c816
test: stabilize context test fixtures and github mock setup since ESM
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
2026-03-03 18:38:14 +01:00

40 lines
982 B
TypeScript

import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import {vi} from 'vitest';
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'docker-build-push-action-'));
const githubPayload = {
repository: {
private: true
}
};
const githubEventPath = path.join(tmpDir, 'github-event.json');
fs.writeFileSync(githubEventPath, JSON.stringify(githubPayload));
process.env = Object.assign({}, process.env, {
TEMP: tmpDir,
GITHUB_REPOSITORY: 'docker/build-push-action',
GITHUB_REF: 'refs/heads/master',
GITHUB_RUN_ID: '123456789',
GITHUB_RUN_ATTEMPT: '1',
GITHUB_EVENT_PATH: githubEventPath,
RUNNER_TEMP: path.join(tmpDir, 'runner-temp'),
RUNNER_TOOL_CACHE: path.join(tmpDir, 'runner-tool-cache')
});
vi.mock('@actions/github', () => ({
context: {
repo: {
owner: 'docker',
repo: 'build-push-action'
},
ref: 'refs/heads/master',
runId: 123456789,
payload: githubPayload
},
getOctokit: vi.fn()
}));