mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-23 11:34:44 -07:00
fix(update): replace update-notifier with latest-version (#11989)
This commit is contained in:
@@ -13,9 +13,9 @@ vi.mock('../../utils/package.js', () => ({
|
||||
getPackageJson,
|
||||
}));
|
||||
|
||||
const updateNotifier = vi.hoisted(() => vi.fn());
|
||||
vi.mock('update-notifier', () => ({
|
||||
default: updateNotifier,
|
||||
const latestVersion = vi.hoisted(() => vi.fn());
|
||||
vi.mock('latest-version', () => ({
|
||||
default: latestVersion,
|
||||
}));
|
||||
|
||||
describe('checkForUpdates', () => {
|
||||
@@ -46,7 +46,7 @@ describe('checkForUpdates', () => {
|
||||
const result = await checkForUpdates(mockSettings);
|
||||
expect(result).toBeNull();
|
||||
expect(getPackageJson).not.toHaveBeenCalled();
|
||||
expect(updateNotifier).not.toHaveBeenCalled();
|
||||
expect(latestVersion).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return null when running from source (DEV=true)', async () => {
|
||||
@@ -55,15 +55,11 @@ describe('checkForUpdates', () => {
|
||||
name: 'test-package',
|
||||
version: '1.0.0',
|
||||
});
|
||||
updateNotifier.mockReturnValue({
|
||||
fetchInfo: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ current: '1.0.0', latest: '1.1.0' }),
|
||||
});
|
||||
latestVersion.mockResolvedValue('1.1.0');
|
||||
const result = await checkForUpdates(mockSettings);
|
||||
expect(result).toBeNull();
|
||||
expect(getPackageJson).not.toHaveBeenCalled();
|
||||
expect(updateNotifier).not.toHaveBeenCalled();
|
||||
expect(latestVersion).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return null if package.json is missing', async () => {
|
||||
@@ -77,9 +73,7 @@ describe('checkForUpdates', () => {
|
||||
name: 'test-package',
|
||||
version: '1.0.0',
|
||||
});
|
||||
updateNotifier.mockReturnValue({
|
||||
fetchInfo: vi.fn().mockResolvedValue(null),
|
||||
});
|
||||
latestVersion.mockResolvedValue('1.0.0');
|
||||
const result = await checkForUpdates(mockSettings);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
@@ -89,15 +83,13 @@ describe('checkForUpdates', () => {
|
||||
name: 'test-package',
|
||||
version: '1.0.0',
|
||||
});
|
||||
updateNotifier.mockReturnValue({
|
||||
fetchInfo: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ current: '1.0.0', latest: '1.1.0' }),
|
||||
});
|
||||
latestVersion.mockResolvedValue('1.1.0');
|
||||
|
||||
const result = await checkForUpdates(mockSettings);
|
||||
expect(result?.message).toContain('1.0.0 → 1.1.0');
|
||||
expect(result?.update).toEqual({ current: '1.0.0', latest: '1.1.0' });
|
||||
expect(result?.update.current).toEqual('1.0.0');
|
||||
expect(result?.update.latest).toEqual('1.1.0');
|
||||
expect(result?.update.name).toEqual('test-package');
|
||||
});
|
||||
|
||||
it('should return null if the latest version is the same as the current version', async () => {
|
||||
@@ -105,11 +97,7 @@ describe('checkForUpdates', () => {
|
||||
name: 'test-package',
|
||||
version: '1.0.0',
|
||||
});
|
||||
updateNotifier.mockReturnValue({
|
||||
fetchInfo: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ current: '1.0.0', latest: '1.0.0' }),
|
||||
});
|
||||
latestVersion.mockResolvedValue('1.0.0');
|
||||
const result = await checkForUpdates(mockSettings);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
@@ -119,23 +107,17 @@ describe('checkForUpdates', () => {
|
||||
name: 'test-package',
|
||||
version: '1.1.0',
|
||||
});
|
||||
updateNotifier.mockReturnValue({
|
||||
fetchInfo: vi
|
||||
.fn()
|
||||
.mockResolvedValue({ current: '1.1.0', latest: '1.0.0' }),
|
||||
});
|
||||
latestVersion.mockResolvedValue('1.0.0');
|
||||
const result = await checkForUpdates(mockSettings);
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('should return null if fetchInfo rejects', async () => {
|
||||
it('should return null if latestVersion rejects', async () => {
|
||||
getPackageJson.mockResolvedValue({
|
||||
name: 'test-package',
|
||||
version: '1.0.0',
|
||||
});
|
||||
updateNotifier.mockReturnValue({
|
||||
fetchInfo: vi.fn().mockRejectedValue(new Error('Timeout')),
|
||||
});
|
||||
latestVersion.mockRejectedValue(new Error('Timeout'));
|
||||
|
||||
const result = await checkForUpdates(mockSettings);
|
||||
expect(result).toBeNull();
|
||||
@@ -154,26 +136,13 @@ describe('checkForUpdates', () => {
|
||||
version: '1.2.3-nightly.1',
|
||||
});
|
||||
|
||||
const fetchInfoMock = vi.fn().mockImplementation(({ distTag }) => {
|
||||
if (distTag === 'nightly') {
|
||||
return Promise.resolve({
|
||||
latest: '1.2.3-nightly.2',
|
||||
current: '1.2.3-nightly.1',
|
||||
});
|
||||
latestVersion.mockImplementation(async (name, options) => {
|
||||
if (options?.version === 'nightly') {
|
||||
return '1.2.3-nightly.2';
|
||||
}
|
||||
if (distTag === 'latest') {
|
||||
return Promise.resolve({
|
||||
latest: '1.2.3',
|
||||
current: '1.2.3-nightly.1',
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
return '1.2.3';
|
||||
});
|
||||
|
||||
updateNotifier.mockImplementation(({ pkg, distTag }) => ({
|
||||
fetchInfo: () => fetchInfoMock({ pkg, distTag }),
|
||||
}));
|
||||
|
||||
const result = await checkForUpdates(mockSettings);
|
||||
expect(result?.message).toContain('1.2.3-nightly.1 → 1.2.3-nightly.2');
|
||||
expect(result?.update.latest).toBe('1.2.3-nightly.2');
|
||||
|
||||
Reference in New Issue
Block a user