| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  | const { expect } = require('chai') | 
					
						
							|  |  |  | const { BrowserWindow } = require('electron').remote | 
					
						
							| 
									
										
										
										
											2016-11-29 11:06:22 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  | const { emittedOnce } = require('./events-helpers') | 
					
						
							| 
									
										
										
										
											2018-06-21 16:43:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | exports.closeWindow = async (window = null, | 
					
						
							| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  |   { assertSingleWindow } = { assertSingleWindow: true }) => { | 
					
						
							| 
									
										
										
										
											2018-06-21 16:43:15 +02:00
										 |  |  |   const windowExists = (window !== null) && !window.isDestroyed() | 
					
						
							|  |  |  |   if (windowExists) { | 
					
						
							|  |  |  |     const isClosed = emittedOnce(window, 'closed') | 
					
						
							|  |  |  |     window.setClosable(true) | 
					
						
							|  |  |  |     window.close() | 
					
						
							|  |  |  |     await isClosed | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (assertSingleWindow) { | 
					
						
							|  |  |  |     expect(BrowserWindow.getAllWindows()).to.have.lengthOf(1) | 
					
						
							| 
									
										
										
										
											2016-08-03 12:47:53 -07:00
										 |  |  |   } | 
					
						
							|  |  |  | } |