-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make sure mocks as global variable for multiple versions of muk-prop #4
Conversation
WalkthroughThe pull request introduces a significant refactoring of mock item management in the Changes
Sequence DiagramsequenceDiagram
participant Client
participant Index as src/index.ts
participant GlobalState as globalThis
Client->>Index: mock()
Index->>GlobalState: Check/Initialize MOCKS symbol
Index->>GlobalState: Push mock item
Client->>Index: restore()
Index->>GlobalState: Retrieve MOCKS
Index->>GlobalState: Pop all mock items
Index->>GlobalState: Clear mock state
Possibly related PRs
Poem
Tip CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
commit: |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #4 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 81 89 +8
Branches 10 12 +2
=========================================
+ Hits 81 89 +8 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/index.ts (3)
12-17
: Ensure array-type consistency in getMocks() usage.
Currently, getMocks() unconditionally sets and retrieves an array from globalThis. Consider validating the stored object type (e.g., if a user accidentally overwrote this Symbol with a non-array value). Type checks might strengthen the resilience of getMocks() against runtime pollution.
72-74
: Pop-based restoration: consider concurrency or parallel usage scenarios.
Although Node.js is single-threaded, library consumers may queue multiple mock/restore cycles. Using pop() in a while loop is fine in synchronous flows, but concurrency or parallel test runners may need a lock or a note that this isn’t thread-safe.Would you like a concurrency-safe version or a big flashing note in the docs that this function isn’t thread-safe?
75-77
: Validate fallback logic for inherited properties.
If hasOwnProperty = false, we unconditionally delete the property on the object. This assumes the original property exists on the prototype chain. Consider verifying that the property still exists upstream to avoid unexpected state if it was absent altogether.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/index.ts
(3 hunks)
🔇 Additional comments (2)
src/index.ts (2)
9-9
: Leverage uniqueness of the Symbol name.
Defining a Symbol with Symbol.for("@cnpmjs/muk-prop mocks") ensures a well-known global Symbol name. This is a good practice for bridging multiple module systems. Just make sure the name is unique enough to avoid collisions.
26-26
: Double-check for undefined descriptors.
Forcing with “!” (in Object.getOwnPropertyDescriptor(obj, key)!) might mask potential undefined results. If “key” doesn’t exist at any level, this returns undefined. Consider fallback handling to ensure robust error reporting.
Run the following script to detect calls to mock() used on potentially non-existent properties:
[skip ci] ## [1.1.1](v1.1.0...v1.1.1) (2024-12-22) ### Bug Fixes * make sure mocks as global variable for multiple versions of muk-prop ([#4](#4)) ([62e120b](62e120b))
Summary by CodeRabbit
New Features
Bug Fixes