forked from electron/electron
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapi-auto-updater-spec.js
162 lines (138 loc) · 5 KB
/
api-auto-updater-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
const { autoUpdater } = require('electron').remote
const { ipcRenderer } = require('electron')
const { expect } = require('chai')
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()
}
})
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', (event, message) => {
expect(message).to.equal('Update URL is not set')
done()
})
autoUpdater.setFeedURL('')
autoUpdater.checkForUpdates()
})
})
describe('getFeedURL', () => {
it('returns a falsey value by default', () => {
expect(autoUpdater.getFeedURL()).to.equal('')
})
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)
expect(autoUpdater.getFeedURL()).to.equal(updateURL)
done()
})
})
describe('setFeedURL', function () {
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', () => {
const url = 'http://electronjs.org'
noThrow(() => autoUpdater.setFeedURL(url, { header: 'val' }))
expect(autoUpdater.getFeedURL()).to.equal(url)
})
it('throws if no url is provided when using the old style', () => {
expect(() => autoUpdater.setFeedURL(),
err => err.message.includes('Expected an options object with a \'url\' property to be provided') // eslint-disable-line
).to.throw()
})
it('sets url successfully using new ({ url }) syntax', () => {
const url = 'http://mymagicurl.local'
noThrow(() => autoUpdater.setFeedURL({ url }))
expect(autoUpdater.getFeedURL()).to.equal(url)
})
it('throws if no url is provided when using the new style', () => {
expect(() => autoUpdater.setFeedURL({ noUrl: 'lol' }),
err => err.message.includes('Expected options object to contain a \'url\' string property in setFeedUrl call') // eslint-disable-line
).to.throw()
})
})
describe('on Mac', function () {
const isServerTypeError = (err) => err.message.includes('Expected serverType to be \'default\' or \'json\'')
before(function () {
if (process.platform !== 'darwin') {
this.skip()
}
})
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')
done()
})
autoUpdater.setFeedURL('')
})
it('does not throw if default is the serverType', () => {
expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
isServerTypeError
).to.not.throw()
})
it('does not throw if json is the serverType', () => {
expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
isServerTypeError
).to.not.throw()
})
it('does throw if an unknown string is the serverType', () => {
expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'weow' }),
isServerTypeError
).to.throw()
})
})
})
describe('quitAndInstall', () => {
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()
}
ipcRenderer.once('auto-updater-error', (event, message) => {
expect(message).to.equal('No update available, can\'t quit and install')
done()
})
autoUpdater.quitAndInstall()
})
})
describe('error event', () => {
it('serializes correctly over the remote module', function (done) {
if (process.platform === 'linux') {
// FIXME(alexeykuzmin): Skip the test.
// this.skip()
return done()
}
autoUpdater.once('error', error => {
expect(error).to.be.an.instanceof(Error)
expect(Object.getOwnPropertyNames(error)).to.deep.equal(['stack', 'message', 'name'])
done()
})
autoUpdater.setFeedURL('')
if (process.platform === 'win32') {
autoUpdater.checkForUpdates()
}
})
})
})