Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions __tests__/setupQuietActionsCore.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import * as core from '@actions/core'
import { beforeEach, vi } from 'vitest'

// setup.ts mocks @actions/core with `spy: true`, so the real implementation still runs and
// its output functions write `::debug::`, `::warning::`, `::error::` and `::add-mask::`
// workflow commands straight to process.stdout (bypassing vitest's console capture).
// Under GitHub Actions the runner parses those lines: a green build-test run carried ten
// `failure` and ten `warning` annotations that were test fixtures, `::add-mask::` redacted
// fixture strings from the rest of the log, and `setFailed` set process.exitCode in the
// worker. Keep the spies — tests assert on the calls — but drop the writes. The
// implementation is reinstalled per test because `mockReset: true` restores the originals.
const outputFunctions = [
'debug',
'info',
'warning',
'error',
'notice',
'setFailed',
'setSecret',
'setOutput',
'exportVariable',
'addPath',
'saveState',
'startGroup',
'endGroup',
'setCommandEcho',
] as const

beforeEach(() => {
for (const name of outputFunctions)
vi.mocked(core[name]).mockImplementation(() => {})
})
2 changes: 1 addition & 1 deletion vitest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
environment: 'node',
include: ['__tests__/**/*.test.ts'],
globals: false,
setupFiles: ['__tests__/setup.ts'],
setupFiles: ['__tests__/setup.ts', '__tests__/setupQuietActionsCore.ts'],
globalSetup: ['__tests__/worker/globalSetup.ts'],
// Mirrors Jest's `clearMocks: true` + `resetMocks: true` + `restoreMocks: true`.
// Note: Vitest's mockReset restores a spy's original implementation (Jest 29
Expand Down
Loading