sindresorhus / ora

Elegant terminal spinner
MIT License
9.15k stars 271 forks source link

Improve `ora.promise()` #181

Closed SrBrahma closed 3 years ago

SrBrahma commented 3 years ago

Implemented https://github.com/sindresorhus/ora/issues/169#issuecomment-873269524

Improves ora.promise: 1) The action can now be a function. It will automatically be executed. The corresponding spinner will be used as argument to that function. 2) It will now return a promise, that resolves when ora.promise given promise/function is resolved, so the user can await ora.promise(..). 3) Added successText and failText, that will be used in the spinner.succeed()/spinner.fail(). They can be either a string or a function. Being a function, successText will receive as argument the return of the action resolve, and failText will receive the action reject content.

Fixes #169

sindresorhus commented 3 years ago

The pull request needs a proper descriptive title.

sindresorhus commented 3 years ago

Please always run npm test locally before pushing changes.

SrBrahma commented 3 years ago

Please always run npm test locally before pushing changes.

~I did and fixed my own errors, but there were other errors not related to my changes~

SrBrahma commented 3 years ago

I have no idea on how to fix this npm test issue: image

SrBrahma commented 3 years ago

I found out why the test error was happening. The new promise() was calling the promise that always rejects. I thought the promise was being rejected before entering the promise() call. Also, the PromiseOptions type definition was missing, looks like I only had added it to the README.

sindresorhus commented 3 years ago

Thanks :)