|
1 | 1 | import path from 'node:path'
|
2 | 2 | import fs from 'node:fs'
|
| 3 | +import * as core from '@actions/core' |
| 4 | +import * as exec from '@actions/exec' |
| 5 | +import * as github from '@actions/github' |
3 | 6 | import { opendir, access } from 'node:fs/promises'
|
4 | 7 | import { setBinpath } from '../src/command'
|
| 8 | +import { onExit } from '../src/diagnostics' |
| 9 | +import { httpClient } from '../src/config' |
5 | 10 | import { install as installBuildless } from '../src/main'
|
6 | 11 |
|
7 | 12 | /**
|
@@ -64,3 +69,55 @@ export async function withTestBinary<R>(
|
64 | 69 | setBinpath(binpath)
|
65 | 70 | return await fn(binpath)
|
66 | 71 | }
|
| 72 | + |
| 73 | +export function resetState() { |
| 74 | + onExit(false) |
| 75 | +} |
| 76 | + |
| 77 | +export function setupCoreMocks(): { |
| 78 | + debugMock: jest.SpyInstance, |
| 79 | + errorMock: jest.SpyInstance, |
| 80 | + getInputMock: jest.SpyInstance, |
| 81 | + setFailedMock: jest.SpyInstance, |
| 82 | + setOutputMock: jest.SpyInstance, |
| 83 | + getJsonMock: jest.SpyInstance, |
| 84 | + getOctokitMock: jest.SpyInstance, |
| 85 | + execMock: jest.SpyInstance, |
| 86 | + clearMocks: () => void, |
| 87 | + setupMocks: () => void, |
| 88 | + resetState: () => void, |
| 89 | +} { |
| 90 | + let debugMock: jest.SpyInstance = jest.spyOn(core, 'debug') |
| 91 | + let errorMock: jest.SpyInstance = jest.spyOn(core, 'error') |
| 92 | + let getInputMock: jest.SpyInstance = jest.spyOn(core, 'getInput') |
| 93 | + let setFailedMock: jest.SpyInstance = jest.spyOn(core, 'setFailed') |
| 94 | + let setOutputMock: jest.SpyInstance = jest.spyOn(core, 'setOutput') |
| 95 | + let execMock: jest.SpyInstance = jest.spyOn(exec, 'exec') |
| 96 | + let getOctokitMock: jest.SpyInstance = jest.spyOn(github, 'getOctokit').mockImplementation() |
| 97 | + let getJsonMock: jest.SpyInstance = jest.spyOn(httpClient, 'getJson').mockImplementation() |
| 98 | + |
| 99 | + return { |
| 100 | + debugMock, |
| 101 | + errorMock, |
| 102 | + getInputMock, |
| 103 | + setFailedMock, |
| 104 | + setOutputMock, |
| 105 | + getJsonMock, |
| 106 | + getOctokitMock, |
| 107 | + execMock, |
| 108 | + resetState: () => { |
| 109 | + resetState() |
| 110 | + }, |
| 111 | + clearMocks: () => { |
| 112 | + // Nothing at this time. |
| 113 | + }, |
| 114 | + setupMocks: () => { |
| 115 | + execMock = jest.spyOn(exec, 'exec').mockImplementation() |
| 116 | + debugMock = jest.spyOn(core, 'debug').mockImplementation() |
| 117 | + errorMock = jest.spyOn(core, 'error').mockImplementation() |
| 118 | + getInputMock = jest.spyOn(core, 'getInput').mockImplementation() |
| 119 | + setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() |
| 120 | + setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() |
| 121 | + }, |
| 122 | + } |
| 123 | +} |
0 commit comments