Skip to content

Commit

Permalink
fix(log): no cli time on relax error
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Jun 11, 2024
1 parent 565d8ea commit c966f5e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/log/lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const format_line = function ({ host, header, status, time }, config) {
header,
config.separator.header,
status,
config.time ? config.separator.time : "",
time && config.time ? config.separator.time : "",
time,
].join("");
].filter(Boolean).join("");
};

// Action
Expand Down Expand Up @@ -123,10 +123,12 @@ export default {
}
const headers = get_headers(action);
let line = format_line({
// error in relax mode don't yet have ssh inherited
host: config.host ?? action.ssh?.config?.host ?? "local",
header: headers.join(config.divider),
status: status,
time: config.time
// error in relax mode don't set time_start
time: config.time && action.metadata.time_start
? utils.string.print_time(
action.metadata.time_end - action.metadata.time_start
)
Expand Down
29 changes: 29 additions & 0 deletions packages/log/test/cli.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,35 @@ describe 'log.cli', ->
data[0].should.match /h1 - 1\d{2}ms\n/
data[1].should.match /h2 : h3 - 1\d{2}ms\n/
data[2].should.match /h2 - 2\d{2}ms\n/

they 'config.time with relax error', ({ssh}) ->
data = []
nikita
$ssh: ssh
, ->
await @log.cli
stream: new MyWritable data
colors: false
await @call $header: 'h1', ->
await @wait 100
await @call $header: 'h2', ->
await @call $header: 'h3', $relax: true, ->
throw Error 'Its ok, keep relaxing'
await @call $header: 'h4', $relax: true, 'invalid module'
await @wait 100
await @call ->
# Check time
data[0].should.match /h1 - 1\d{2}ms\n/
data[1].should.match /h2 : h3 ✘ \dms\n/
data[2].should.match /h2 : h4 ✘\n/
data[3].should.match /h2 - \d{3}ms\n/
# Check hostname
# relax error with invalid module is only run locally
host = ssh?.host or 'local'
data[0].split(' ')[0].should.eql host
data[1].split(' ')[0].should.eql host
data[2].split(' ')[0].should.eql 'local'
data[3].split(' ')[0].should.eql host

describe 'session events', ->

Expand Down

0 comments on commit c966f5e

Please sign in to comment.