summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/utils/updateCheck.test.ts
diff options
context:
space:
mode:
authorGal Zahavi <[email protected]>2025-08-01 20:17:32 -0700
committerGitHub <[email protected]>2025-08-02 03:17:32 +0000
commit820169ba2e0777ee2bee240f063649cc4b2b107f (patch)
tree1c8e6105512f0fc417442fb6ba27637b744ee739 /packages/cli/src/ui/utils/updateCheck.test.ts
parent15a1f1af9d0e4628e9e82f81d384d614899770e3 (diff)
feat(autoupdate): Improve update check and refactor for testability (#5389)
Diffstat (limited to 'packages/cli/src/ui/utils/updateCheck.test.ts')
-rw-r--r--packages/cli/src/ui/utils/updateCheck.test.ts51
1 files changed, 38 insertions, 13 deletions
diff --git a/packages/cli/src/ui/utils/updateCheck.test.ts b/packages/cli/src/ui/utils/updateCheck.test.ts
index fa6f342e..c2b56a03 100644
--- a/packages/cli/src/ui/utils/updateCheck.test.ts
+++ b/packages/cli/src/ui/utils/updateCheck.test.ts
@@ -5,7 +5,7 @@
*/
import { vi, describe, it, expect, beforeEach } from 'vitest';
-import { checkForUpdates, FETCH_TIMEOUT_MS } from './updateCheck.js';
+import { checkForUpdates } from './updateCheck.js';
const getPackageJson = vi.hoisted(() => vi.fn());
vi.mock('../../utils/package.js', () => ({
@@ -109,24 +109,16 @@ describe('checkForUpdates', () => {
expect(result).toBeNull();
});
- it('should return null if fetchInfo times out', async () => {
+ it('should return null if fetchInfo rejects', async () => {
getPackageJson.mockResolvedValue({
name: 'test-package',
version: '1.0.0',
});
updateNotifier.mockReturnValue({
- fetchInfo: vi.fn(
- async () =>
- new Promise((resolve) => {
- setTimeout(() => {
- resolve({ current: '1.0.0', latest: '1.1.0' });
- }, FETCH_TIMEOUT_MS + 1);
- }),
- ),
+ fetchInfo: vi.fn().mockRejectedValue(new Error('Timeout')),
});
- const promise = checkForUpdates();
- await vi.advanceTimersByTimeAsync(FETCH_TIMEOUT_MS);
- const result = await promise;
+
+ const result = await checkForUpdates();
expect(result).toBeNull();
});
@@ -135,4 +127,37 @@ describe('checkForUpdates', () => {
const result = await checkForUpdates();
expect(result).toBeNull();
});
+
+ describe('nightly updates', () => {
+ it('should notify for a newer nightly version when current is nightly', async () => {
+ getPackageJson.mockResolvedValue({
+ name: 'test-package',
+ 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',
+ });
+ }
+ if (distTag === 'latest') {
+ return Promise.resolve({
+ latest: '1.2.3',
+ current: '1.2.3-nightly.1',
+ });
+ }
+ return Promise.resolve(null);
+ });
+
+ updateNotifier.mockImplementation(({ pkg, distTag }) => ({
+ fetchInfo: () => fetchInfoMock({ pkg, distTag }),
+ }));
+
+ const result = await checkForUpdates();
+ expect(result?.message).toContain('1.2.3-nightly.1 → 1.2.3-nightly.2');
+ expect(result?.update.latest).toBe('1.2.3-nightly.2');
+ });
+ });
});