diff --git a/internal/runner/jest.go b/internal/runner/jest.go index 79d376c..6f75a00 100644 --- a/internal/runner/jest.go +++ b/internal/runner/jest.go @@ -119,8 +119,8 @@ func (j Jest) Run(result *RunResult, testCases []plan.TestCase, retry bool) erro } } - for i := 0; i < report.NumRuntimeErrorTestSuites; i++ { - result.errors = append(result.errors, ErrOutsideOfTest) + if report.NumRuntimeErrorTestSuites > 0 { + result.error = fmt.Errorf("Jest failed with runtime error test suites") } return nil diff --git a/internal/runner/playwright.go b/internal/runner/playwright.go index edf7f65..59e8230 100644 --- a/internal/runner/playwright.go +++ b/internal/runner/playwright.go @@ -67,8 +67,8 @@ func (p Playwright) Run(result *RunResult, testCases []plan.TestCase, retry bool } } - for _, reportError := range report.Errors { - result.errors = append(result.errors, fmt.Errorf("Playwright error: %s", reportError.Message)) + if len(report.Errors) > 0 { + result.error = fmt.Errorf("Playwright failed with errors") } return nil diff --git a/internal/runner/rspec.go b/internal/runner/rspec.go index 16741e8..6a8a2bd 100644 --- a/internal/runner/rspec.go +++ b/internal/runner/rspec.go @@ -117,8 +117,8 @@ func (r Rspec) Run(result *RunResult, testCases []plan.TestCase, retry bool) err result.RecordTestResult(mapExampleToTestCase(example), status) } - for i := 0; i < report.Summary.ErrorsOutsideOfExamplesCount; i++ { - result.errors = append(result.errors, ErrOutsideOfTest) + if report.Summary.ErrorsOutsideOfExamplesCount > 0 { + result.error = fmt.Errorf("RSpec failed with errors outside of examples") } return nil diff --git a/internal/runner/run_result.go b/internal/runner/run_result.go index 5d88a5b..1365474 100644 --- a/internal/runner/run_result.go +++ b/internal/runner/run_result.go @@ -1,8 +1,6 @@ package runner import ( - "errors" - "github.com/buildkite/test-engine-client/internal/plan" ) @@ -20,8 +18,6 @@ const ( RunStatusUnknown RunStatus = "unknown" ) -var ErrOutsideOfTest = errors.New("errors outside of tests") - // RunResult is a struct to keep track the results of a test run. // It contains the logics to record test results, calculate the status of the run. type RunResult struct { @@ -30,7 +26,7 @@ type RunResult struct { // mutedTestLookup is a map containing the test identifiers of muted tests. // This list might contain tests that are not part of the current run (i.e. belong to a different node). mutedTestLookup map[string]bool - errors []error + error error } func NewRunResult(mutedTests []plan.TestCase) *RunResult { @@ -105,7 +101,7 @@ func (r *RunResult) MutedTests() []TestResult { // If there are failed tests, it returns RunStatusFailed. // Otherwise, it returns RunStatusPassed. func (r *RunResult) Status() RunStatus { - if len(r.errors) > 0 { + if r.error != nil { return RunStatusError } @@ -120,6 +116,10 @@ func (r *RunResult) Status() RunStatus { return RunStatusPassed } +func (r *RunResult) Error() error { + return r.error +} + type RunStatistics struct { Total int PassedOnFirstRun int diff --git a/internal/runner/run_result_test.go b/internal/runner/run_result_test.go index 6a05cef..1c1b44f 100644 --- a/internal/runner/run_result_test.go +++ b/internal/runner/run_result_test.go @@ -1,6 +1,7 @@ package runner import ( + "fmt" "slices" "strings" "testing" @@ -224,7 +225,7 @@ func TestRunStatus_Failed(t *testing.T) { func TestRunStatus_Error(t *testing.T) { r := NewRunResult([]plan.TestCase{}) - r.errors = append(r.errors, ErrOutsideOfTest) + r.error = fmt.Errorf("error") if r.Status() != RunStatusError { t.Errorf("Status() is %s, want %s", r.Status(), RunStatusError) } diff --git a/main.go b/main.go index 2592e98..08fffb6 100644 --- a/main.go +++ b/main.go @@ -130,13 +130,6 @@ func main() { } func printReport(runResult runner.RunResult) { - statistics := runResult.Statistics() - - if statistics.Total == 0 { - return - } - - // Print statistics fmt.Println("+++ ========== Buildkite Test Engine Report ==========") switch runResult.Status() { @@ -145,9 +138,12 @@ func printReport(runResult runner.RunResult) { case runner.RunStatusFailed: fmt.Println("❌ Some tests failed.") case runner.RunStatusError: - fmt.Println("🚨 Errors encountered outside of tests.") + fmt.Printf("🚨 %s\n", runResult.Error()) } + fmt.Println("") + // Print statistics + statistics := runResult.Statistics() data := [][]string{ {"Passed", "first run", strconv.Itoa(statistics.PassedOnFirstRun)}, {"Passed", "on retry", strconv.Itoa(statistics.PassedOnRetry)},