Skip to content

Fix test suite crashes from nock v14 and ESM incompatibility#132

Merged
antonym merged 2 commits intomasterfrom
fix/nock-unhandled-error
Mar 15, 2026
Merged

Fix test suite crashes from nock v14 and ESM incompatibility#132
antonym merged 2 commits intomasterfrom
fix/nock-unhandled-error

Conversation

@antonym
Copy link
Copy Markdown
Member

@antonym antonym commented Mar 15, 2026

Summary

  • Fix unhandled nock/mswjs error: nock v14 uses @mswjs/interceptors internally, and replyWithError() emits an async socket error that escapes try/catch, crashing the process after tests complete. Replaced with reply(500) which tests the same failure-handling scenario without the unhandled error.
  • Fix nock cleanup guard in tests/setup.js: The typeof require('nock') !== 'undefined' check was always true (require returns the module object). Now uses require.cache to only call cleanAll() when nock was actually loaded by a test.
  • Fix ESM import error in binary detection test: isbinaryfile is ESM-only and cannot be require()'d in Jest's CJS environment. Removed the unnecessary require() calls since the test only uses a jest.fn() mock.

All 5 test suites, 62 tests passing.

isbinaryfile is ESM-only and cannot be require()'d in Jest's CJS
environment. The test was importing it only to immediately replace the
export with a jest.fn() mock, so remove the unnecessary require() calls.
const { isBinaryFile } = require('isbinaryfile');

// Mock binary file detection
// Mock binary file detection (isbinaryfile is ESM-only, so mock directly)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: Test is not testing any application code

While the comment explains why the import was removed (ESM-only module), the resulting test has a fundamental flaw: it creates a mock function and then calls the mock directly (lines 180-181), which means it's only testing that the mock returns what it was configured to return.

This is a tautological test that provides no value. The test should either:

  1. Mock isbinaryfile at the module level and test actual application code that uses it
  2. Be removed entirely if binary file detection is not actually used in the application
  3. Be converted to an integration test that tests the actual binary file detection behavior

Currently, this test will always pass regardless of whether binary file detection works correctly in the application.

@kilo-code-bot
Copy link
Copy Markdown

kilo-code-bot bot commented Mar 15, 2026

Code Review Summary

Status: No New Issues Found | Recommendation: Address existing feedback

Overview

Reviewed the changes to tests/unit/app.test.js. The PR improves the binary file detection test by:

  • Adding proper module-level mock for isbinaryfile (line 13)
  • Rewriting the test with realistic text and binary data buffers
  • Verifying mock calls with correct parameters

The code changes are technically correct with no runtime errors, security issues, or logic bugs.

Note: The previously identified issue (test not testing actual application code) remains, but no new issues were introduced by these changes.

Files Reviewed (1 file)

Fix these issues in Kilo Cloud

Address review feedback: the old test was tautological (created a mock
and called it directly). Now uses jest.mock('isbinaryfile') at the
module level, which also fixes the ESM import error, and tests the
binary detection branching logic used by the editgetfile socket handler.
@antonym antonym merged commit 44623b5 into master Mar 15, 2026
7 checks passed
@antonym antonym deleted the fix/nock-unhandled-error branch March 15, 2026 20:56
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.

1 participant