Skip to content

Commit

Permalink
chore(cli): add output for waiting logs (#3066)
Browse files Browse the repository at this point in the history
* Add output for waiting logs

* Update log-displayer & tests

* Update log-displayer

* Update tests
  • Loading branch information
zwhitfield3 authored Nov 4, 2024
1 parent 5f62279 commit cbe1790
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/cli/src/lib/run/log-displayer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {APIClient} from '@heroku-cli/command'
import {ux} from '@oclif/core'
import color from '@heroku-cli/color'
import colorize from './colorize'
import {isFirApp} from '../apps/generation'
import {LogSession} from '../types/fir'
Expand Down Expand Up @@ -74,17 +75,19 @@ async function logDisplayer(heroku: APIClient, options: LogDisplayerOptions) {
source: options.source,
}

if (firApp)
if (firApp) {
process.stderr.write(color.cyan.bold('Fetching logs...\n\n'))
Object.assign(requestBodyParameters, {
dyno: options.dyno,
type: options.type,
})
else
} else {
Object.assign(requestBodyParameters, {
dyno: options.dyno || options.type,
lines: options.lines,
tail: options.tail,
})
}

let recreateLogSession = false
do {
Expand Down
7 changes: 6 additions & 1 deletion packages/cli/test/unit/lib/run/log-displayer.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Config} from '@oclif/core'
import {CLIError} from '@oclif/core/lib/errors'
import {expect} from 'chai'
import * as nock from 'nock'
import {stdout} from 'stdout-stderr'
import {stdout, stderr} from 'stdout-stderr'
import heredoc from 'tsheredoc'
import logDisplayer from '../../../../src/lib/run/log-displayer'
import {cedarApp, firApp} from '../../../fixtures/apps/fixtures'
Expand Down Expand Up @@ -380,12 +380,14 @@ describe('logDisplayer', function () {

try {
stdout.start()
stderr.start()
await logDisplayer(heroku, {
app: 'my-fir-app',
tail: false,
})
} catch (error: unknown) {
stdout.stop()
stderr.stop()
const {message} = error as Error
expect(message.trim()).to.equal('HTTP Error 500 for POST https://api.heroku.com/apps/my-fir-app/log-sessions')
}
Expand All @@ -403,6 +405,9 @@ describe('logDisplayer', function () {

logSession1.done()
logSession2.done()

// it displays message about fetching logs for fir apps
expect(stderr.output).to.eq('Fetching logs...\n\n')
})
})
})

0 comments on commit cbe1790

Please sign in to comment.