-
Notifications
You must be signed in to change notification settings - Fork 7
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: should bind ctx to egg router controller this context #14
Conversation
WalkthroughThe recent changes to the Changes
Sequence Diagram(s)sequenceDiagram
participant Supertest
participant KoaApp
participant EggRouter
participant Controller
Supertest->>KoaApp: Sends HTTP Request
KoaApp->>EggRouter: Processes route and middlewares
EggRouter->>Controller: Binds ctx to this and executes
Controller->>EggRouter: Returns response
EggRouter->>KoaApp: Sends response
KoaApp->>Supertest: Forwards HTTP Response
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #14 +/- ##
==========================================
- Coverage 99.41% 99.18% -0.24%
==========================================
Files 4 4
Lines 1699 1710 +11
Branches 220 224 +4
==========================================
+ Hits 1689 1696 +7
- Misses 10 14 +4 ☔ 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
Outside diff range and nitpick comments (2)
test/EggRouter.test.ts (2)
Line range hint
39-39
: The generator functionworld
in thehello
controller does not useyield
, which is misleading as it is defined as a generator.Consider refactoring this to an async function if no yielding is necessary, or add a yield statement if intended.
Line range hint
244-246
: Arrow function conversion recommended for cleaner and more concise code.- const asyncMiddleware1 = async function() { return; }; + const asyncMiddleware1 = async () => {}; - const asyncMiddleware = async function() { return; }; + const asyncMiddleware = async () => {}; - const commonMiddleware = function() {}; + const commonMiddleware = () => {}; - const asyncMiddleware = async function() { return; }; + const asyncMiddleware = async () => {};Also applies to: 283-283
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/EggRouter.ts (3 hunks)
- test/EggRouter.test.ts (1 hunks)
Additional context used
Biome
test/EggRouter.test.ts
[error] 39-39: This generator function doesn't contain yield. (lint/correctness/useYield)
[error] 244-244: This function expression can be turned into an arrow function. (lint/complexity/useArrowFunction)
Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.
[error] 245-245: This function expression can be turned into an arrow function. (lint/complexity/useArrowFunction)
Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.
[error] 246-246: This function expression can be turned into an arrow function. (lint/complexity/useArrowFunction)
Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.
[error] 283-283: This function expression can be turned into an arrow function. (lint/complexity/useArrowFunction)
Function expressions that don't use this can be turned into arrow functions.
Safe fix: Use an arrow function instead.
Additional comments not posted (5)
test/EggRouter.test.ts (2)
3-4
: Import statements added successfully for Koa and supertest.
8-23
: This test case verifies the correct binding ofctx
tothis
in a controller function. The setup and assertions are correctly implemented.src/EggRouter.ts (3)
5-7
: Imports forisGeneratorFunction
and updated types withNext
added correctly.
150-158
: Added checks for generator functions in middleware and appropriate error handling. This ensures that only async functions are used, aligning with modern async/await patterns.
337-348
: TheconvertMiddlewares
function now correctly binds the controller context tothis
within middleware functions. This is crucial for maintaining consistency in controller methods.
[skip ci] ## [3.0.4](v3.0.3...v3.0.4) (2024-06-16) ### Bug Fixes * should bind ctx to egg router controller this context ([#14](#14)) ([b5b5588](b5b5588))
Summary by CodeRabbit
Bug Fixes
New Features
ctx
) binding tothis
within controller functions in theEggRouter
class.Tests
EggRouter
class.