2025-08-25 17:02:10 +00:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright 2025 Google LLC
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import { describe, it, expect } from 'vitest';
|
2025-09-02 08:15:47 -07:00
|
|
|
import { installCommand, handleInstall } from './install.js';
|
2025-08-25 17:02:10 +00:00
|
|
|
import yargs from 'yargs';
|
2025-09-02 08:15:47 -07:00
|
|
|
import * as extension from '../../config/extension.js';
|
|
|
|
|
|
|
|
|
|
vi.mock('../../config/extension.js', () => ({
|
|
|
|
|
installExtension: vi.fn(),
|
|
|
|
|
}));
|
2025-08-25 17:02:10 +00:00
|
|
|
|
|
|
|
|
describe('extensions install command', () => {
|
|
|
|
|
it('should fail if no source is provided', () => {
|
|
|
|
|
const validationParser = yargs([]).command(installCommand).fail(false);
|
|
|
|
|
expect(() => validationParser.parse('install')).toThrow(
|
2025-09-02 08:15:47 -07:00
|
|
|
'Either --source or --path must be provided.',
|
2025-08-25 17:02:10 +00:00
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should fail if both git source and local path are provided', () => {
|
|
|
|
|
const validationParser = yargs([]).command(installCommand).fail(false);
|
|
|
|
|
expect(() =>
|
|
|
|
|
validationParser.parse('install --source some-url --path /some/path'),
|
|
|
|
|
).toThrow('Arguments source and path are mutually exclusive');
|
|
|
|
|
});
|
|
|
|
|
});
|
2025-09-02 08:15:47 -07:00
|
|
|
|
|
|
|
|
describe('extensions install with org/repo', () => {
|
|
|
|
|
it('should call installExtension with the correct git URL', async () => {
|
|
|
|
|
const consoleLogSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
|
|
|
|
|
const installExtensionSpy = vi
|
|
|
|
|
.spyOn(extension, 'installExtension')
|
|
|
|
|
.mockResolvedValue('test-extension');
|
|
|
|
|
|
|
|
|
|
await handleInstall({ source: 'test-org/test-repo' });
|
|
|
|
|
|
|
|
|
|
expect(installExtensionSpy).toHaveBeenCalledWith({
|
|
|
|
|
source: 'https://github.com/test-org/test-repo.git',
|
|
|
|
|
type: 'git',
|
|
|
|
|
});
|
|
|
|
|
expect(consoleLogSpy).toHaveBeenCalledWith(
|
|
|
|
|
'Extension "test-extension" installed successfully and enabled.',
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|