-
Notifications
You must be signed in to change notification settings - Fork 16
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: allow call mm.restore on normal export #63
Conversation
WalkthroughThe pull request introduces changes to multiple files in the project, focusing on import statement modifications, dependency updates, and restructuring of the mocking library's export mechanism. The primary modifications include updating import syntax from default to named imports, updating package dependencies, and refactoring the mock functionality in the Changes
Sequence DiagramsequenceDiagram
participant Module as Module
participant ProxyMock as Proxy Mock
participant MockFunctions as Mock Functions
Module->>ProxyMock: Create proxy with _mock
ProxyMock-->>Module: Proxy object
Module->>ProxyMock: Invoke mock function
ProxyMock->>MockFunctions: Intercept and delegate call
MockFunctions-->>ProxyMock: Return result
ProxyMock-->>Module: Return result
Poem
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 #63 +/- ##
==========================================
+ Coverage 95.52% 95.62% +0.10%
==========================================
Files 1 1
Lines 648 663 +15
Branches 123 125 +2
==========================================
+ Hits 619 634 +15
Misses 29 29 ☔ View full report in Codecov by Sentry. |
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/[email protected], npm/[email protected] |
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 (6)
src/index.ts (4)
598-598
: Consider renaming_mock
.While
_mock
is acceptable, a more descriptive name would improve readability (e.g.,mockImplementation
ormockAPI
).
601-601
: Maintain consistent exports naming.We have
_mock
aliased asmm
, but also an explicitmock
property. Consider simplifying this to reduce confusion.
602-602
: Group related exports for clarity.Similar functionality is scattered across alias properties (
datas
,data
,empty
,error
). Consider grouping them in a single logical export object to improve discoverability and future maintainability.Also applies to: 604-604, 607-607, 609-609
621-623
: Check usage of commented imports.Lines mention commented out lines (
// import mm from 'mm';
). If these are no longer necessary, remove them to keep the file clean.test/async-await.test.ts (2)
14-14
: Simplify consistent restoration calls.Both lines call
mm.restore()
in different contexts. Confirm if it’s repeated intentionally or if you want to rely on theafterEach(mm.restore);
.Also applies to: 25-25
73-73
: Inline usage ofmm.mockDatas()
.Calls to
mm.mockDatas()
are correct. If repeated multiple times, consider extracting a helper within the test suite for reusability.Also applies to: 77-77
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
README.md
(8 hunks)package.json
(1 hunks)src/index.ts
(1 hunks)test/async-await.test.ts
(4 hunks)test/mm.test.ts
(1 hunks)
🔇 Additional comments (8)
src/index.ts (3)
616-617
: Verify thehttp
andhttps
mocks.Refactor suggestions for these new exported properties to ensure the underlying logic is consistent. For example,
mockHttp
andmockHttps
rely on forcibly backing up and restoring.request
from their modules. Confirm all test coverage is adequate.
624-633
: Confirm Proxy traps handle all usage.The
apply
andget
traps look fine, but ensure that you do not need additional traps for property definitions or enumerations if you plan to expand usage of_mock
.
639-640
: Exports align well with the new Proxy-based design.All aliased exports appear to match the new signature. This looks good. Just verify references in other files have updated references to
_mock as mm
.Also applies to: 643-644, 646-646, 649-649, 651-651, 658-659, 663-663
test/async-await.test.ts (1)
2-2
: Confirm library usage.Using named import
{ mm }
from'../src/index.js'
. Double-check references in tests to ensure the new usage does not break any test logic.test/mm.test.ts (1)
13-13
: Confirm pedding import usage.Swapping to a named import is fine. Ensure that you are properly referencing
pedding
in all test contexts.package.json (2)
28-28
: Dependency addition of@eggjs/bin
.Please confirm if this replacement is tested adequately in your CI environment, given that
egg-bin
is removed.
34-34
: Upgrade topedding
v2.Check for breaking changes from v1 to v2 and ensure no code references the removed default import.
README.md (1)
28-28
: Correctly updated to named imports.All references to
mm
are adjusted to a named import. This aligns with the new export structure insrc/index.ts
.Also applies to: 47-47, 71-71, 99-99, 123-123, 210-210, 259-259, 300-300
[skip ci] ## [4.0.2](v4.0.1...v4.0.2) (2025-01-02) ### Bug Fixes * allow call mm.restore on normal export ([#63](#63)) ([18f4f7c](18f4f7c))
Summary by CodeRabbit
Dependencies
@eggjs/bin
to version 7pedding
to version 2.0.1egg-bin
version 6Documentation
Refactor
src/index.ts
Tests
mm
object methods