test: add unit tests for logger and update check utils - #2518
Open
ZayanKhan-12 wants to merge 1 commit into
Open
test: add unit tests for logger and update check utils#2518ZayanKhan-12 wants to merge 1 commit into
ZayanKhan-12 wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
ZayanKhan-12
force-pushed
the
chore/tests-logger-updates
branch
from
August 8, 2026 21:46
96734b7 to
c795bf3
Compare
Lightning00Blade
self-requested a review
August 10, 2026 09:40
Lightning00Blade
requested changes
Aug 10, 2026
| assert.ok(content.endsWith('\n')); | ||
| }); | ||
|
|
||
| it('enables the mcp:log debug namespace', async () => { |
Collaborator
There was a problem hiding this comment.
This is a side-effect and we should not test for it.
| @@ -0,0 +1,170 @@ | |||
| /** | |||
Collaborator
There was a problem hiding this comment.
There is test in tests/check-for-updates.test.ts Why do we need this?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
src/utils/logger.tsandsrc/utils/check-for-updates.tshad no unit test coverage intests/utils/. Both contain observable behavior (file log sink, namespace enabling, flush timeout, update cache freshness/once-per-process logic) that can regress silently, so this adds focused tests asserting the current behavior. Nosrc/changes.What's covered
tests/utils/logger.test.ts(6 tests)saveLogsToFilewritesmcp:logoutput to the given file, appends (flaga+) instead of truncating, writes one newline-terminated line per log call, and enables themcp:logdebug namespace even when previously disabled.flushLogsresolves once the stream has finished, and rejects when the stream does not finish within the timeout (via a stub stream whoseendcallback never fires).debugstate (enabled namespaces,debug.logsink) is saved and restored around the suite.tests/utils/check-for-updates.test.ts(8 tests)CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKSis set (the test runner sets this globally, so the tests save/clear/restore it).{version: VERSION}to~/.cache/chrome-devtools-mcp/latest.jsonand spawnscheck-latest-version.jsdetached withstdio: 'ignore'.Update available: <current> -> <cached>plus the caller-provided message when the cached version is newer; no warning when equal.resetUpdateCheckFlagForTesting().os.homedir()to a per-test temp dir and stubchild_process.spawn/console.warnvianode:test'smock.method, so no real home-directory files are touched and no subprocess/network activity happens.What's not covered (and why)
saveLogsToFile's streamerrorhandler callsprocess.exit(1), which cannot be exercised in-process without killing the test runner.bin/check-latest-version.jssubprocess itself (registry fetch) is out of scope for these unit tests;spawnis stubbed.debug.logis replaced with a plainchunks.join(' ')sink, so printf-style placeholders (e.g.logger('hello %s', 'world')) are written literally ashello %s worldinstead of being substituted the way the defaultutil.formatWithOptions-based sink does. The tests use plain messages to assert current behavior; happy to file a follow-up issue if that quirk is worth fixing.Testing
npm run build— clean.node scripts/test.js tests/utils/logger.test.ts tests/utils/check-for-updates.test.ts— 14/14 pass.npm run test:no-build— 702 tests, 702 pass, 0 fail.npm run check-format— eslint + prettier clean.🤖 Generated with Claude Code