Skip to content
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

Merged
merged 1 commit into from
Jan 2, 2025
Merged

Conversation

fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Jan 2, 2025

Summary by CodeRabbit

  • Dependencies

    • Updated @eggjs/bin to version 7
    • Upgraded pedding to version 2.0.1
    • Removed egg-bin version 6
  • Documentation

    • Updated import statements in README.md to use named imports
  • Refactor

    • Restructured mock functionality in src/index.ts
    • Modified import statements in test files to use named imports
  • Tests

    • Updated mocking approach in test files to use consistent mm object methods

Copy link

coderabbitai bot commented Jan 2, 2025

Walkthrough

The 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 src/index.ts file to use a more sophisticated proxy-based export approach.

Changes

File Change Summary
README.md Updated import statements from import mm from 'mm' to import { mm } from 'mm' across multiple examples
package.json - Added @eggjs/bin@7 as a dev dependency
- Removed egg-bin@6
- Updated pedding from ^1.1.0 to ^2.0.1
src/index.ts - Created _mock constant consolidating mock functions
- Introduced proxyMock with custom Proxy behavior
- Updated default export to proxyMock
test/async-await.test.ts - Updated import to remove restore and mockDatas
- Replaced direct function calls with mm method calls
test/mm.test.ts Updated pedding import from default to named import

Sequence Diagram

sequenceDiagram
    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
Loading

Poem

🐰 A Rabbit's Ode to Code Refactor 🔧

With imports named and proxies bright,
Our mock library takes elegant flight
Dependencies dance, versions anew
Refactoring magic, clean and true
A codebase transformed with bunny delight!

🚀✨


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Jan 2, 2025

Open in Stackblitz

npm i https://pkg.pr.new/node-modules/mm@63

commit: f557999

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.62%. Comparing base (a7950f3) to head (f557999).
Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

Copy link

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/[email protected] None 0 13.2 kB fengmk2

🚮 Removed packages: npm/[email protected], npm/[email protected]

View full report↗︎

@fengmk2 fengmk2 merged commit 18f4f7c into master Jan 2, 2025
23 checks passed
@fengmk2 fengmk2 deleted the fix-export-mm branch January 2, 2025 08:55
Copy link

@coderabbitai coderabbitai bot left a 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 or mockAPI).


601-601: Maintain consistent exports naming.

We have _mock aliased as mm, but also an explicit mock 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 the afterEach(mm.restore);.

Also applies to: 25-25


73-73: Inline usage of mm.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

📥 Commits

Reviewing files that changed from the base of the PR and between 93c6647 and f557999.

📒 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 the http and https mocks.

Refactor suggestions for these new exported properties to ensure the underlying logic is consistent. For example, mockHttp and mockHttps 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 and get 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 to pedding 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 in src/index.ts.

Also applies to: 47-47, 71-71, 99-99, 123-123, 210-210, 259-259, 300-300

fengmk2 pushed a commit that referenced this pull request Jan 2, 2025
[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))
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