Improve code coverage for cli package (#13724)

This commit is contained in:
Megha Bansal
2025-11-24 23:11:46 +05:30
committed by GitHub
parent 569c6f1dd0
commit 95693e265e
47 changed files with 5115 additions and 489 deletions

View File

@@ -0,0 +1,41 @@
/**
* @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);
});
});
});