refactor: remove unused, duplicated code in deprecate module (#14579)
* remove obsolete tests * remove unused deprecate API * make a warnOnce helper for the deprecate methods * misc. copyediting, e.g. variable names, whitespace * test that any deprecation warns once at most * use strict
This commit is contained in:
parent
d78a2a110a
commit
a3f7e298cf
3 changed files with 71 additions and 97 deletions
|
@ -1,6 +1,8 @@
|
|||
'use strict'
|
||||
|
||||
const chai = require('chai')
|
||||
const dirtyChai = require('dirty-chai')
|
||||
const {deprecations, deprecate, nativeImage} = require('electron')
|
||||
const {deprecations, deprecate} = require('electron')
|
||||
|
||||
const {expect} = chai
|
||||
chai.use(dirtyChai)
|
||||
|
@ -33,26 +35,6 @@ describe('deprecations', () => {
|
|||
expect(deprecations.getHandler()).to.be.a('function')
|
||||
})
|
||||
|
||||
it('returns a deprecation warning', () => {
|
||||
const messages = []
|
||||
|
||||
deprecations.setHandler(message => {
|
||||
messages.push(message)
|
||||
})
|
||||
|
||||
deprecate.warn('old', 'new')
|
||||
expect(messages).to.deep.equal([`'old' is deprecated. Use 'new' instead.`])
|
||||
})
|
||||
|
||||
it('renames a method', () => {
|
||||
expect(nativeImage.createFromDataUrl).to.be.undefined()
|
||||
expect(nativeImage.createFromDataURL).to.be.a('function')
|
||||
|
||||
deprecate.alias(nativeImage, 'createFromDataUrl', 'createFromDataURL')
|
||||
|
||||
expect(nativeImage.createFromDataUrl).to.be.a('function')
|
||||
})
|
||||
|
||||
it('renames a property', () => {
|
||||
let msg
|
||||
deprecations.setHandler(m => { msg = m })
|
||||
|
@ -80,8 +62,8 @@ describe('deprecations', () => {
|
|||
const o = {}
|
||||
|
||||
expect(() => {
|
||||
deprecate.removeProperty(o, 'iDontExist')
|
||||
}).to.throw(/Cannot deprecate a property on an object which does not have that property/)
|
||||
deprecate.removeProperty(o, 'iDoNotExist')
|
||||
}).to.throw(/iDoNotExist/)
|
||||
})
|
||||
|
||||
it('deprecates a property of an object', () => {
|
||||
|
@ -100,6 +82,21 @@ describe('deprecations', () => {
|
|||
expect(msg).to.include(prop)
|
||||
})
|
||||
|
||||
it('warns only once per item', () => {
|
||||
const messages = []
|
||||
deprecations.setHandler(message => { messages.push(message) })
|
||||
|
||||
const key = 'foo'
|
||||
const val = 'bar'
|
||||
let o = {[key]: val}
|
||||
deprecate.removeProperty(o, key)
|
||||
|
||||
for (let i = 0; i < 3; ++i) {
|
||||
expect(o[key]).to.equal(val)
|
||||
expect(messages).to.have.length(1)
|
||||
}
|
||||
})
|
||||
|
||||
it('warns if deprecated property is already set', () => {
|
||||
let msg
|
||||
deprecations.setHandler(m => { msg = m })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue