fix(container-runtime): Fix navigator assignment in Hardware Stats tests#26938
Open
ChumpChief wants to merge 2 commits intomicrosoft:mainfrom
Open
fix(container-runtime): Fix navigator assignment in Hardware Stats tests#26938ChumpChief wants to merge 2 commits intomicrosoft:mainfrom
ChumpChief wants to merge 2 commits intomicrosoft:mainfrom
Conversation
In Node 22+, globalThis.navigator is a read-only getter. Use Object.defineProperty to override it in tests instead of direct assignment. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Updates the Hardware Stats test helper to work on Node 22+ where globalThis.navigator is a read-only getter, enabling the repo’s Node 22 upgrade path.
Changes:
- Replaces direct
global.navigator = ...assignment withObject.defineProperty(globalThis, "navigator", ...)in tests. - Adds an explanatory comment about Node 22’s read-only
navigatorbehavior.
Capture the original navigator property descriptor and restore it in afterEach so the override doesn't leak into other test suites. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
jason-ha
approved these changes
Apr 7, 2026
|
|
||
| function restoreNavigator() { | ||
| if (originalNavigatorDescriptor === undefined) { | ||
| // eslint-disable-next-line @typescript-eslint/no-dynamic-delete -- this branch can be removed after upgrading to Node 22, which always provides a built-in navigator descriptor |
shlevari
reviewed
Apr 7, 2026
shlevari
left a comment
There was a problem hiding this comment.
This code seems right for doing what you're doing, but, the fix feels a little weird to me. Like it just seems odd to add code to get around the fact that you can't set something because there is only a getter. Could you add more description to the PR on why this is necessary and the right fix and if there is any plan to remove it once the update happens?
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.
Description
In Node 22+,
globalThis.navigatoris a read-only getter (Node added a built-inNavigatorobject). The Hardware Stats tests were assigning directly toglobal.navigator, which now throwsTypeError: Cannot set property navigator of #<Object> which has only a getter.Fix: use
Object.definePropertyto override the property instead of direct assignment.This is a prerequisite for upgrading the repo to Node 22 (#26934).
Reviewer Guidance
The review process is outlined on this wiki page.