Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 15 additions & 64 deletions elm/src/Test/Reporter/TestResults.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Test.Reporter.TestResults exposing
, SummaryInfo
, TestResult
, isFailure
, outcomesFromExpectations
, outcomeFromExpectations
)

import Expect exposing (Expectation)
Expand Down Expand Up @@ -52,75 +52,26 @@ isFailure outcome =
False


outcomesFromExpectations : List Expectation -> List Outcome
outcomesFromExpectations expectations =
outcomeFromExpectations : List Expectation -> Outcome
outcomeFromExpectations expectations =
case expectations of
expectation :: [] ->
-- Most often we'll get exactly 1 pass, so try that case first!
-- The type of test runner functions says that they return `List Expectation`,
-- but in practice they only ever return lists with exactly one item:
-- https://github.com/elm-explorations/test/pull/244
-- That PR was reverted because it unfortunately was a breaking change for the package:
-- https://github.com/elm-explorations/test/commit/11f70d5fc0b6fdc88d7a34ea1d10f56969890493
-- But to keep things simpler here, we only support exactly one expectation.
[ expectation ] ->
case Test.Runner.getFailureReason expectation of
Nothing ->
[ Passed (Test.Runner.getDistributionReport expectation) ]
Passed (Test.Runner.getDistributionReport expectation)

Just failure ->
if Test.Runner.isTodo expectation then
[ Todo failure.description ]
Todo failure.description

else
[ Failed
[ ( failure, Test.Runner.getDistributionReport expectation ) ]
]

_ :: _ ->
let
builder =
List.foldl outcomesFromExpectationsHelp
{ passes = [], todos = [], failures = [] }
expectations

failuresList =
case builder.failures of
[] ->
[]

failures ->
[ Failed failures ]
in
List.concat
[ List.map Passed builder.passes
, List.map Todo builder.todos
, failuresList
]

[] ->
[]


type alias OutcomeBuilder =
{ passes : List DistributionReport
, todos : List String
, failures : List ( Failure, DistributionReport )
}

Failed [ ( failure, Test.Runner.getDistributionReport expectation ) ]

outcomesFromExpectationsHelp : Expectation -> OutcomeBuilder -> OutcomeBuilder
outcomesFromExpectationsHelp expectation builder =
case Test.Runner.getFailureReason expectation of
Just failure ->
if Test.Runner.isTodo expectation then
{ builder | todos = failure.description :: builder.todos }

else
{ builder
| failures =
( failure
, Test.Runner.getDistributionReport expectation
)
:: builder.failures
}

Nothing ->
{ builder
| passes =
Test.Runner.getDistributionReport expectation
:: builder.passes
}
_ ->
Debug.todo ("A test somehow did not return exactly 1 expectation, it returned " ++ String.fromInt (List.length expectations) ++ "!")
21 changes: 9 additions & 12 deletions elm/src/Test/Runner/Node.elm
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Random
import Task
import Test exposing (Test)
import Test.Reporter.Reporter exposing (Report, RunInfo, TestReporter, createReporter)
import Test.Reporter.TestResults exposing (Outcome, TestResult, isFailure, outcomesFromExpectations)
import Test.Reporter.TestResults exposing (Outcome, TestResult, isFailure, outcomeFromExpectations)
import Test.Runner exposing (Runner, SeededRunners(..))
import Test.Runner.JsMessage as JsMessage exposing (JsMessage(..))
import Time exposing (Posix)
Expand Down Expand Up @@ -75,7 +75,7 @@ type alias TestProgram =
type Msg
= Receive Decode.Value
| Dispatch Posix
| Complete (List String) (List Outcome) Posix Posix
| Complete (List String) Outcome Posix Posix


{-| The port names are prefixed to reduce the likelihood of the project
Expand All @@ -96,11 +96,11 @@ dispatch model startTime =

Just config ->
let
outcomes =
outcomesFromExpectations (config.run ())
outcome =
outcomeFromExpectations (config.run ())
in
Time.now
|> Task.perform (Complete config.labels outcomes startTime)
|> Task.perform (Complete config.labels outcome startTime)


update : Msg -> Model -> ( Model, Cmd Msg )
Expand Down Expand Up @@ -173,27 +173,24 @@ update msg ({ testReporter } as model) =
Dispatch startTime ->
( model, dispatch model startTime )

Complete labels outcomes startTime endTime ->
Complete labels outcome startTime endTime ->
let
duration =
Time.posixToMillis endTime - Time.posixToMillis startTime

prependOutcome outcome rest =
results =
( model.nextTestToRun
, { labels = labels, outcome = outcome, duration = duration }
)
:: rest

results =
List.foldl prependOutcome model.results outcomes
:: model.results

nextTestToRun =
model.nextTestToRun + model.processes

isFinished =
nextTestToRun >= model.runInfo.testCount
in
if isFinished || List.any isFailure outcomes then
if isFinished || isFailure outcome then
let
cmd =
sendResults isFinished testReporter results
Expand Down