diff --git a/__tests__/setupQuietActionsCore.ts b/__tests__/setupQuietActionsCore.ts new file mode 100644 index 00000000..53136ee7 --- /dev/null +++ b/__tests__/setupQuietActionsCore.ts @@ -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(() => {}) +}) diff --git a/vitest.config.mjs b/vitest.config.mjs index 998045b5..52c1bf50 100644 --- a/vitest.config.mjs +++ b/vitest.config.mjs @@ -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