2020-04-07 00:04:09 +00:00
|
|
|
import { autoUpdater } from 'electron/main';
|
2020-03-20 20:28:31 +00:00
|
|
|
import { expect } from 'chai';
|
2023-01-25 21:01:25 +00:00
|
|
|
import { ifit, ifdescribe } from './lib/spec-helpers';
|
2023-02-23 23:53:53 +00:00
|
|
|
import { once } from 'events';
|
2019-07-26 17:52:57 +00:00
|
|
|
|
|
|
|
ifdescribe(!process.mas)('autoUpdater module', function () {
|
|
|
|
describe('checkForUpdates', function () {
|
2020-06-30 22:10:36 +00:00
|
|
|
ifit(process.platform === 'win32')('emits an error on Windows if the feed URL is not set', async function () {
|
2023-02-23 23:53:53 +00:00
|
|
|
const errorEvent = once(autoUpdater, 'error');
|
2020-03-20 20:28:31 +00:00
|
|
|
autoUpdater.setFeedURL({ url: '' });
|
|
|
|
autoUpdater.checkForUpdates();
|
2020-06-30 22:10:36 +00:00
|
|
|
const [error] = await errorEvent;
|
|
|
|
expect(error.message).to.equal('Update URL is not set');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
|
|
|
describe('getFeedURL', () => {
|
|
|
|
it('returns an empty string by default', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(autoUpdater.getFeedURL()).to.equal('');
|
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
2020-06-30 22:10:36 +00:00
|
|
|
ifit(process.platform === 'win32')('correctly fetches the previously set FeedURL', function () {
|
2020-03-20 20:28:31 +00:00
|
|
|
const updateURL = 'https://fake-update.electron.io';
|
|
|
|
autoUpdater.setFeedURL({ url: updateURL });
|
|
|
|
expect(autoUpdater.getFeedURL()).to.equal(updateURL);
|
|
|
|
});
|
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
|
|
|
describe('setFeedURL', function () {
|
|
|
|
ifdescribe(process.platform === 'win32' || process.platform === 'darwin')('on Mac or Windows', () => {
|
|
|
|
it('sets url successfully using old (url, headers) syntax', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const url = 'http://electronjs.org';
|
2019-07-26 17:52:57 +00:00
|
|
|
try {
|
2020-03-20 20:28:31 +00:00
|
|
|
(autoUpdater.setFeedURL as any)(url, { header: 'val' });
|
2019-07-26 17:52:57 +00:00
|
|
|
} catch (err) { /* ignore */ }
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(autoUpdater.getFeedURL()).to.equal(url);
|
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
|
|
|
it('throws if no url is provided when using the old style', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(() => (autoUpdater.setFeedURL as any)()).to.throw('Expected an options object with a \'url\' property to be provided');
|
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
|
|
|
it('sets url successfully using new ({ url }) syntax', () => {
|
2020-03-20 20:28:31 +00:00
|
|
|
const url = 'http://mymagicurl.local';
|
2019-07-26 17:52:57 +00:00
|
|
|
try {
|
2020-03-20 20:28:31 +00:00
|
|
|
autoUpdater.setFeedURL({ url });
|
2019-07-26 17:52:57 +00:00
|
|
|
} catch (err) { /* ignore */ }
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(autoUpdater.getFeedURL()).to.equal(url);
|
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
|
|
|
it('throws if no url is provided when using the new style', () => {
|
2019-11-01 20:37:02 +00:00
|
|
|
expect(() => autoUpdater.setFeedURL({ noUrl: 'lol' } as any)
|
2020-03-20 20:28:31 +00:00
|
|
|
).to.throw('Expected options object to contain a \'url\' string property in setFeedUrl call');
|
|
|
|
});
|
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
2021-01-21 23:36:52 +00:00
|
|
|
ifdescribe(process.platform === 'darwin' && process.arch !== 'arm64')('on Mac', function () {
|
2020-06-30 22:10:36 +00:00
|
|
|
it('emits an error when the application is unsigned', async () => {
|
2023-02-23 23:53:53 +00:00
|
|
|
const errorEvent = once(autoUpdater, 'error');
|
2020-03-20 20:28:31 +00:00
|
|
|
autoUpdater.setFeedURL({ url: '' });
|
2020-06-30 22:10:36 +00:00
|
|
|
const [error] = await errorEvent;
|
|
|
|
expect(error.message).equal('Could not get code signature for running application');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
|
|
|
it('does not throw if default is the serverType', () => {
|
|
|
|
// "Could not get code signature..." means the function got far enough to validate that serverType was OK.
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'default' })).to.throw('Could not get code signature for running application');
|
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
|
|
|
it('does not throw if json is the serverType', () => {
|
|
|
|
// "Could not get code signature..." means the function got far enough to validate that serverType was OK.
|
2020-03-20 20:28:31 +00:00
|
|
|
expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'json' })).to.throw('Could not get code signature for running application');
|
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
|
|
|
it('does throw if an unknown string is the serverType', () => {
|
2020-07-20 16:51:33 +00:00
|
|
|
expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'weow' as any })).to.throw('Expected serverType to be \'default\' or \'json\'');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-07-26 17:52:57 +00:00
|
|
|
|
|
|
|
describe('quitAndInstall', () => {
|
2020-06-30 22:10:36 +00:00
|
|
|
ifit(process.platform === 'win32')('emits an error on Windows when no update is available', async function () {
|
2023-02-23 23:53:53 +00:00
|
|
|
const errorEvent = once(autoUpdater, 'error');
|
2020-03-20 20:28:31 +00:00
|
|
|
autoUpdater.quitAndInstall();
|
2020-06-30 22:10:36 +00:00
|
|
|
const [error] = await errorEvent;
|
|
|
|
expect(error.message).to.equal('No update available, can\'t quit and install');
|
2020-03-20 20:28:31 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|