chore: remove unused promisify code (#21114)
This commit is contained in:
parent
457b7bf24f
commit
af1e8a347e
5 changed files with 1 additions and 156 deletions
|
@ -192,79 +192,4 @@ describe('deprecate', () => {
|
|||
expect(warnings[0]).to.equal('\'old\' is deprecated and will be removed. Please use \'new\' instead.')
|
||||
})
|
||||
})
|
||||
|
||||
describe('promisify', () => {
|
||||
const expected = 'Hello, world!'
|
||||
let promiseFunc: (param: any) => Promise<any>
|
||||
let warnings: string[]
|
||||
|
||||
const enableCallbackWarnings = () => {
|
||||
warnings = []
|
||||
deprecate.setHandler(warning => warnings.push(warning))
|
||||
process.enablePromiseAPIs = true
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
deprecate.setHandler(null)
|
||||
process.throwDeprecation = true
|
||||
|
||||
promiseFunc = param => new Promise((resolve) => resolve(param))
|
||||
})
|
||||
|
||||
it('acts as a pass-through for promise-based invocations', async () => {
|
||||
enableCallbackWarnings()
|
||||
promiseFunc = deprecate.promisify(promiseFunc)
|
||||
|
||||
const actual = await promiseFunc(expected)
|
||||
expect(actual).to.equal(expected)
|
||||
expect(warnings).to.have.lengthOf(0)
|
||||
})
|
||||
|
||||
it('only calls back an error if the callback is called with (err, data)', async () => {
|
||||
enableCallbackWarnings()
|
||||
const erringPromiseFunc = deprecate.promisify(
|
||||
() => new Promise((resolve, reject) => {
|
||||
reject(new Error('fail'))
|
||||
})
|
||||
)
|
||||
|
||||
{
|
||||
const [err, data] = await new Promise(resolve => {
|
||||
(erringPromiseFunc as any)((err: Error | undefined, data: any) => {
|
||||
resolve([err, data])
|
||||
}).catch(() => { /* silence deprecation warning */ })
|
||||
})
|
||||
expect(data).to.be.undefined()
|
||||
expect(err).to.be.an.instanceOf(Error).with.property('message', 'fail')
|
||||
}
|
||||
{
|
||||
const data = await new Promise(resolve => {
|
||||
(erringPromiseFunc as any)((data: any) => { resolve(data) })
|
||||
.catch(() => { /* silence deprecation warning */ })
|
||||
})
|
||||
expect(data).to.be.undefined()
|
||||
}
|
||||
})
|
||||
|
||||
it('warns exactly once for callback-based invocations', (done) => {
|
||||
enableCallbackWarnings()
|
||||
promiseFunc = deprecate.promisify(promiseFunc)
|
||||
|
||||
let callbackCount = 0
|
||||
const invocationCount = 3
|
||||
const callback = (actual: number) => {
|
||||
expect(actual).to.equal(expected)
|
||||
expect(warnings).to.have.lengthOf(1)
|
||||
expect(warnings[0]).to.include('promiseFunc')
|
||||
callbackCount += 1
|
||||
if (callbackCount === invocationCount) {
|
||||
done()
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < invocationCount; i += 1) {
|
||||
(promiseFunc as any)(expected, callback)
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue