Skip to content

Commit 8b6460d

Browse files
committed
update shell.openExternal to promisified
1 parent 0cbd954 commit 8b6460d

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

packages/server/lib/gui/auth.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ const _launchNativeAuth = (loginUrl, sendMessage) => {
191191
openExternalAttempted = true
192192

193193
// wrap openExternal here in case `electron.shell` is not available (during tests)
194-
return Promise.fromCallback((cb) => {
195-
shell.openExternal(loginUrl, {}, cb)
194+
return Promise.try(() => {
195+
return shell.openExternal(loginUrl)
196196
})
197197
.catch((err) => {
198198
debug('Error launching native auth: %o', { err })

packages/server/test/unit/gui/auth_spec.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,23 @@ describe('lib/gui/auth', function () {
8888
})
8989

9090
it('returns a promise that is fulfilled when openExternal succeeds', function () {
91-
sinon.stub(electron.shell, 'openExternal').callsArg(2)
91+
sinon.stub(electron.shell, 'openExternal').resolves()
92+
const sendWarning = sinon.stub()
9293

93-
return auth._launchNativeAuth(REDIRECT_URL)
94+
return auth._launchNativeAuth(REDIRECT_URL, sendWarning)
9495
.then(() => {
95-
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL, {}, sinon.match.func)
96+
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL)
97+
expect(sendWarning).to.not.be.called
9698
})
9799
})
98100

99101
it('is still fulfilled when openExternal fails, but sendWarning is called', function () {
100-
sinon.stub(electron.shell, 'openExternal').callsArgWith(2, new Error)
102+
sinon.stub(electron.shell, 'openExternal').rejects(new Error)
101103
const sendWarning = sinon.stub()
102104

103105
return auth._launchNativeAuth(REDIRECT_URL, sendWarning)
104106
.then(() => {
105-
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL, {}, sinon.match.func)
107+
expect(electron.shell.openExternal).to.be.calledWithMatch(REDIRECT_URL)
106108
expect(sendWarning).to.be.calledWithMatch('warning', 'AUTH_COULD_NOT_LAUNCH_BROWSER', REDIRECT_URL)
107109
})
108110
})

0 commit comments

Comments
 (0)