2018-06-19 15:22:08 +00:00
|
|
|
const chai = require('chai')
|
|
|
|
const dirtyChai = require('dirty-chai')
|
2017-11-14 19:56:16 +00:00
|
|
|
const {deprecations, deprecate, nativeImage} = require('electron')
|
2016-02-16 23:09:35 +00:00
|
|
|
|
2018-06-19 15:22:08 +00:00
|
|
|
const {expect} = chai
|
|
|
|
chai.use(dirtyChai)
|
|
|
|
|
2017-11-20 14:12:34 +00:00
|
|
|
describe('deprecations', () => {
|
2017-10-27 00:35:33 +00:00
|
|
|
beforeEach(() => {
|
2016-03-25 20:03:49 +00:00
|
|
|
deprecations.setHandler(null)
|
|
|
|
process.throwDeprecation = true
|
|
|
|
})
|
2016-02-16 23:09:35 +00:00
|
|
|
|
2017-11-14 19:56:16 +00:00
|
|
|
it('allows a deprecation handler function to be specified', () => {
|
|
|
|
const messages = []
|
2017-11-14 01:21:57 +00:00
|
|
|
|
2018-06-19 15:22:08 +00:00
|
|
|
deprecations.setHandler(message => {
|
2017-11-14 19:56:16 +00:00
|
|
|
messages.push(message)
|
|
|
|
})
|
|
|
|
|
|
|
|
deprecate.log('this is deprecated')
|
2018-06-19 15:22:08 +00:00
|
|
|
expect(messages).to.deep.equal(['this is deprecated'])
|
2017-11-14 19:56:16 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('returns a deprecation handler after one is set', () => {
|
|
|
|
const messages = []
|
|
|
|
|
2018-06-19 15:22:08 +00:00
|
|
|
deprecations.setHandler(message => {
|
2017-11-14 19:56:16 +00:00
|
|
|
messages.push(message)
|
|
|
|
})
|
|
|
|
|
|
|
|
deprecate.log('this is deprecated')
|
2018-06-19 15:22:08 +00:00
|
|
|
expect(deprecations.getHandler()).to.be.a('function')
|
2017-11-14 19:56:16 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('returns a deprecation warning', () => {
|
|
|
|
const messages = []
|
|
|
|
|
2018-06-19 15:22:08 +00:00
|
|
|
deprecations.setHandler(message => {
|
2017-11-14 19:56:16 +00:00
|
|
|
messages.push(message)
|
|
|
|
})
|
|
|
|
|
|
|
|
deprecate.warn('old', 'new')
|
2018-06-19 15:22:08 +00:00
|
|
|
expect(messages).to.deep.equal([`'old' is deprecated. Use 'new' instead.`])
|
2017-11-14 19:56:16 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('renames a method', () => {
|
2018-06-19 15:22:08 +00:00
|
|
|
expect(nativeImage.createFromDataUrl).to.be.undefined()
|
|
|
|
expect(nativeImage.createFromDataURL).to.be.a('function')
|
2017-11-14 19:56:16 +00:00
|
|
|
|
|
|
|
deprecate.alias(nativeImage, 'createFromDataUrl', 'createFromDataURL')
|
|
|
|
|
2018-06-19 15:22:08 +00:00
|
|
|
expect(nativeImage.createFromDataUrl).to.be.a('function')
|
2017-11-14 19:56:16 +00:00
|
|
|
})
|
|
|
|
|
2018-05-29 13:40:48 +00:00
|
|
|
it('renames a property', () => {
|
|
|
|
let msg
|
|
|
|
deprecations.setHandler((m) => { msg = m })
|
|
|
|
|
|
|
|
const oldPropertyName = 'dingyOldName'
|
|
|
|
const newPropertyName = 'shinyNewName'
|
|
|
|
|
|
|
|
let value = 0
|
|
|
|
let o = { [newPropertyName]: value }
|
2018-06-19 15:22:08 +00:00
|
|
|
expect(o).to.not.have.a.property(oldPropertyName)
|
|
|
|
expect(o).to.have.a.property(newPropertyName).that.is.a('number')
|
2018-05-29 13:40:48 +00:00
|
|
|
|
|
|
|
deprecate.property(o, oldPropertyName, newPropertyName)
|
|
|
|
o[oldPropertyName] = ++value
|
|
|
|
|
2018-06-19 15:22:08 +00:00
|
|
|
expect(msg).to.be.a('string')
|
|
|
|
expect(msg).to.include(oldPropertyName)
|
|
|
|
expect(msg).to.include(newPropertyName)
|
2018-05-29 13:40:48 +00:00
|
|
|
|
2018-06-19 15:22:08 +00:00
|
|
|
expect(o).to.have.a.property(newPropertyName).that.is.equal(value)
|
|
|
|
expect(o).to.have.a.property(oldPropertyName).that.is.equal(value)
|
2018-05-29 13:40:48 +00:00
|
|
|
})
|
|
|
|
|
2018-05-29 13:58:02 +00:00
|
|
|
it('warns if deprecated property is already set', () => {
|
|
|
|
let msg
|
|
|
|
deprecations.setHandler((m) => { msg = m })
|
|
|
|
|
|
|
|
const oldPropertyName = 'dingyOldName'
|
|
|
|
const newPropertyName = 'shinyNewName'
|
|
|
|
const value = 0
|
|
|
|
|
|
|
|
let o = { [oldPropertyName]: value }
|
|
|
|
deprecate.property(o, oldPropertyName, newPropertyName)
|
|
|
|
|
2018-06-19 15:22:08 +00:00
|
|
|
expect(msg).to.be.a('string')
|
|
|
|
expect(msg).to.include(oldPropertyName)
|
|
|
|
expect(msg).to.include(newPropertyName)
|
2018-05-29 13:58:02 +00:00
|
|
|
})
|
|
|
|
|
2017-11-14 19:56:16 +00:00
|
|
|
it('throws an exception if no deprecation handler is specified', () => {
|
2018-06-19 15:22:08 +00:00
|
|
|
expect(() => {
|
2017-11-14 19:56:16 +00:00
|
|
|
deprecate.log('this is deprecated')
|
2018-06-19 15:22:08 +00:00
|
|
|
}).to.throw(/this is deprecated/)
|
2017-11-14 19:56:16 +00:00
|
|
|
})
|
2016-03-25 20:03:49 +00:00
|
|
|
})
|