File size: 1,086 Bytes
84aa3bf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | /**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { exitCli } from './utils.js';
import { runExitCleanup } from '../utils/cleanup.js';
vi.mock('../utils/cleanup.js', () => ({
runExitCleanup: vi.fn(),
}));
describe('utils', () => {
const originalProcessExit = process.exit;
beforeEach(() => {
// @ts-expect-error - Mocking process.exit
process.exit = vi.fn();
});
afterEach(() => {
process.exit = originalProcessExit;
vi.clearAllMocks();
});
describe('exitCli', () => {
it('should call runExitCleanup and process.exit with default exit code 0', async () => {
await exitCli();
expect(runExitCleanup).toHaveBeenCalled();
expect(process.exit).toHaveBeenCalledWith(0);
});
it('should call runExitCleanup and process.exit with specified exit code', async () => {
await exitCli(1);
expect(runExitCleanup).toHaveBeenCalled();
expect(process.exit).toHaveBeenCalledWith(1);
});
});
});
|