From 0ac2be286061011f9ee5d764370fb9cc26fca245 Mon Sep 17 00:00:00 2001 From: Naoki Oketani Date: Wed, 7 May 2025 11:18:01 +0000 Subject: [PATCH] fix: suppress unnecessary output during test execution --- __fixtures__/core.ts | 15 +++++++++++++++ __tests__/main.test.ts | 3 +++ tsconfig.eslint.json | 1 + 3 files changed, 19 insertions(+) create mode 100644 __fixtures__/core.ts diff --git a/__fixtures__/core.ts b/__fixtures__/core.ts new file mode 100644 index 0000000..6f57cd6 --- /dev/null +++ b/__fixtures__/core.ts @@ -0,0 +1,15 @@ +import type * as core from '@actions/core' +import { vi } from 'vitest' + +export const debug = vi.fn() +export const error = vi.fn() +export const info = vi.fn() +export const getInput = vi + .fn() + .mockImplementation((name, options) => { + const key = `INPUT_${name.replace(/ /g, '_').toUpperCase()}` + return process.env[key] || '' + }) +export const setOutput = vi.fn() +export const setFailed = vi.fn() +export const warning = vi.fn() diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index dc0e9ff..cb2075c 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -1,5 +1,6 @@ import * as fs from 'fs' import * as path from 'path' +import * as core from '../__fixtures__/core' import { Audit } from '../src/audit' import { run } from '../src/main' import * as issue from '../src/issue' @@ -10,6 +11,8 @@ import { dirname } from 'path' const __filename = fileURLToPath(import.meta.url) 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/issue') vi.mock('../src/pr') diff --git a/tsconfig.eslint.json b/tsconfig.eslint.json index 28ec8b4..f9d3275 100644 --- a/tsconfig.eslint.json +++ b/tsconfig.eslint.json @@ -7,6 +7,7 @@ }, "exclude": ["dist", "node_modules"], "include": [ + "__fixtures__", "__tests__", "src", "eslint.config.mjs",