2016-03-25 19:57:49 +00:00
|
|
|
const assert = require('assert')
|
2017-04-21 22:12:08 +00:00
|
|
|
const {autoUpdater} = require('electron').remote
|
|
|
|
const {ipcRenderer} = require('electron')
|
2016-02-03 20:53:56 +00:00
|
|
|
|
2017-11-15 21:05:46 +00: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 03:00:36 +00:00
|
|
|
|
2017-11-15 21:05:46 +00: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()
|
|
|
|
}
|
|
|
|
|
|
|
|
ipcRenderer.once('auto-updater-error', function (event, message) {
|
|
|
|
assert.equal(message, 'Update URL is not set')
|
|
|
|
done()
|
2016-03-25 19:57:49 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
autoUpdater.setFeedURL('')
|
|
|
|
autoUpdater.checkForUpdates()
|
2016-03-25 19:57:49 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
2016-02-03 20:53:56 +00:00
|
|
|
|
2018-02-16 05:02:10 +00:00
|
|
|
describe('getFeedURL', function () {
|
|
|
|
it('returns a falsey value by default', function () {
|
|
|
|
assert.ok(!autoUpdater.getFeedURL())
|
|
|
|
})
|
|
|
|
|
|
|
|
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)
|
|
|
|
assert.equal(autoUpdater.getFeedURL(), updateURL)
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
describe('setFeedURL', function () {
|
2018-02-15 02:58:59 +00: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', () => {
|
|
|
|
noThrow(() => autoUpdater.setFeedURL('http://electronjs.org', { header: 'val' }))
|
|
|
|
assert.equal(autoUpdater.getFeedURL(), 'http://electronjs.org')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws if no url is provided when using the old style', () => {
|
|
|
|
assert.throws(
|
|
|
|
() => autoUpdater.setFeedURL(),
|
|
|
|
err => err.message.includes('Expected an options object with a \'url\' property to be provided') // eslint-disable-line
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sets url successfully using new ({ url }) syntax', () => {
|
|
|
|
noThrow(() => autoUpdater.setFeedURL({ url: 'http://mymagicurl.local' }))
|
|
|
|
assert.equal(autoUpdater.getFeedURL(), 'http://mymagicurl.local')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('throws if no url is provided when using the new style', () => {
|
|
|
|
assert.throws(
|
|
|
|
() => autoUpdater.setFeedURL({ noUrl: 'lol' }),
|
|
|
|
err => err.message.includes('Expected options object to contain a \'url\' string property in setFeedUrl call') // eslint-disable-line
|
|
|
|
)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
describe('on Mac', function () {
|
2018-02-15 02:58:59 +00:00
|
|
|
const isServerTypeError = (err) => err.message.includes('Expected serverType to be \'default\' or \'json\'')
|
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
before(function () {
|
2016-03-25 19:57:49 +00:00
|
|
|
if (process.platform !== 'darwin') {
|
2017-11-15 21:05:46 +00:00
|
|
|
this.skip()
|
2016-03-25 19:57:49 +00:00
|
|
|
}
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
2016-02-03 20:53:56 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
it('emits an error when the application is unsigned', function (done) {
|
2016-03-25 19:57:49 +00:00
|
|
|
ipcRenderer.once('auto-updater-error', function (event, message) {
|
|
|
|
assert.equal(message, 'Could not get code signature for running application')
|
|
|
|
done()
|
|
|
|
})
|
|
|
|
autoUpdater.setFeedURL('')
|
|
|
|
})
|
2018-02-15 02:58:59 +00:00
|
|
|
|
|
|
|
it('does not throw if default is the serverType', () => {
|
|
|
|
assert.doesNotThrow(
|
|
|
|
() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
|
|
|
|
isServerTypeError
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does not throw if json is the serverType', () => {
|
|
|
|
assert.doesNotThrow(
|
|
|
|
() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
|
|
|
|
isServerTypeError
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does throw if an unknown string is the serverType', () => {
|
|
|
|
assert.throws(
|
|
|
|
() => autoUpdater.setFeedURL({ url: '', serverType: 'weow' }),
|
|
|
|
isServerTypeError
|
|
|
|
)
|
|
|
|
})
|
2016-03-25 19:57:49 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
2016-07-14 22:13:41 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
describe('quitAndInstall', function () {
|
|
|
|
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 20:12:39 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
ipcRenderer.once('auto-updater-error', function (event, message) {
|
|
|
|
assert.equal(message, 'No update available, can\'t quit and install')
|
|
|
|
done()
|
2016-08-08 20:12:39 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
autoUpdater.quitAndInstall()
|
2016-08-08 20:12:39 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|
2017-04-21 22:12:08 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
describe('error event', function () {
|
|
|
|
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 23:50:19 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
autoUpdater.once('error', function (error) {
|
|
|
|
assert.equal(error instanceof Error, true)
|
|
|
|
assert.deepEqual(Object.getOwnPropertyNames(error), ['stack', 'message', 'name'])
|
|
|
|
done()
|
|
|
|
})
|
2017-04-21 22:12:08 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
autoUpdater.setFeedURL('')
|
2017-04-21 22:12:08 +00:00
|
|
|
|
2017-11-15 21:05:46 +00:00
|
|
|
if (process.platform === 'win32') {
|
|
|
|
autoUpdater.checkForUpdates()
|
|
|
|
}
|
2017-04-21 22:12:08 +00:00
|
|
|
})
|
2016-03-25 19:57:49 +00:00
|
|
|
})
|
2017-11-15 21:05:46 +00:00
|
|
|
})
|