util-promisifyall
Advanced tools
Comparing version 1.0.2 to 1.0.3
11
index.js
const { promisify } = require('util') | ||
const functionBlackListMap = | ||
Object.getOwnPropertyNames(Object.prototype) | ||
.reduce(function (map, functionName) { | ||
map[functionName] = true | ||
return map | ||
}, {}); | ||
function _promisifyAllFunctions (object) { | ||
for (const key of Object.getOwnPropertyNames(object)) { | ||
if (functionBlackListMap[key]) { | ||
continue; | ||
} | ||
const descriptor = Object.getOwnPropertyDescriptor(object, key) | ||
@@ -6,0 +17,0 @@ |
{ | ||
"name": "util-promisifyall", | ||
"version": "1.0.2", | ||
"version": "1.0.3", | ||
"description": "promisifyAll with node's native promisify function", | ||
@@ -30,5 +30,4 @@ "main": "index.js", | ||
"mocha": "^3.4.2", | ||
"nyc": "^11.0.2", | ||
"redis": "^2.8.0" | ||
"nyc": "^11.0.2" | ||
} | ||
} |
const assert = require('assert') | ||
const Redis = require('redis') | ||
@@ -49,2 +48,23 @@ const promisifyAll = require('../index') | ||
it('should not promisify any functions on the default object prototype', () => { | ||
class MyClass { | ||
someFunc (input, callback) { | ||
callback(null, input) | ||
} | ||
someOtherFunc (input, callback) { | ||
callback(null, input) | ||
} | ||
} | ||
const NewClass = promisifyAll(MyClass.prototype) | ||
const propertyNames = Object.getOwnPropertyNames(Object.prototype) | ||
for (const key in Object.getPrototypeOf(NewClass)) { | ||
const asyncName = key + 'Async' | ||
assert(propertyNames.indexOf(asyncName) === -1, | ||
`Error: class prototype should not contain ${asyncName}`) | ||
} | ||
}) | ||
context('when directly promisifing a prototype', () => { | ||
@@ -51,0 +71,0 @@ it('should all functions defined on an object\'s prototype', async () => { |
5097
3
122
5