Skip to content

Instantly share code, notes, and snippets.

@chrisdickinson
Created August 14, 2015 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisdickinson/3184a40e758ba262c22a to your computer and use it in GitHub Desktop.
Save chrisdickinson/3184a40e758ba262c22a to your computer and use it in GitHub Desktop.
// my npm dep tree (fake, made of lies)
myproject
├─┬ mydep@A.B.C
│ └── bluebird@X.Y.Z
└── bluebird@M.N.O
// this is a file that all of my tests require.
for (var key in require.cache) {
if (require.cache[key].exports &&
require.cache[key].exports.onPossiblyUnhandledRejection) {
require.cache[key].exports
.onPossiblyUnhandledRejection(throwRejectedPromise)
}
}
function throwRejectedPromise (err) {
throw err
}
// I have to do this because sometimes I'm returning promises
// generated by "mydep" and ".then"-ing them in my tests — which
// means errors thrown by failed assertions in them will go to
// bluebird@X.Y.Z's unhandledRejection handler.
//
// At other times I'm returning promises from my own library, and
// errors that happen in those ".then" handlers will go to
// bluebird@M.N.O's unhandledRejection handler.
//
// Yes, `dedupe` can solve this for a lot of cases, but:
// - some folks pin deps and thus they're not dedupable
// - sometimes deps are dedupable, but different versions of npm
// will build different dep trees (npm@3 is great at flattening!
// but not all npms are equal in this regard.)
// - the other option is to wrap-ish all promises coming out of my
// library, which is ... kind of a no-go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment