Skip to content

Commit b69e55f

Browse files
fix fallback url message formating (#303)
1 parent bb06c15 commit b69e55f

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

src/login.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class Login {
184184
urlDisplayed = true
185185
}
186186

187-
ux.warn(`If browser does not open, visit ${ansis.greenBright(url)}`)
187+
this.showManualBrowserLoginUrl(url)
188188
const cp = await open(url, {wait: false, ...(browser ? {app: {name: browser}} : {})})
189189
cp.on('error', err => {
190190
ux.warn(err)
@@ -360,4 +360,9 @@ machine, please manually open the URL above in your browser.\n`,
360360
password,
361361
}
362362
}
363+
364+
private showManualBrowserLoginUrl(url: string) {
365+
ux.warn('If browser does not open, visit:')
366+
ux.stderr(ansis.greenBright(url))
367+
}
363368
}

test/login.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import {Config} from '@oclif/core'
1+
import {Config, ux} from '@oclif/core'
2+
import ansis from 'ansis'
23
import {expect, fancy} from 'fancy-test'
34
import inquirer from 'inquirer'
45
import nock from 'nock'
@@ -7,6 +8,7 @@ import {fileURLToPath} from 'node:url'
78
import * as sinon from 'sinon'
89

910
import {Command as CommandBase} from '../src/command.js'
11+
import {Login} from '../src/login.js'
1012
import {restoreNetrcStub, stubNetrc} from './helpers/netrc-stub.js'
1113

1214
class Command extends CommandBase {
@@ -123,3 +125,22 @@ describe('login with interactive', () => {
123125
})
124126
})
125127
})
128+
129+
describe('login with browser', () => {
130+
test
131+
.it('prints fallback URL on its own line', async ctx => {
132+
const cmd = new Command([], ctx.config)
133+
const login = new Login(ctx.config, cmd.heroku)
134+
const warnStub = sinon.stub(ux, 'warn')
135+
const stderrStub = sinon.stub(ux, 'stderr')
136+
const url = 'https://cli-auth.heroku.com/auth/cli/browser/abc123?requestor=xyz'
137+
138+
const showManualBrowserLoginUrl = (login as any).showManualBrowserLoginUrl.bind(login)
139+
showManualBrowserLoginUrl(url)
140+
141+
expect(warnStub.calledWithExactly('If browser does not open, visit:')).to.equal(true)
142+
expect(warnStub.firstCall.args[0]).to.not.contain(url)
143+
expect(stderrStub.calledWithExactly(ansis.greenBright(url))).to.equal(true)
144+
sinon.assert.callOrder(warnStub, stderrStub)
145+
})
146+
})

0 commit comments

Comments
 (0)