fix: suppress unnecessary output during test execution

This commit is contained in:
Naoki Oketani
2025-05-07 11:18:01 +00:00
parent 57f2b64786
commit 0ac2be2860
3 changed files with 19 additions and 0 deletions

15
__fixtures__/core.ts Normal file
View File

@@ -0,0 +1,15 @@
import type * as core from '@actions/core'
import { vi } from 'vitest'
export const debug = vi.fn<typeof core.debug>()
export const error = vi.fn<typeof core.error>()
export const info = vi.fn<typeof core.info>()
export const getInput = vi
.fn<typeof core.getInput>()
.mockImplementation((name, options) => {
const key = `INPUT_${name.replace(/ /g, '_').toUpperCase()}`
return process.env[key] || ''
})
export const setOutput = vi.fn<typeof core.setOutput>()
export const setFailed = vi.fn<typeof core.setFailed>()
export const warning = vi.fn<typeof core.warning>()

View File

@@ -1,5 +1,6 @@
import * as fs from 'fs' import * as fs from 'fs'
import * as path from 'path' import * as path from 'path'
import * as core from '../__fixtures__/core'
import { Audit } from '../src/audit' import { Audit } from '../src/audit'
import { run } from '../src/main' import { run } from '../src/main'
import * as issue from '../src/issue' import * as issue from '../src/issue'
@@ -10,6 +11,8 @@ import { dirname } from 'path'
const __filename = fileURLToPath(import.meta.url) const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename) const __dirname = dirname(__filename)
// Mocks should be declared before the module being tested is imported.
vi.mock('@actions/core', () => core)
vi.mock('../src/audit') vi.mock('../src/audit')
vi.mock('../src/issue') vi.mock('../src/issue')
vi.mock('../src/pr') vi.mock('../src/pr')

View File

@@ -7,6 +7,7 @@
}, },
"exclude": ["dist", "node_modules"], "exclude": ["dist", "node_modules"],
"include": [ "include": [
"__fixtures__",
"__tests__", "__tests__",
"src", "src",
"eslint.config.mjs", "eslint.config.mjs",