Skip to content

Commit

Permalink
Use fmtElapsed on wall times, update on all events
Browse files Browse the repository at this point in the history
  • Loading branch information
zalenskivolt committed Apr 19, 2023
1 parent 1b3c41e commit b3a3394
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 5 additions & 2 deletions testjson/dotformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ func (d *dotFormatter) orderByLastUpdated(i, j int) bool {
}

func fmtDotElapsed(p *Package) string {
return fmtElapsed(p.Elapsed(), p.cached)
}

func fmtElapsed(elapsed time.Duration, cached bool) string {
f := func(v string) string {
return fmt.Sprintf(" %5s ", v)
}

elapsed := p.Elapsed()
switch {
case p.cached:
case cached:
return f("🖴 ")
case elapsed <= 0:
return f("")
Expand Down
14 changes: 9 additions & 5 deletions testjson/multipkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testjson

import (
"bufio"
"fmt"
"io"
"os"
"regexp"
Expand Down Expand Up @@ -112,8 +111,8 @@ func multiPkgNameFormat(out io.Writer, opts FormatOptions, withFailures, withWal
pkgTracker.col = 0

if withWallTime {
t := time.Since(pkgTracker.startTime).Round(time.Millisecond)
eventStr = fmt.Sprintf("%.3fs %s", float64(t.Milliseconds())/1000, eventStr)
elapsed := time.Since(pkgTracker.startTime).Round(time.Millisecond)
eventStr = fmtElapsed(elapsed, false) + eventStr
}
}
pkgTracker.lastPkg = pkgPath
Expand Down Expand Up @@ -153,13 +152,17 @@ func multiPkgNameFormat2(out io.Writer, opts FormatOptions, withFailures, withWa
}
}

pkgPath := RelativePackagePath(event.Package)

// Remove newline from shortFormatPackageEvent
eventStr := strings.TrimSuffix(shortFormatPackageEvent(opts, event, exec), "\n")
if eventStr == "" {
if p := pkgTracker.pkgs[pkgPath]; p != nil {
p.lastUpdate = time.Now()
}
return nil // pkgTracker.flush(writer, opts, exec, withWallTime) // nil
}

pkgPath := RelativePackagePath(event.Package)
pkgTracker.pkgs[pkgPath] = &pkgLine{
pkg: pkgPath,
event: event,
Expand Down Expand Up @@ -245,7 +248,8 @@ func (pt *PkgTracker) flush(writer *dotwriter.Writer, opts FormatOptions, exec *
lastUpdatePkg = p
}
}
eventStr = fmtDotElapsed(exec.Package(lastUpdatePkg.event.Package)) + eventStr
elapsed := lastUpdatePkg.lastUpdate.Sub(pt.startTime)
eventStr = fmtElapsed(elapsed, false) + eventStr
}
}
noColorStr := colorRe.ReplaceAllString(eventStr, "")
Expand Down

0 comments on commit b3a3394

Please sign in to comment.