Fix async middleware#2164
Conversation
test/middleware.cjs
Outdated
|
|
||
| // Addresses: https://github.com/yargs/yargs/issues/2124 | ||
| // This test will fail if the result of async middleware is not treated like a promise | ||
| it('treats result of async middleware as promise', done => { |
There was a problem hiding this comment.
I would be tempted to write a more specific test to #2124
"Using the strict option in combination with an async middleware, which is applied before the validation, does not result in unknown command"
There was a problem hiding this comment.
I simplified the test. I kept the done logic, because Mocha will pass this test before the unhandled promise would cause it to fail. If there's a regression, this test will fail because done will get called twice, and one of the executions will have an error passed as an argument
test/middleware.cjs
Outdated
| 'cmd1', | ||
| 'cmd1 desc', | ||
| yargs => | ||
| yargs |
There was a problem hiding this comment.
I had to read this a few times, I'm wondering if it would be worth simplifying to exactly the minimal case outlined in the regression:
Yargs
.strict(true)
.middleware(async () => {}, true)
.command("test", false, () => {}, () => {})
.parseAsync(['test']);
I don't have a strong opinion though, if your goal was to exercise parts of the codebase that weren't covered in the above example.
Addresses: #2124
Description
The result of
applyMiddlewareisArguments | Promise<Arguments>, but the code treats it synchronously. Whenever it returns a promise, that promise isn't handled as such.This problem is easier to spot when
strictis usedReproduction
I put a console log after
applyMiddlewareis called, and I could see that 'waking up' showed up afterapplyMiddlewarefinished.