fix: resolve three flaky tests (#7058)

This commit is contained in:
Arya Gummadi
2025-08-25 17:27:36 -07:00
committed by GitHub
parent 8075300e34
commit 2c6794feed
3 changed files with 69 additions and 44 deletions

View File

@@ -6,6 +6,7 @@
import type { Mock } from 'vitest';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { waitFor } from '@testing-library/react';
import { renderWithProviders } from '../test-utils/render.js';
import { AppWrapper as App } from './App.js';
import type {
@@ -399,9 +400,10 @@ describe('App UI', () => {
);
currentUnmount = unmount;
await new Promise((resolve) => setTimeout(resolve, 10));
expect(spawn).not.toHaveBeenCalled();
// Wait for any potential async operations to complete
await waitFor(() => {
expect(spawn).not.toHaveBeenCalled();
});
});
it('should show a success message when update succeeds', async () => {
@@ -427,11 +429,12 @@ describe('App UI', () => {
updateEventEmitter.emit('update-success', info);
await new Promise((resolve) => setTimeout(resolve, 10));
expect(lastFrame()).toContain(
'Update successful! The new version will be used on your next run.',
);
// Wait for the success message to appear
await waitFor(() => {
expect(lastFrame()).toContain(
'Update successful! The new version will be used on your next run.',
);
});
});
it('should show an error message when update fails', async () => {
@@ -457,11 +460,12 @@ describe('App UI', () => {
updateEventEmitter.emit('update-failed', info);
await new Promise((resolve) => setTimeout(resolve, 10));
expect(lastFrame()).toContain(
'Automatic update failed. Please try updating manually',
);
// Wait for the error message to appear
await waitFor(() => {
expect(lastFrame()).toContain(
'Automatic update failed. Please try updating manually',
);
});
});
it('should show an error message when spawn fails', async () => {
@@ -489,11 +493,12 @@ describe('App UI', () => {
// which is what should be emitted when a spawn error occurs elsewhere.
updateEventEmitter.emit('update-failed', info);
await new Promise((resolve) => setTimeout(resolve, 10));
expect(lastFrame()).toContain(
'Automatic update failed. Please try updating manually',
);
// Wait for the error message to appear
await waitFor(() => {
expect(lastFrame()).toContain(
'Automatic update failed. Please try updating manually',
);
});
});
it('should not auto-update if GEMINI_CLI_DISABLE_AUTOUPDATER is true', async () => {
@@ -519,9 +524,10 @@ describe('App UI', () => {
);
currentUnmount = unmount;
await new Promise((resolve) => setTimeout(resolve, 10));
expect(spawn).not.toHaveBeenCalled();
// Wait for any potential async operations to complete
await waitFor(() => {
expect(spawn).not.toHaveBeenCalled();
});
});
});