You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an example of tests passing (can't publish at the moment) with require.resolve and with resolve as a callback, but when I wrap resolve in const resolveAsync = Promise.promisify(resolve) for some reason the tests that worked are failing. I've also implemented my own wrapped promise and some of tests pass, and others fail, specifically cases where there's a package.json resolve.
Any ideas why this package is un-promisify-able, and potential ways around it?
I've been using Bluebird to promisify, but even an initial check here.
➜ ~ trymodule util.promisify resolve
Gonna start a REPL with packages installed and loaded for you
'util.promisify' was already installed since before!
'resolve' was already installed since before!
Package 'util.promisify' was loaded and assigned to 'util_promisify' in the current scope
Package 'resolve' was loaded and assigned to 'resolve' in the current scope
REPL started...
> require.resolve('./Desktop/jest-example/index.js')
'/Users/treggi/Desktop/jest-example/index.js'
> util.promisify(resolve)('./Desktop/jest-example/index.js').then(console.log)
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
> (node:86567) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Cannot find module './Desktop/jest-example/index.js' from 'internal'
(node:86567) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
On Feb 22, 2018 8:42 PM, "Jordan Harband" ***@***.***> wrote:
Unhandled promise rejection (rejection id: 1): Error: Cannot find module
'./Desktop/jest-example/index.js' from 'internal' - it seems like it's
properly rejecting. Try adding .catch(e => console.error(e))?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#151 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AASHXnSxljP8-9qXB79SUBqt8WVYjfEnks5tXhdvgaJpZM4SP8to>
.
➜ ~ trymodule util.promisify resolve
Gonna start a REPL with packages installed and loaded for you
'util.promisify' was already installed since before!'resolve' was already installed since before!
Package 'util.promisify' was loaded and assigned to 'util_promisify'in the current scope
Package 'resolve' was loaded and assigned to 'resolve'in the current scope
REPL started...
Regular require.resolve works, and resolves this path.
After looking into this a bit more, the issue is that the assumption that "promisify will work on everything" is flawed; it won't.
Using util.promisfy.custom, we could provide a custom implementation that would work with the native one (but not with bluebird) - but then this module would have to add a dependency on util.promisify and/or restrict which node versions it runs on.
In other words, I think the proper solution is to wrap resolve in new Promise if you want to promisify it.
Activity
ljharb commentedon Feb 22, 2018
What promisify implementation are you using?
Since https://npmjs.com/util.promisify is built into node, that’s really the only implementation that matters.
If resolve can’t promisify by default, we could maybe add a custom promisify symbol.
Does it work with the canonical implementation?
reggi commentedon Feb 22, 2018
I've been using Bluebird to promisify, but even an initial check here.
Running node 9.5
ljharb commentedon Feb 23, 2018
Unhandled promise rejection (rejection id: 1): Error: Cannot find module './Desktop/jest-example/index.js' from 'internal'- it seems like it's properly rejecting. Try adding.catch(e => console.error(e))?reggi commentedon Feb 23, 2018
ljharb commentedon Feb 23, 2018
What happens with a non-promisified version of this module, however?
reggi commentedon Feb 23, 2018
@ljharb It works perfectly fine
Let me explain this example:
Regular
require.resolveworks, and resolves this path.The
resolvemodule callback returns the correct resolved path.Node 9's native
util.promisifyreturns a promise, calls it's.catchand logs the error.The
util.promisifymodule returns a promise, calls it's.catchand logs the error.reggi commentedon Feb 24, 2018
Any idea what's going on here @ljharb?
ljharb commentedon Feb 24, 2018
@reggi what happens if you call the promisified
resolvewith an empty object as the second argument?ljharb commentedon Feb 24, 2018
After looking into this a bit more, the issue is that the assumption that "promisify will work on everything" is flawed; it won't.
Using
util.promisfy.custom, we could provide a custom implementation that would work with the native one (but not with bluebird) - but then this module would have to add a dependency onutil.promisifyand/or restrict which node versions it runs on.In other words, I think the proper solution is to wrap
resolveinnew Promiseif you want to promisify it.