From bcab9c84b1beb13a8cd95216a09ffbe27f1047b7 Mon Sep 17 00:00:00 2001 From: Onsi Fakhouri Date: Tue, 29 Oct 2024 14:33:08 -0600 Subject: [PATCH] add GINKGO_NO_COLOR to disable colors via environment variables --- docs/index.md | 2 +- formatter/formatter.go | 4 ++++ types/config.go | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/index.md b/docs/index.md index 2eec98e31..a8762aa8b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -3445,7 +3445,7 @@ When you [filter specs](#filtering-specs) using Ginkgo's various filtering mecha #### Other Settings Here are a grab bag of other settings: -You can disable Ginkgo's color output by running `ginkgo --no-color`. +You can disable Ginkgo's color output by running `ginkgo --no-color` or setting the `GINKGO_NO_COLOR=TRUE` environment variable. You can also output in a format that makes it easier to read in github actions console by running `ginkgo --github-output`. By default, Ginkgo only emits full stack traces when a spec panics. When a normal assertion failure occurs, Ginkgo simply emits the line at which the failure occurred. You can, instead, have Ginkgo always emit the full stack trace by running `ginkgo --trace`. diff --git a/formatter/formatter.go b/formatter/formatter.go index 743555dde..4d5749114 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -82,6 +82,10 @@ func New(colorMode ColorMode) Formatter { return fmt.Sprintf("\x1b[38;5;%dm", colorCode) } + if _, noColor := os.LookupEnv("GINKGO_NO_COLOR"); noColor { + colorMode = ColorModeNone + } + f := Formatter{ ColorMode: colorMode, colors: map[string]string{ diff --git a/types/config.go b/types/config.go index 97a049e0c..8c0dfab8c 100644 --- a/types/config.go +++ b/types/config.go @@ -328,7 +328,7 @@ var ParallelConfigFlags = GinkgoFlags{ // ReporterConfigFlags provides flags for the Ginkgo test process, and CLI var ReporterConfigFlags = GinkgoFlags{ {KeyPath: "R.NoColor", Name: "no-color", SectionKey: "output", DeprecatedName: "noColor", DeprecatedDocLink: "changed-command-line-flags", - Usage: "If set, suppress color output in default reporter."}, + Usage: "If set, suppress color output in default reporter. You can also set the environment variable GINKGO_NO_COLOR=TRUE"}, {KeyPath: "R.Verbose", Name: "v", SectionKey: "output", Usage: "If set, emits more output including GinkgoWriter contents."}, {KeyPath: "R.VeryVerbose", Name: "vv", SectionKey: "output",