| 
									
										
										
										
											2018-09-14 02:10:51 +10:00
										 |  |  | const { autoUpdater } = require('electron').remote | 
					
						
							|  |  |  | const { ipcRenderer } = require('electron') | 
					
						
							|  |  |  | const { expect } = require('chai') | 
					
						
							| 
									
										
										
										
											2016-02-03 12:53:56 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  | describe('autoUpdater module', function () { | 
					
						
							|  |  |  |   // XXX(alexeykuzmin): Calling `.skip()` in a 'before' hook
 | 
					
						
							|  |  |  |   // doesn't affect nested 'describe's
 | 
					
						
							|  |  |  |   beforeEach(function () { | 
					
						
							|  |  |  |     // Skip autoUpdater tests in MAS build.
 | 
					
						
							|  |  |  |     if (process.mas) { | 
					
						
							|  |  |  |       this.skip() | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-02-16 11:00:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |   describe('checkForUpdates', function () { | 
					
						
							|  |  |  |     it('emits an error on Windows when called the feed URL is not set', function (done) { | 
					
						
							|  |  |  |       if (process.platform !== 'win32') { | 
					
						
							|  |  |  |         // FIXME(alexeykuzmin): Skip the test.
 | 
					
						
							|  |  |  |         // this.skip()
 | 
					
						
							|  |  |  |         return done() | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |       ipcRenderer.once('auto-updater-error', (event, message) => { | 
					
						
							|  |  |  |         expect(message).to.equal('Update URL is not set') | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |         done() | 
					
						
							| 
									
										
										
										
											2016-03-25 12:57:49 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |       autoUpdater.setFeedURL('') | 
					
						
							|  |  |  |       autoUpdater.checkForUpdates() | 
					
						
							| 
									
										
										
										
											2016-03-25 12:57:49 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-02-03 12:53:56 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |   describe('getFeedURL', () => { | 
					
						
							|  |  |  |     it('returns a falsey value by default', () => { | 
					
						
							|  |  |  |       expect(autoUpdater.getFeedURL()).to.equal('') | 
					
						
							| 
									
										
										
										
											2018-02-16 16:02:10 +11:00
										 |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     it('correctly fetches the previously set FeedURL', function (done) { | 
					
						
							|  |  |  |       if (process.platform !== 'win32') { | 
					
						
							|  |  |  |         // FIXME(alexeykuzmin): Skip the test.
 | 
					
						
							|  |  |  |         // this.skip()
 | 
					
						
							|  |  |  |         return done() | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       const updateURL = 'https://fake-update.electron.io' | 
					
						
							|  |  |  |       autoUpdater.setFeedURL(updateURL) | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |       expect(autoUpdater.getFeedURL()).to.equal(updateURL) | 
					
						
							| 
									
										
										
										
											2018-02-16 16:02:10 +11:00
										 |  |  |       done() | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |   describe('setFeedURL', function () { | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |     describe('on Mac or Windows', () => { | 
					
						
							|  |  |  |       const noThrow = (fn) => { | 
					
						
							|  |  |  |         try { fn() } catch (err) {} | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       before(function () { | 
					
						
							|  |  |  |         if (process.platform !== 'win32' && process.platform !== 'darwin') { | 
					
						
							|  |  |  |           this.skip() | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('sets url successfully using old (url, headers) syntax', () => { | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         const url = 'http://electronjs.org' | 
					
						
							|  |  |  |         noThrow(() => autoUpdater.setFeedURL(url, { header: 'val' })) | 
					
						
							|  |  |  |         expect(autoUpdater.getFeedURL()).to.equal(url) | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('throws if no url is provided when using the old style', () => { | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         expect(() => autoUpdater.setFeedURL(), | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |           err => err.message.includes('Expected an options object with a \'url\' property to be provided') // eslint-disable-line
 | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         ).to.throw() | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('sets url successfully using new ({ url }) syntax', () => { | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         const url = 'http://mymagicurl.local' | 
					
						
							|  |  |  |         noThrow(() => autoUpdater.setFeedURL({ url })) | 
					
						
							|  |  |  |         expect(autoUpdater.getFeedURL()).to.equal(url) | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('throws if no url is provided when using the new style', () => { | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         expect(() => autoUpdater.setFeedURL({ noUrl: 'lol' }), | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |           err => err.message.includes('Expected options object to contain a \'url\' string property in setFeedUrl call') // eslint-disable-line
 | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         ).to.throw() | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |       }) | 
					
						
							|  |  |  |     }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |     describe('on Mac', function () { | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |       const isServerTypeError = (err) => err.message.includes('Expected serverType to be \'default\' or \'json\'') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |       before(function () { | 
					
						
							| 
									
										
										
										
											2016-03-25 12:57:49 -07:00
										 |  |  |         if (process.platform !== 'darwin') { | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |           this.skip() | 
					
						
							| 
									
										
										
										
											2016-03-25 12:57:49 -07:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-02-03 12:53:56 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |       it('emits an error when the application is unsigned', done => { | 
					
						
							|  |  |  |         ipcRenderer.once('auto-updater-error', (event, message) => { | 
					
						
							|  |  |  |           expect(message).equal('Could not get code signature for running application') | 
					
						
							| 
									
										
										
										
											2016-03-25 12:57:49 -07:00
										 |  |  |           done() | 
					
						
							|  |  |  |         }) | 
					
						
							|  |  |  |         autoUpdater.setFeedURL('') | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('does not throw if default is the serverType', () => { | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }), | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |           isServerTypeError | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         ).to.not.throw() | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('does not throw if json is the serverType', () => { | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }), | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |           isServerTypeError | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         ).to.not.throw() | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |       }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('does throw if an unknown string is the serverType', () => { | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'weow' }), | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |           isServerTypeError | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |         ).to.throw() | 
					
						
							| 
									
										
										
										
											2018-02-15 13:58:59 +11:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2016-03-25 12:57:49 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2016-07-15 10:13:41 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |   describe('quitAndInstall', () => { | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |     it('emits an error on Windows when no update is available', function (done) { | 
					
						
							|  |  |  |       if (process.platform !== 'win32') { | 
					
						
							|  |  |  |         // FIXME(alexeykuzmin): Skip the test.
 | 
					
						
							|  |  |  |         // this.skip()
 | 
					
						
							|  |  |  |         return done() | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2016-08-08 13:12:39 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |       ipcRenderer.once('auto-updater-error', (event, message) => { | 
					
						
							|  |  |  |         expect(message).to.equal('No update available, can\'t quit and install') | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |         done() | 
					
						
							| 
									
										
										
										
											2016-08-08 13:12:39 -07:00
										 |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |       autoUpdater.quitAndInstall() | 
					
						
							| 
									
										
										
										
											2016-08-08 13:12:39 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-04-21 15:12:08 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |   describe('error event', () => { | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |     it('serializes correctly over the remote module', function (done) { | 
					
						
							|  |  |  |       if (process.platform === 'linux') { | 
					
						
							|  |  |  |         // FIXME(alexeykuzmin): Skip the test.
 | 
					
						
							|  |  |  |         // this.skip()
 | 
					
						
							|  |  |  |         return done() | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-04-21 16:50:19 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-16 00:28:28 -07:00
										 |  |  |       autoUpdater.once('error', error => { | 
					
						
							|  |  |  |         expect(error).to.be.an.instanceof(Error) | 
					
						
							|  |  |  |         expect(Object.getOwnPropertyNames(error)).to.deep.equal(['stack', 'message', 'name']) | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |         done() | 
					
						
							|  |  |  |       }) | 
					
						
							| 
									
										
										
										
											2017-04-21 15:12:08 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |       autoUpdater.setFeedURL('') | 
					
						
							| 
									
										
										
										
											2017-04-21 15:12:08 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  |       if (process.platform === 'win32') { | 
					
						
							|  |  |  |         autoUpdater.checkForUpdates() | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2017-04-21 15:12:08 -07:00
										 |  |  |     }) | 
					
						
							| 
									
										
										
										
											2016-03-25 12:57:49 -07:00
										 |  |  |   }) | 
					
						
							| 
									
										
										
										
											2017-11-16 00:05:46 +03:00
										 |  |  | }) |