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: remove ContextDelegation #183

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/core dependency from version 6.2.5 to 6.2.11
  • Refactor

    • Replaced ContextDelegation with Context across multiple files
    • Updated logging types from Logger to EggLogger
    • Modified type declarations in test files and application code
  • Tests

    • Updated type assertions in test files to reflect new context and logging types

Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request introduces a comprehensive update to the @eggjs/mock package, focusing on type changes related to context and logging. The primary modifications involve replacing ContextDelegation with Context and Logger with EggLogger across multiple files. The package's core dependency is also upgraded from version 6.2.5 to 6.2.11. These changes aim to improve type consistency and align the package with the latest Egg.js framework specifications.

Changes

File Change Summary
package.json Upgraded @eggjs/core dependency from ^6.2.5 to ^6.2.11
src/app/extend/application.ts Replaced Logger with EggLogger, updated MockContextDelegation to MockContext, modified method signatures
src/app/middleware/cluster_app_mock.ts Updated ctx parameter type from ContextDelegation to Context
test/fixtures/tegg-app-esm/test/*.ts Replaced ContextDelegation with Context in type declarations
test/fixtures/tegg-app/test/*.ts Replaced ContextDelegation with Context in type declarations
test/index.test-d.ts Updated import and type expectations from ContextDelegation to Context

Poem

🐰 Hop, hop, through the code we go,
Context and Logger in a new-found glow
Types dancing with elegant grace
Egg.js mock, setting a brighter pace
Refactoring magic, clean and bright! 🌟


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

Removed dependencies detected. Learn more about Socket for GitHub ↗︎

🚮 Removed packages: npm/tsd@0.31.2, npm/tshy-after@1.4.0, npm/tshy@3.0.2, npm/typescript@5.7.2

View full report↗︎

Copy link

pkg-pr-new bot commented Jan 2, 2025

Open in Stackblitz

npm i https://pkg.pr.new/eggjs/mock/@eggjs/mock@183

commit: 191ddf5

Copy link
Contributor

@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 (1)
src/app/middleware/cluster_app_mock.ts (1)

12-14: Avoid casting ctx.request to any.
Casting to any bypasses type safety. Consider using a typed request body or a narrower type assertion if needed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b3d83d8 and 191ddf5.

📒 Files selected for processing (8)
  • package.json (1 hunks)
  • src/app/extend/application.ts (8 hunks)
  • src/app/middleware/cluster_app_mock.ts (1 hunks)
  • test/fixtures/tegg-app-esm/test/hooks.test.ts (2 hunks)
  • test/fixtures/tegg-app-esm/test/tegg_context.test.ts (1 hunks)
  • test/fixtures/tegg-app/test/hooks.test.ts (2 hunks)
  • test/fixtures/tegg-app/test/tegg_context.test.ts (1 hunks)
  • test/index.test-d.ts (1 hunks)
🔇 Additional comments (30)
src/app/extend/application.ts (11)

9-10: Use consistent import naming.

Replacing Logger with EggLogger and ContextDelegation with Context is consistent with the new implementation. Confirm that all other imports referencing ContextDelegation are removed or updated throughout the codebase.


42-42: Interface rename is clear and aligns with Egg’s standard context.

Changing MockContextDelegation to MockContext and extending Context ensures better type checking and clarity. Keep an eye out for any references to the old interface name.


50-52: Logger type alignment.

These changes ensure that the application’s logger and coreLogger properties match Egg’s official logger type. This should help avoid confusion and leverage the proper Egg logger APIs.


76-76: Transition from MockContextDelegation to MockContext in return type.

Returning MockContext here aligns with the new extended interface and enhances type consistency.


105-105: Reusing existing currentContext.

Ensuring the returned context is properly cast to MockContext. This is acceptable as long as the underlying currentContext truly conforms to MockContext.


112-112: Directly returning the new context.

Casting the newly created context to MockContext is consistent. Just verify all relevant properties are initialized properly (e.g., service).


115-115: Method signature update to accept and return MockContext.

Using MockContext clarifies what context methods or properties can be used within the scope function. The async logic here remains clear.


407-407: Logger parameter usage.

The update to EggLogger clarifies usage and ensures the parameter can accept a logger instance conforming to Egg’s standard. No further changes needed.


427-427: Synchronized logger checks with EggLogger.

Ensures _mockLogs logic works properly with the updated logger type. This method’s approach to reading logs from memory or file remains valid.


463-463: expectLog method aligned with EggLogger.

Maintains consistency with the rest of the logger changes in the file. Good job.


473-473: notExpectLog method aligned with EggLogger.

Ensures consistency with new logging approach. No issues noted.

test/fixtures/tegg-app/test/tegg_context.test.ts (2)

2-2: Context import alignment.

This change from ContextDelegation to Context is in line with the broader context refactor. Confirm no references to the old type remain.


8-8: Context variable declaration.

Declaring ctx with the new Context type ensures type safety. Looks good.

test/fixtures/tegg-app-esm/test/tegg_context.test.ts (2)

2-2: Update to import from egg.

Renaming to Context is correct and consistent with Egg framework updates.


8-8: Variable type updated.

Switching ctx to the Context type aligns with the rest of the PR’s context changes.

test/fixtures/tegg-app-esm/test/hooks.test.ts (5)

2-2: Import Context from egg.

Good replacement of the old ContextDelegation type. Ensures that the test suite references the correct context type.


9-11: Variables updated to Record<string, Context>.

Switching the type from a custom delegation to the standard Egg Context clarifies usage. Keep an eye on any helper methods that might expect the old type.


29-37: Assigning app.currentContext to typed objects.

Casting app.currentContext as Context ensures type safety in tests. No issues found.


43-51: Same pattern for bar suite.

Behavior is identical to the foo suite, which is consistent and good.


56-63: Array of Context objects in multi-it tests.

Appending multiple Context references ensures each test run is self-contained. This approach is valid.

test/fixtures/tegg-app/test/hooks.test.ts (5)

2-2: Import Context from egg.

Updating the import to use Context matches the removal of ContextDelegation from the codebase.


9-11: Initialization of context dictionaries with Context.

Switches to Context confirm the new type is fully adopted.


29-37: Ensuring typed references to currentContext.

Consistently casting to Context ensures no untyped usage.


43-51: bar suite updated for type consistency.

Matches the foo suite approach.


56-63: Storing multiple contexts in an array.

Confirming the array is typed as Array<Context>. Consistency is maintained here as well.

test/index.test-d.ts (2)

2-2: Consider removing unused references to ContextDelegation.
Great job replacing ContextDelegation with Context. If there are any remaining references to ContextDelegation in other files or test cases, consider removing them for consistency.


8-9: Verify correctness of type assertions.
Using Context | undefined ensures stricter type safety. Just confirm you have test coverage to validate these scenarios (when app.currentContext or app.ctxStorage.getStore() might be undefined).

src/app/middleware/cluster_app_mock.ts (2)

2-2: Context type alignment.
Updating ContextDelegation to Context is consistent with the new Egg.js definitions. Good job making this change.


7-7: Preserve functionality after type replacement.
Be sure that no ContextDelegation-specific properties or methods are being relied on. Confirm that any references to older context properties are updated accordingly.

package.json (1)

32-32: Verify compatibility with @eggjs/core@^6.2.11.
Ensure that other dependencies and your code are fully compatible with the updated @eggjs/core version.

@fengmk2 fengmk2 merged commit f4051d0 into master Jan 2, 2025
14 checks passed
@fengmk2 fengmk2 deleted the fix-remove-ContextDelegation branch January 2, 2025 15:10
fengmk2 pushed a commit that referenced this pull request Jan 2, 2025
[skip ci]

## [6.0.5](v6.0.4...v6.0.5) (2025-01-02)

### Bug Fixes

* remove ContextDelegation ([#183](#183)) ([f4051d0](f4051d0))
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