Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spec: update auto-updater spec to expect #13237

Merged
merged 3 commits into from Jun 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 29 additions & 34 deletions spec/api-auto-updater-spec.js
@@ -1,6 +1,6 @@
const assert = require('assert')
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
Expand All @@ -20,18 +20,18 @@ describe('autoUpdater module', function () {
return done()
}

ipcRenderer.once('auto-updater-error', function (event, message) {
assert.equal(message, 'Update URL is not set')
ipcRenderer.once('auto-updater-error', (event, message) => {
expect(message).to.equal('Update URL is not set')
done()
})
autoUpdater.setFeedURL('')
autoUpdater.checkForUpdates()
})
})

describe('getFeedURL', function () {
it('returns a falsey value by default', function () {
assert.ok(!autoUpdater.getFeedURL())
describe('getFeedURL', () => {
it('returns a falsey value by default', () => {
expect(!autoUpdater.getFeedURL()).to.equal(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that using expect(value).to.equal(false) instead of expect(!value).to.equal(true) can make code clearer.

})

it('correctly fetches the previously set FeedURL', function (done) {
Expand All @@ -43,7 +43,7 @@ describe('autoUpdater module', function () {

const updateURL = 'https://fake-update.electron.io'
autoUpdater.setFeedURL(updateURL)
assert.equal(autoUpdater.getFeedURL(), updateURL)
expect(autoUpdater.getFeedURL()).to.equal(updateURL)
done()
})
})
Expand All @@ -62,26 +62,24 @@ describe('autoUpdater module', function () {

it('sets url successfully using old (url, headers) syntax', () => {
noThrow(() => autoUpdater.setFeedURL('http://electronjs.org', { header: 'val' }))
assert.equal(autoUpdater.getFeedURL(), 'http://electronjs.org')
expect(autoUpdater.getFeedURL()).to.equal('http://electronjs.org')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can that string be moved to a variable?

})

it('throws if no url is provided when using the old style', () => {
assert.throws(
() => autoUpdater.setFeedURL(),
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', () => {
noThrow(() => autoUpdater.setFeedURL({ url: 'http://mymagicurl.local' }))
assert.equal(autoUpdater.getFeedURL(), 'http://mymagicurl.local')
expect(autoUpdater.getFeedURL()).to.equal('http://mymagicurl.local')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable?

})

it('throws if no url is provided when using the new style', () => {
assert.throws(
() => autoUpdater.setFeedURL({ noUrl: 'lol' }),
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()
})
})

Expand All @@ -94,64 +92,61 @@ describe('autoUpdater module', function () {
}
})

it('emits an error when the application is unsigned', function (done) {
ipcRenderer.once('auto-updater-error', function (event, message) {
assert.equal(message, 'Could not get code signature for running application')
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', () => {
assert.doesNotThrow(
() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
isServerTypeError
)
).to.not.throw()
})

it('does not throw if json is the serverType', () => {
assert.doesNotThrow(
() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'default' }),
isServerTypeError
)
).to.not.throw()
})

it('does throw if an unknown string is the serverType', () => {
assert.throws(
() => autoUpdater.setFeedURL({ url: '', serverType: 'weow' }),
expect(() => autoUpdater.setFeedURL({ url: '', serverType: 'weow' }),
isServerTypeError
)
).to.throw()
})
})
})

describe('quitAndInstall', function () {
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', function (event, message) {
assert.equal(message, 'No update available, can\'t quit and install')
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', function () {
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', function (error) {
assert.equal(error instanceof Error, true)
assert.deepEqual(Object.getOwnPropertyNames(error), ['stack', 'message', 'name'])
autoUpdater.once('error', error => {
expect(error).to.be.an.instanceof(Error)
expect(Object.getOwnPropertyNames(error)).to.deep.equal(['stack', 'message', 'name'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might this be slightly more readable?

expect(error).to.have.all.keys(['message', 'name', 'stack'])

done()
})

Expand Down