Skip to content

Commit

Permalink
Console reporter should look at full path when deciding whether to pr…
Browse files Browse the repository at this point in the history
…int suite (#145)
  • Loading branch information
fsoikin committed Sep 6, 2023
1 parent 7374a4c commit c66a79d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module Test.Main where

import Prelude

import Effect (Effect)
import Effect.Aff (launchAff_)
import Test.Spec (describe, it)
import Test.Spec.Config (defaultConfig)
import Test.Spec.Reporter (consoleReporter)
import Test.Spec.Runner (runSpec')

main :: Effect Unit
main = launchAff_ $ runSpec' defaultConfig [consoleReporter] do
describe "A" do
it "should be under A" (pure unit)
describe "B" do
it "should be under B" (pure unit)
describe "C" do
it "should be under C" (pure unit)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[1;35mA[0m
[32m✓︎ [0m[2mshould be under A[0m
[1;35mB[0m
[32m✓︎ [0m[2mshould be under B[0m
[1;35mC[0m
[32m✓︎ [0m[2mshould be under C[0m

[1mSummary[0m
[2m3/3 tests passed[0m
19 changes: 9 additions & 10 deletions src/Test/Spec/Reporter/Console.purs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Prelude

import Control.Monad.State (class MonadState, get, put)
import Control.Monad.Writer (class MonadWriter)
import Data.Foldable (for_, intercalate)
import Data.Foldable (intercalate)
import Data.Generic.Rep (class Generic)
import Data.Map (Map)
import Data.Map as Map
Expand All @@ -20,7 +20,7 @@ import Test.Spec.Style (styled)
import Test.Spec.Style as Style
import Test.Spec.Summary (Summary(..))
import Test.Spec.Summary as Summary
import Test.Spec.Tree (Path, Tree, parentSuite, parentSuiteName)
import Test.Spec.Tree (Path, Tree, parentSuiteName)

type State = { runningItems :: Map Path RunningItem, lastPrintedSuitePath :: Maybe Path}

Expand Down Expand Up @@ -88,14 +88,13 @@ print
-> PrintAction
-> m Unit
print path a = do
for_ (parentSuite path) \suite -> do
s <- get
case s.lastPrintedSuitePath of
Just p | p == suite.path -> pure unit
_ -> do
tellLn $ styled (Style.bold <> Style.magenta)
$ intercalate " » " (parentSuiteName suite.path <> [suite.name])
put s{lastPrintedSuitePath = Just suite.path}
s <- get
case s.lastPrintedSuitePath of
Just p | p == path -> pure unit
_ -> do
tellLn $ styled (Style.bold <> Style.magenta)
$ intercalate " » " (parentSuiteName path)
put s { lastPrintedSuitePath = Just path }
case a of
PrintTest name (Success _ _) -> do
tellLn $ " " <> styled Style.green "✓︎ " <> styled Style.dim name
Expand Down

0 comments on commit c66a79d

Please sign in to comment.