mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-22 01:37:50 +00:00
pre-release commit
This commit is contained in:
82
packages/cli/src/ui/utils/updateCheck.test.ts
Normal file
82
packages/cli/src/ui/utils/updateCheck.test.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2025 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { vi, describe, it, expect, beforeEach } from 'vitest';
|
||||
import { checkForUpdates } from './updateCheck.js';
|
||||
|
||||
const getPackageJson = vi.hoisted(() => vi.fn());
|
||||
vi.mock('../../utils/package.js', () => ({
|
||||
getPackageJson,
|
||||
}));
|
||||
|
||||
const updateNotifier = vi.hoisted(() => vi.fn());
|
||||
vi.mock('update-notifier', () => ({
|
||||
default: updateNotifier,
|
||||
}));
|
||||
|
||||
describe('checkForUpdates', () => {
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
});
|
||||
|
||||
it('should return null if package.json is missing', async () => {
|
||||
getPackageJson.mockResolvedValue(null);
|
||||
const result = await checkForUpdates();
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('should return null if there is no update', async () => {
|
||||
getPackageJson.mockResolvedValue({
|
||||
name: 'test-package',
|
||||
version: '1.0.0',
|
||||
});
|
||||
updateNotifier.mockReturnValue({ update: null });
|
||||
const result = await checkForUpdates();
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('should return a message if a newer version is available', async () => {
|
||||
getPackageJson.mockResolvedValue({
|
||||
name: 'test-package',
|
||||
version: '1.0.0',
|
||||
});
|
||||
updateNotifier.mockReturnValue({
|
||||
update: { current: '1.0.0', latest: '1.1.0' },
|
||||
});
|
||||
const result = await checkForUpdates();
|
||||
expect(result).toContain('1.0.0 → 1.1.0');
|
||||
});
|
||||
|
||||
it('should return null if the latest version is the same as the current version', async () => {
|
||||
getPackageJson.mockResolvedValue({
|
||||
name: 'test-package',
|
||||
version: '1.0.0',
|
||||
});
|
||||
updateNotifier.mockReturnValue({
|
||||
update: { current: '1.0.0', latest: '1.0.0' },
|
||||
});
|
||||
const result = await checkForUpdates();
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('should return null if the latest version is older than the current version', async () => {
|
||||
getPackageJson.mockResolvedValue({
|
||||
name: 'test-package',
|
||||
version: '1.1.0',
|
||||
});
|
||||
updateNotifier.mockReturnValue({
|
||||
update: { current: '1.1.0', latest: '1.0.0' },
|
||||
});
|
||||
const result = await checkForUpdates();
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('should handle errors gracefully', async () => {
|
||||
getPackageJson.mockRejectedValue(new Error('test error'));
|
||||
const result = await checkForUpdates();
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user