Kiro icon indicating copy to clipboard operation
Kiro copied to clipboard

Kiro struggles to write proper Jest

Open peterhora opened this issue 1 year ago • 1 comments

Feature Description

Test Implementation Issues with Kiro Coding Agent

Kiro struggles to write proper Jest tests that complete successfully, particularly for route testing scenarios. The primary issue is that generated tests hang indefinitely in "RUNS" state because Kiro fails to implement proper resource cleanup and async operation management.

Core Problems:

1. Missing Resource Cleanup Kiro generates tests that open servers, database connections, and other resources but fails to close them properly. Tests hang because Node.js processes remain alive waiting for these unclosed handles.

Example issue:

// Kiro generates this:
describe('Terms Routes', () => {
  let app;
  
  beforeAll(() => {
    app = express();
    // Sets up routes, database connections
  });
  
  test('should get terms', async () => {
    const response = await request(app).get('/terms');
    expect(response.status).toBe(200);
  });
  // Missing: afterAll cleanup
});

2. Improper Async/Await Handling Kiro doesn't consistently await async operations or handle promises correctly, leading to tests that never complete or resolve.

3. No Timeout Configuration Generated tests lack proper timeout settings, causing indefinite hangs when operations don't complete as expected.

4. Missing Error Handling Tests don't include proper error handling for failed async operations, which can cause hanging promises.

Expected Solution:

describe('Terms Routes', () => {
  let app, server, db;
  
  beforeAll(async () => {
    app = express();
    server = app.listen(0);
    db = await connectDatabase();
  });
  
  afterAll(async () => {
    await server.close();
    await db.close();
  });
  
  test('should get terms', async () => {
    const response = await request(app).get('/terms');
    expect(response.status).toBe(200);
  });
});

Impact:

  • Tests cannot be run reliably in CI/CD pipelines
  • Development workflow is disrupted
  • Manual intervention required to kill hanging processes
  • False impression that code is broken when tests simply don't complete

Recommendation: Kiro should be updated to automatically include proper lifecycle management (beforeAll/afterAll hooks) and resource cleanup patterns when generating any tests that involve servers, databases, or external resources.

Use Case

Kiro struggles to write proper Jest tests that complete successfully, particularly for route testing scenarios. The primary issue is that generated tests hang indefinitely in "RUNS" state because Kiro fails to implement proper resource cleanup and async operation management.

Additional Context

No response

peterhora avatar Jul 22 '25 20:07 peterhora

Closing this issue as stale — it was filed over 12 months ago against an early version of Kiro, and the product has undergone significant architectural changes since then (including the 1.0 GA rewrite, new permissions system, hooks v1, Agent Focus, and many CLI improvements).

If this is still relevant on the latest version (IDE 1.0.242 / CLI 2.15.0), please open a new issue with a fresh Conversation ID and your current Kiro version — those help a lot.

AnilMaktala avatar Jul 31 '26 14:07 AnilMaktala