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,35 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
import * as os from 'node:os';
import * as path from 'node:path';
import { resolvePath } from './resolvePath.js';
vi.mock('node:os', () => ({
homedir: vi.fn(),
}));
describe('resolvePath', () => {
beforeEach(() => {
vi.mocked(os.homedir).mockReturnValue('/home/user');
});
it.each([
['', ''],
['/foo/bar', path.normalize('/foo/bar')],
['~/foo', path.join('/home/user', 'foo')],
['~', path.normalize('/home/user')],
['%userprofile%/foo', path.join('/home/user', 'foo')],
['%USERPROFILE%/foo', path.join('/home/user', 'foo')],
])('resolvePath(%s) should return %s', (input, expected) => {
expect(resolvePath(input)).toBe(expected);
});
it('should handle path normalization', () => {
expect(resolvePath('/foo//bar/../baz')).toBe(path.normalize('/foo/baz'));
});
});