rename and fix assoc. test
This commit is contained in:
parent
99d35f7786
commit
dc410efa36
2 changed files with 54 additions and 51 deletions
|
@ -11,20 +11,21 @@ const deprecate = function (oldName, newName, fn) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// The method is renamed.
|
// The method is renamed.
|
||||||
deprecate.rename = (object, oldName, newName) => {
|
// nota bene: newName should already exist and
|
||||||
console.log('we are here')
|
// oldName is being injected for compatibility with old code
|
||||||
|
deprecate.alias = function (object, deprecatedName, existingName) {
|
||||||
let warned = false
|
let warned = false
|
||||||
const newMethod = function () {
|
const newMethod = function () {
|
||||||
if (!(warned || process.noDeprecation)) {
|
if (!(warned || process.noDeprecation)) {
|
||||||
warned = true
|
warned = true
|
||||||
deprecate.warn(oldName, newName)
|
deprecate.warn(deprecatedName, existingName)
|
||||||
}
|
}
|
||||||
return this[newName].apply(this, arguments)
|
return this[existingName].apply(this, arguments)
|
||||||
}
|
}
|
||||||
if (typeof object === 'function') {
|
if (typeof object === 'function') {
|
||||||
object.prototype[oldName] = newMethod
|
object.prototype[deprecatedName] = newMethod
|
||||||
} else {
|
} else {
|
||||||
object[oldName] = newMethod
|
object[deprecatedName] = newMethod
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const assert = require('assert')
|
const assert = require('assert')
|
||||||
const {deprecations, deprecate, ipcRenderer} = require('electron')
|
const {deprecations, deprecate, nativeImage} = require('electron')
|
||||||
|
|
||||||
describe.only('deprecations', () => {
|
describe.only('deprecations', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -7,44 +7,53 @@ describe.only('deprecations', () => {
|
||||||
process.throwDeprecation = true
|
process.throwDeprecation = true
|
||||||
})
|
})
|
||||||
|
|
||||||
// it('allows a deprecation handler function to be specified', () => {
|
it('allows a deprecation handler function to be specified', () => {
|
||||||
// const messages = []
|
const messages = []
|
||||||
//
|
|
||||||
// deprecations.setHandler((message) => {
|
|
||||||
// messages.push(message)
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// deprecate.log('this is deprecated')
|
|
||||||
// assert.deepEqual(messages, ['this is deprecated'])
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// it('returns a deprecation handler after one is set', () => {
|
|
||||||
// const messages = []
|
|
||||||
//
|
|
||||||
// deprecations.setHandler((message) => {
|
|
||||||
// messages.push(message)
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// deprecate.log('this is deprecated')
|
|
||||||
// assert(typeof deprecations.getHandler() === 'function')
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// it('returns a deprecation warning', () => {
|
|
||||||
// const messages = []
|
|
||||||
//
|
|
||||||
// deprecations.setHandler((message) => {
|
|
||||||
// messages.push(message)
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// deprecate.warn('old', 'new')
|
|
||||||
// assert.deepEqual(messages, [`'old' is deprecated. Use 'new' instead.`])
|
|
||||||
// })
|
|
||||||
|
|
||||||
// it('throws an exception if no deprecation handler is specified', () => {
|
deprecations.setHandler((message) => {
|
||||||
// assert.throws(() => {
|
messages.push(message)
|
||||||
// deprecate.log('this is deprecated')
|
})
|
||||||
// }, /this is deprecated/)
|
|
||||||
// })
|
deprecate.log('this is deprecated')
|
||||||
|
assert.deepEqual(messages, ['this is deprecated'])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns a deprecation handler after one is set', () => {
|
||||||
|
const messages = []
|
||||||
|
|
||||||
|
deprecations.setHandler((message) => {
|
||||||
|
messages.push(message)
|
||||||
|
})
|
||||||
|
|
||||||
|
deprecate.log('this is deprecated')
|
||||||
|
assert(typeof deprecations.getHandler() === 'function')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns a deprecation warning', () => {
|
||||||
|
const messages = []
|
||||||
|
|
||||||
|
deprecations.setHandler((message) => {
|
||||||
|
messages.push(message)
|
||||||
|
})
|
||||||
|
|
||||||
|
deprecate.warn('old', 'new')
|
||||||
|
assert.deepEqual(messages, [`'old' is deprecated. Use 'new' instead.`])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renames a method', () => {
|
||||||
|
assert.equal(typeof nativeImage.createFromDataUrl, 'undefined')
|
||||||
|
assert.equal(typeof nativeImage.createFromDataURL, 'function')
|
||||||
|
|
||||||
|
deprecate.alias(nativeImage, 'createFromDataUrl', 'createFromDataURL')
|
||||||
|
|
||||||
|
assert.equal(typeof nativeImage.createFromDataUrl, 'function')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('throws an exception if no deprecation handler is specified', () => {
|
||||||
|
assert.throws(() => {
|
||||||
|
deprecate.log('this is deprecated')
|
||||||
|
}, /this is deprecated/)
|
||||||
|
})
|
||||||
|
|
||||||
// it('deprecates a property', () => {
|
// it('deprecates a property', () => {
|
||||||
// deprecate.property(object, property, method)
|
// deprecate.property(object, property, method)
|
||||||
|
@ -57,11 +66,4 @@ describe.only('deprecations', () => {
|
||||||
// it('forwards a method to member', () => {
|
// it('forwards a method to member', () => {
|
||||||
// deprecate.member(object, method, member)
|
// deprecate.member(object, method, member)
|
||||||
// })
|
// })
|
||||||
|
|
||||||
it('renames a method', () => {
|
|
||||||
assert(typeof ipcRenderer.sendSync === 'function')
|
|
||||||
assert(typeof ipcRenderer.sendChannelSync === 'undefined')
|
|
||||||
deprecate.rename(ipcRenderer, 'sendSync', 'sendChannelSync')
|
|
||||||
assert(typeof ipcRenderer.sendChannelSync === 'function')
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue