Skip to content

Commit f993c0e

Browse files
add compact test output with step descriptions
1 parent 20fc7e5 commit f993c0e

12 files changed

Lines changed: 266 additions & 57 deletions

File tree

checks/runner.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func CLIChecks(cliData api.CLIData, overrideBaseURL string, ch chan tea.Msg) (re
3030
// This is the magic of the initial message sent before executing the test
3131
if step.CLICommand != nil {
3232
ch <- messages.StartStepMsg{
33+
Description: step.Description,
3334
CMD: step.CLICommand.Command,
3435
TmdlQuery: step.CLICommand.StdoutFilterTmdl,
3536
NoPenaltyOnFail: step.NoPenaltyOnFail,
@@ -44,6 +45,7 @@ func CLIChecks(cliData api.CLIData, overrideBaseURL string, ch chan tea.Msg) (re
4445
interpolatedURL := InterpolateVariables(fullURL, variables)
4546

4647
ch <- messages.StartStepMsg{
48+
Description: step.Description,
4749
URL: interpolatedURL,
4850
Method: step.HTTPRequest.Request.Method,
4951
NoPenaltyOnFail: step.NoPenaltyOnFail,

client/lessons.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type CLIData struct {
2828
}
2929

3030
type CLIStep struct {
31+
Description string `yaml:"description"`
3132
CLICommand *CLIStepCLICommand `yaml:"cliCommand"`
3233
HTTPRequest *CLIStepHTTPRequest `yaml:"httpRequest"`
3334
NoPenaltyOnFail bool `yaml:"noPenaltyOnFail"`

cmd/localtest.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
func init() {
2121
rootCmd.AddCommand(localTestCmd)
22+
localTestCmd.Flags().BoolVarP(&verboseOutput, "verbose", "v", false, "show detailed output for every step")
2223
}
2324

2425
var localTestCmd = &cobra.Command{
@@ -46,7 +47,7 @@ func localTestHandler(cmd *cobra.Command, args []string) error {
4647
}
4748

4849
ch := make(chan tea.Msg, 1)
49-
finalise := render.StartRenderer(data, true, ch)
50+
finalise := render.StartRenderer(data, true, verboseOutput, ch)
5051

5152
cliResults := checks.CLIChecks(data, overrideBaseURL, ch)
5253
submissionEvent := checks.LocalSubmissionEvent(data, cliResults)

cmd/localtest_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ func TestReadLocalCLIDataAcceptsLessonDirectory(t *testing.T) {
1515
- darwin
1616
baseURLDefault: http://localhost:3000
1717
steps:
18-
- cliCommand:
18+
- description: Prints a greeting
19+
cliCommand:
1920
command: echo hello
2021
tests:
2122
- exitCode: 0
@@ -36,6 +37,9 @@ steps:
3637
if len(data.Steps) != 1 || data.Steps[0].CLICommand == nil {
3738
t.Fatalf("expected one CLI command step, got %#v", data.Steps)
3839
}
40+
if data.Steps[0].Description != "Prints a greeting" {
41+
t.Fatalf("Description = %q, want manifest description", data.Steps[0].Description)
42+
}
3943
if len(data.Steps[0].CLICommand.Tests[1].StdoutContainsAll) != 1 {
4044
t.Fatalf("expected stdoutContainsAll test to load")
4145
}

cmd/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ func init() {
88
rootCmd.AddCommand(runCmd)
99
runCmd.Flags().BoolVarP(&forceSubmit, "submit", "s", false, "shortcut flag to submit after running")
1010
runCmd.Flags().BoolVar(&debugSubmission, "debug", false, "log submission request/response debug output")
11+
runCmd.Flags().BoolVarP(&verboseOutput, "verbose", "v", false, "show detailed output for every step")
1112
}
1213

1314
// runCmd represents the run command

cmd/submit.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ import (
2020
var (
2121
forceSubmit bool
2222
debugSubmission bool
23+
verboseOutput bool
2324
)
2425

2526
func init() {
2627
rootCmd.AddCommand(submitCmd)
2728
submitCmd.Flags().BoolVar(&debugSubmission, "debug", false, "log submission request/response debug output")
29+
submitCmd.Flags().BoolVarP(&verboseOutput, "verbose", "v", false, "show detailed output for every step")
2830
}
2931

3032
// submitCmd represents the submit command
@@ -73,7 +75,7 @@ func submissionHandler(cmd *cobra.Command, args []string) error {
7375

7476
ch := make(chan tea.Msg, 1)
7577
// StartRenderer and returns immediately, finalise function blocks the execution until the renderer is closed.
76-
finalise := render.StartRenderer(data, isSubmit, ch)
78+
finalise := render.StartRenderer(data, isSubmit, verboseOutput, ch)
7779

7880
cliResults := checks.CLIChecks(data, overrideBaseURL, ch)
7981

messages/messages.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package messages
33
import api "github.com/bootdotdev/bootdev/client"
44

55
type StartStepMsg struct {
6+
Description string
67
CMD string
78
URL string
89
Method string

render/http.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,16 @@ func printHTTPRequestResult(result api.HTTPRequestResult) string {
5656
bytes := []byte(result.BodyString)
5757
contentType := http.DetectContentType(bytes)
5858
if contentType == "application/json" || strings.HasPrefix(contentType, "text/") {
59+
body := result.BodyString
5960
var unmarshalled any
6061
err := json.Unmarshal([]byte(result.BodyString), &unmarshalled)
6162
if err == nil {
6263
pretty, err := json.MarshalIndent(unmarshalled, "", " ")
6364
if err == nil {
64-
str.Write(pretty)
65-
} else {
66-
str.WriteString(result.BodyString)
65+
body = string(pretty)
6766
}
68-
} else {
69-
str.WriteString(result.BodyString)
7067
}
68+
str.WriteString(truncateVisualOutput(body))
7169
} else {
7270
fmt.Fprintf(
7371
&str,

render/models.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ type testModel struct {
1212
}
1313

1414
type stepModel struct {
15-
step string
15+
description string
16+
detail string
1617
passed *bool
1718
result *api.CLIStepResult
1819
finished bool
@@ -29,16 +30,18 @@ type rootModel struct {
2930
xpReward int
3031
xpBreakdown []api.XPBreakdownItem
3132
isSubmit bool
33+
verbose bool
3234
finalized bool
3335
clear bool
3436
}
3537

36-
func initModel(isSubmit bool) rootModel {
38+
func initModel(isSubmit bool, verbose bool) rootModel {
3739
s := spinner.New()
3840
s.Spinner = spinner.Dot
3941
return rootModel{
4042
spinner: s,
4143
isSubmit: isSubmit,
44+
verbose: verbose,
4245
steps: []stepModel{},
4346
}
4447
}

render/render.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package render
33
import (
44
"fmt"
55
"os"
6+
"strings"
67
"sync"
78

89
api "github.com/bootdotdev/bootdev/client"
@@ -42,15 +43,21 @@ func (m rootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
4243
return m, tea.Quit
4344

4445
case messages.StartStepMsg:
45-
step := fmt.Sprintf("Running: %s", msg.CMD)
46+
description := strings.TrimSpace(msg.Description)
47+
detail := fmt.Sprintf("Command: %s", msg.CMD)
4648
if msg.TmdlQuery != nil {
47-
step += fmt.Sprintf(" (TMDL query: '%s')", *msg.TmdlQuery)
49+
detail += fmt.Sprintf(" (TMDL query: '%s')", *msg.TmdlQuery)
4850
}
4951
if msg.CMD == "" {
50-
step = fmt.Sprintf("%s %s", msg.Method, msg.URL)
52+
detail = fmt.Sprintf("Request: %s %s", msg.Method, msg.URL)
53+
}
54+
if description == "" {
55+
description = strings.TrimPrefix(detail, "Command: ")
56+
description = strings.TrimPrefix(description, "Request: ")
5157
}
5258
m.steps = append(m.steps, stepModel{
53-
step: step,
59+
description: description,
60+
detail: detail,
5461
tests: []testModel{},
5562
noPenaltyOnFail: msg.NoPenaltyOnFail,
5663
})
@@ -97,9 +104,9 @@ func (m rootModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
97104
}
98105
}
99106

100-
func StartRenderer(data api.CLIData, isSubmit bool, ch chan tea.Msg) func(api.LessonSubmissionEvent) {
107+
func StartRenderer(data api.CLIData, isSubmit bool, verbose bool, ch chan tea.Msg) func(api.LessonSubmissionEvent) {
101108
var wg sync.WaitGroup
102-
p := tea.NewProgram(initModel(isSubmit), tea.WithoutSignalHandler())
109+
p := tea.NewProgram(initModel(isSubmit, verbose), tea.WithoutSignalHandler())
103110

104111
wg.Add(1)
105112
go func() {

0 commit comments

Comments
 (0)