Skip to content
This repository has been archived by the owner on Jun 25, 2019. It is now read-only.

Support for 0.19 #9

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
20 changes: 0 additions & 20 deletions elm-package.json

This file was deleted.

21 changes: 21 additions & 0 deletions elm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "package",
"name": "elm-community/html-test-runner",
"summary": "Run elm-test tests in a browser.",
"license": "BSD-3-Clause",
"version": "1.0.7",
"exposed-modules": [
"Test.Runner.Html"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"elm-explorations/test": "1.0.0 <= v < 2.0.0",
"elm-lang/browser": "1.0.0 <= v < 2.0.0",
"elm-lang/core": "6.0.0 <= v < 7.0.0",
"elm-lang/html": "3.0.0 <= v < 4.0.0",
"elm-lang/random": "1.0.0 <= v < 2.0.0",
"elm-lang/time": "1.0.0 <= v < 2.0.0",
"mdgriffith/style-elements": "5.0.1 <= v < 6.0.0"
},
"test-dependencies": {}
}
4 changes: 2 additions & 2 deletions example/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module HtmlRunnerExample exposing (..)

{-| HOW TO RUN THIS EXAMPLE

1. Run elm-reactor from the same directory as your tests' elm-package.json. (For example, if you have tests/elm-package.json, then cd into tests/ and
1. Run elm-reactor from the same directory as your tests' elm.json. (For example, if you have tests/elm.json, then cd into tests/ and
run elm-reactor.)
2. Visit <http://localhost:8000> and bring up this file.

Expand Down Expand Up @@ -39,7 +39,7 @@ testWithoutNums =
describe "withoutNums"
[ fuzzWith { runs = 100 } (tuple3 ( string, float, string )) "adding numbers to strings has no effect" <|
\( prefix, num, suffix ) ->
withoutNums (prefix ++ toString num ++ suffix)
withoutNums (prefix ++ String.fromFloat num ++ suffix)
|> Expect.equal (withoutNums (prefix ++ suffix))
]

Expand Down
98 changes: 78 additions & 20 deletions src/Test/Runner/Exploration.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,58 @@ module Test.Runner.Exploration
, formatFailure
, fromTest
, step
, toString
)

import Expect
import Random.Pcg
import Random
import Test
import Test.Runner
import Test.Runner.Failure


toString : Runner -> String
toString (Runner internals) =
let
keyValue key value =
" " ++ key ++ ": " ++ value
in
String.join "\n"
[ keyValue "passed" (String.fromInt internals.passed)
, keyValue "todos" ("\n [ " ++ String.join " \n" (List.map failureToString internals.todos) ++ "]")
, keyValue "failures" ("\n [ " ++ String.join " \n" (List.map failureToString internals.failures) ++ "]")
, keyValue "incomplete"
(case internals.incomplete of
Nothing ->
"Nothing"

Just reason ->
"Just "
++ (case reason of
Skip ->
"Skip"

Only ->
"Only"

Custom label ->
"Custom " ++ label
)
)
, keyValue "queue"
(case internals.queue of
[] ->
"[]"

q ->
String.join " " (List.map (.labels >> String.join ", ") q)
)
]


failureToString : Failure -> String
failureToString (Failure labels messages) =
"failure: " ++ String.join ", " labels ++ ", reasons: " ++ String.join ", " (List.map .description messages)


type Runner
Expand Down Expand Up @@ -48,10 +94,17 @@ type Reason


type Failure
= Failure (List String) (List { given : Maybe String, message : String })
= Failure
(List String)
(List
{ given : Maybe String
, description : String
, reason : Test.Runner.Failure.Reason
}
)


fromTest : Int -> Random.Pcg.Seed -> Test.Test -> Runner
fromTest : Int -> Random.Seed -> Test.Test -> Runner
fromTest runs seed test =
let
new queue incomplete =
Expand Down Expand Up @@ -81,33 +134,38 @@ formatFailure :
(String -> a)
-> (String -> a)
-> Failure
-> ( List a, List { given : Maybe String, message : String } )
->
( List a
, List
{ given : Maybe String
, description : String
, reason : Test.Runner.Failure.Reason
}
)
formatFailure formatFirst formatLast (Failure labels errors) =
( Test.Runner.formatLabels formatFirst formatLast labels, errors )


step : Runner -> Status
step (Runner internals) =
case
( internals.incomplete
, internals.todos
, internals.failures
, internals.queue
)
of
( Nothing, [], [], [] ) ->
Pass internals.passed
case ( internals.failures, internals.queue ) of
( [], [] ) ->
case internals.incomplete of
Nothing ->
case internals.todos of
[] ->
Pass internals.passed

( Nothing, todos, [], [] ) ->
Todo internals.passed todos
todos ->
Todo internals.passed todos

( Just reason, _, [], [] ) ->
Incomplete internals.passed reason
Just incompleteReason ->
Incomplete internals.passed incompleteReason

( _, _, failures, [] ) ->
( failures, [] ) ->
Fail internals.passed failures

( _, _, _, next :: queue ) ->
( _, next :: queue ) ->
next.run ()
|> fromExpectation { internals | queue = queue } next.labels

Expand All @@ -119,7 +177,7 @@ fromExpectation internals labels expectations =
List.foldr partition ( [], [] ) expectations

partition e =
case ( Test.Runner.isTodo e, Test.Runner.getFailure e ) of
case ( Test.Runner.isTodo e, Test.Runner.getFailureReason e ) of
( True, Just result ) ->
Tuple.mapFirst ((::) result)

Expand Down
12 changes: 7 additions & 5 deletions src/Test/Runner/Html.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ one of these tests in elm-reactor to have it run and show outputs.

-}

import Html
import Random.Pcg as Random
-- import Html
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary comment can be removed?


import Browser
import Random
import Test exposing (Test)
import Test.Runner.Html.App as App
import Test.Runner.Html.View as View
Expand All @@ -20,7 +22,7 @@ import View as View
{-| A program which will run tests and report their results.
-}
type alias TestProgram =
Program Never App.Model App.Msg
Program () App.Model App.Msg


{-| Run the test and report the results.
Expand All @@ -39,8 +41,8 @@ run =
-}
runWithOptions : Maybe Int -> Maybe Random.Seed -> Test -> TestProgram
runWithOptions runs seed test =
Html.program
{ init = App.init (Maybe.withDefault 100 runs) seed test
Browser.embed
{ init = always (App.init (Maybe.withDefault 100 runs) seed test)
, update = App.update
, view = App.present >> View.view
, subscriptions = \_ -> Sub.none
Expand Down
19 changes: 13 additions & 6 deletions src/Test/Runner/Html/App.elm
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ module Test.Runner.Html.App

import Expect exposing (Expectation)
import Process
import Random.Pcg as Random
import Random
import Task
import Test exposing (Test)
import Test.Runner.Exploration as Runner
import Test.Runner.Html.View as View
import Time exposing (Time)
import Time


type Model
= NotStarted (Maybe Random.Seed) Int Test
| Started Time Time Runner.Status
| Started Time.Posix Time.Posix Runner.Status


type Msg
= Dispatch Time
= Dispatch Time.Posix


dispatch : Cmd Msg
Expand All @@ -48,7 +48,7 @@ update : Msg -> Model -> ( Model, Cmd Msg )
update (Dispatch now) model =
case model of
NotStarted Nothing runs test ->
( floor now
( Time.toMillis Time.utc now
|> Random.initialSeed
|> start runs test
|> Started now now
Expand Down Expand Up @@ -78,4 +78,11 @@ present model =
Nothing

Started startTime now status ->
Just ( now - startTime, status )
let
diff =
Time.toMillis Time.utc now - Time.toMillis Time.utc startTime
in
Just
( Time.millisToPosix diff
, status
)
4 changes: 2 additions & 2 deletions src/Test/Runner/Html/View.elm
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Test.Runner.Html.View exposing (..)

import Test.Runner.Exploration as Runner
import Time exposing (Time)
import Time


type alias Model =
Maybe ( Time, Runner.Status )
Maybe ( Time.Posix, Runner.Status )
Loading