| 
									
										
										
										
											2018-09-12 17:13:22 -05:00
										 |  |  | 'use strict' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 08:22:08 -07:00
										 |  |  | const chai = require('chai') | 
					
						
							|  |  |  | const dirtyChai = require('dirty-chai') | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  | const { deprecations, deprecate } = require('electron') | 
					
						
							| 
									
										
										
										
											2016-02-16 15:09:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  | const { expect } = chai | 
					
						
							| 
									
										
										
										
											2018-06-19 08:22:08 -07:00
										 |  |  | chai.use(dirtyChai) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 23:00:41 -07:00
										 |  |  | describe('deprecations', () => { | 
					
						
							| 
									
										
										
										
											2017-10-26 20:35:33 -04:00
										 |  |  |   beforeEach(() => { | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  |     deprecations.setHandler(null) | 
					
						
							|  |  |  |     process.throwDeprecation = true | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-02-16 15:09:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 14:56:16 -05:00
										 |  |  |   it('allows a deprecation handler function to be specified', () => { | 
					
						
							|  |  |  |     const messages = [] | 
					
						
							| 
									
										
										
										
											2017-11-13 20:21:57 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 08:22:08 -07:00
										 |  |  |     deprecations.setHandler(message => { | 
					
						
							| 
									
										
										
										
											2017-11-14 14:56:16 -05:00
										 |  |  |       messages.push(message) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     deprecate.log('this is deprecated') | 
					
						
							| 
									
										
										
										
											2018-06-19 08:22:08 -07:00
										 |  |  |     expect(messages).to.deep.equal(['this is deprecated']) | 
					
						
							| 
									
										
										
										
											2017-11-14 14:56:16 -05:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('returns a deprecation handler after one is set', () => { | 
					
						
							|  |  |  |     const messages = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 08:22:08 -07:00
										 |  |  |     deprecations.setHandler(message => { | 
					
						
							| 
									
										
										
										
											2017-11-14 14:56:16 -05:00
										 |  |  |       messages.push(message) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     deprecate.log('this is deprecated') | 
					
						
							| 
									
										
										
										
											2018-06-19 08:22:08 -07:00
										 |  |  |     expect(deprecations.getHandler()).to.be.a('function') | 
					
						
							| 
									
										
										
										
											2017-11-14 14:56:16 -05:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 15:40:48 +02:00
										 |  |  |   it('renames a property', () => { | 
					
						
							|  |  |  |     let msg | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     deprecations.setHandler(m => { msg = m }) | 
					
						
							| 
									
										
										
										
											2018-05-29 15:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     const oldProp = 'dingyOldName' | 
					
						
							|  |  |  |     const newProp = 'shinyNewName' | 
					
						
							| 
									
										
										
										
											2018-05-29 15:40:48 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     let value = 0 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |     const o = { [newProp]: value } | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     expect(o).to.not.have.a.property(oldProp) | 
					
						
							|  |  |  |     expect(o).to.have.a.property(newProp).that.is.a('number') | 
					
						
							| 
									
										
										
										
											2018-05-29 15:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     deprecate.renameProperty(o, oldProp, newProp) | 
					
						
							|  |  |  |     o[oldProp] = ++value | 
					
						
							| 
									
										
										
										
											2018-05-29 15:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 08:22:08 -07:00
										 |  |  |     expect(msg).to.be.a('string') | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     expect(msg).to.include(oldProp) | 
					
						
							|  |  |  |     expect(msg).to.include(newProp) | 
					
						
							| 
									
										
										
										
											2018-05-29 15:40:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     expect(o).to.have.a.property(newProp).that.is.equal(value) | 
					
						
							|  |  |  |     expect(o).to.have.a.property(oldProp).that.is.equal(value) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('doesn\'t deprecate a property not on an object', () => { | 
					
						
							|  |  |  |     const o = {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect(() => { | 
					
						
							| 
									
										
										
										
											2018-09-12 17:13:22 -05:00
										 |  |  |       deprecate.removeProperty(o, 'iDoNotExist') | 
					
						
							|  |  |  |     }).to.throw(/iDoNotExist/) | 
					
						
							| 
									
										
										
										
											2018-05-29 15:40:48 +02:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-26 23:47:01 -07:00
										 |  |  |   it('deprecates a property of an object', () => { | 
					
						
							|  |  |  |     let msg | 
					
						
							|  |  |  |     deprecations.setHandler(m => { msg = m }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     const prop = 'itMustGo' | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |     const o = { [prop]: 0 } | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     deprecate.removeProperty(o, prop) | 
					
						
							| 
									
										
										
										
											2018-06-26 23:47:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     const temp = o[prop] | 
					
						
							| 
									
										
										
										
											2018-06-26 23:47:01 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     expect(temp).to.equal(0) | 
					
						
							| 
									
										
										
										
											2018-06-26 23:47:01 -07:00
										 |  |  |     expect(msg).to.be.a('string') | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     expect(msg).to.include(prop) | 
					
						
							| 
									
										
										
										
											2018-06-26 23:47:01 -07:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-12 17:13:22 -05:00
										 |  |  |   it('warns only once per item', () => { | 
					
						
							|  |  |  |     const messages = [] | 
					
						
							|  |  |  |     deprecations.setHandler(message => { messages.push(message) }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const key = 'foo' | 
					
						
							|  |  |  |     const val = 'bar' | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |     const o = { [key]: val } | 
					
						
							| 
									
										
										
										
											2018-09-12 17:13:22 -05:00
										 |  |  |     deprecate.removeProperty(o, key) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (let i = 0; i < 3; ++i) { | 
					
						
							|  |  |  |       expect(o[key]).to.equal(val) | 
					
						
							|  |  |  |       expect(messages).to.have.length(1) | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-29 15:58:02 +02:00
										 |  |  |   it('warns if deprecated property is already set', () => { | 
					
						
							|  |  |  |     let msg | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     deprecations.setHandler(m => { msg = m }) | 
					
						
							| 
									
										
										
										
											2018-05-29 15:58:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     const oldProp = 'dingyOldName' | 
					
						
							|  |  |  |     const newProp = 'shinyNewName' | 
					
						
							| 
									
										
										
										
											2018-05-29 15:58:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-02 03:56:31 +02:00
										 |  |  |     const o = { [oldProp]: 0 } | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     deprecate.renameProperty(o, oldProp, newProp) | 
					
						
							| 
									
										
										
										
											2018-05-29 15:58:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-19 08:22:08 -07:00
										 |  |  |     expect(msg).to.be.a('string') | 
					
						
							| 
									
										
										
										
											2018-09-11 11:16:49 -07:00
										 |  |  |     expect(msg).to.include(oldProp) | 
					
						
							|  |  |  |     expect(msg).to.include(newProp) | 
					
						
							| 
									
										
										
										
											2018-05-29 15:58:02 +02:00
										 |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-14 14:56:16 -05:00
										 |  |  |   it('throws an exception if no deprecation handler is specified', () => { | 
					
						
							| 
									
										
										
										
											2018-06-19 08:22:08 -07:00
										 |  |  |     expect(() => { | 
					
						
							| 
									
										
										
										
											2017-11-14 14:56:16 -05:00
										 |  |  |       deprecate.log('this is deprecated') | 
					
						
							| 
									
										
										
										
											2018-06-19 08:22:08 -07:00
										 |  |  |     }).to.throw(/this is deprecated/) | 
					
						
							| 
									
										
										
										
											2017-11-14 14:56:16 -05:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-03-25 13:03:49 -07:00
										 |  |  | }) |