-
Notifications
You must be signed in to change notification settings - Fork 399
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 #1098 next() is optional in middleware in TypeScript #1099
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -291,12 +291,11 @@ describe('WorkflowStep', () => { | |
|
||
describe('processStepMiddleware', () => { | ||
it('should call each callback in user-provided middleware', async () => { | ||
const { next: _next, ...fakeArgs } = createFakeStepEditAction() as unknown as AllWorkflowStepMiddlewareArgs; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only vaguely remember writing this, but what I think I recall is that the removal of |
||
const { ...fakeArgs } = createFakeStepEditAction() as unknown as AllWorkflowStepMiddlewareArgs; | ||
seratch marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const { processStepMiddleware } = await importWorkflowStep(); | ||
|
||
const fn1 = sinon.spy((async ({ next: continuation }) => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
await continuation!(); | ||
await continuation(); | ||
}) as Middleware<WorkflowStepEdit>); | ||
const fn2 = sinon.spy(async () => {}); | ||
const fakeMiddleware = [fn1, fn2] as WorkflowStepMiddleware; | ||
|
@@ -323,7 +322,6 @@ function createFakeStepEditAction() { | |
workflow_step: {}, | ||
}, | ||
context: {}, | ||
next: sinon.fake(), | ||
}; | ||
} | ||
|
||
|
@@ -341,7 +339,6 @@ function createFakeStepSaveEvent() { | |
callback_id: 'test_save_callback_id', | ||
}, | ||
context: {}, | ||
next: sinon.fake(), | ||
}; | ||
} | ||
|
||
|
@@ -362,7 +359,6 @@ function createFakeStepExecuteEvent() { | |
}, | ||
}, | ||
context: {}, | ||
next: sinon.fake(), | ||
}; | ||
} | ||
|
||
|
@@ -380,6 +376,5 @@ function createFakeViewEvent() { | |
callback_id: 'test_view_callback_id', | ||
}, | ||
context: {}, | ||
next: sinon.fake(), | ||
}; | ||
} |
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.
The code here is a bit tricky. You can check the internals of
processMiddleware
. The outerprocessMiddleware
call quietly setsnext
and middleware execution relies on it.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.
Are the comments on 884 and 871 technically misleading then, if
next
is actually set?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.
@srajiang Indeed,
last()
and L871 may be confusing. In my understanding, the last element of an array of middleware technically can havenext()
but we don't do anything with it. As you saw, inside theprocessMiddleware
method, we calllast()
instead of next middleware with recursiveinvokeMiddleware
call.We may want to update the L871 comment when merging this PR.
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.
Updated the comment