Skip to content

test: fix unit test cases #8

Merged
Baba-2001 merged 1 commit intomainfrom
fix/unit-tests
Mar 3, 2026
Merged

test: fix unit test cases #8
Baba-2001 merged 1 commit intomainfrom
fix/unit-tests

Conversation

@Rishavraaj
Copy link
Contributor

This PR focuses on fixing hanging and failing unit tests across the workspace, along with improving the Jest configuration for better stability and centralized mock setups.

🛠️ Changes Made

  • Centralized Test Setup for Agents ([NEW] libs/agents/src/test-setup.ts)
    • Created a global test setup file to accurately mock @langchain/openai and provide a functional MockChatOpenAI implementation.
    • Linked the new setup file in libs/agents/jest.config.cts via setupFilesAfterEnv.
    • Added the setup file to tsconfig.lib.json and tsconfig.spec.json for proper compilation.
  • Fixed persistent-context.middleware.spec.ts in Agents Library (libs/agents/src/lib/middleware/persistent-context.middleware.spec.ts)
    • Updated the mocked ContactsService to correctly use findById instead of findOne, ensuring the mock aligns with the actual interface.
  • Fixed Hanging Tests in Chat Route (apps/web/src/app/api/chat/route.test.ts)
    • Added proper promise resolution and text stream consuming (await response.text()) to prevent tests from hanging on open handles.
    • Consolidated formatting to use double quotes consistently in the file.
  • Jest Configuration Updates
    • Updated libs/agents/jest.config.cts to integrate the centralized setup file.
    • Updated libs/sales/jest.config.cts with passWithNoTests: true to prevent test task failures if no specs are present in the sales package.

✅ Verification

  • All tests in the workspace now run explicitly via nx run-many -t test.
  • No lingering open handles or unhandled promises in the Next.js API route tests.

- Add global test setup in agents lib for @langchain/openai mock
- Fix ContactsService mock in persistent-context middleware spec
- Resolve open handles in web api chat route tests by consuming streams
- Configure sales lib jest to pass with no tests

COAUTHOR="Co-authored-by: Antigravity AI <agent@antigravity.google>
@Baba-2001 Baba-2001 merged commit 8d712bc into main Mar 3, 2026
1 check passed
@Baba-2001 Baba-2001 deleted the fix/unit-tests branch March 3, 2026 07:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants