Skip to content

Commit

Permalink
Strongly type runFor instead of boxing (#486)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kai authored and lefthandedgoat committed Nov 5, 2019
1 parent 1bce9ed commit cfe3fa1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
25 changes: 11 additions & 14 deletions src/canopy/runner.fs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,12 @@ let private runtest (suite : suite) (test : Test) =

match testResult with
| Skip -> Skip
| _ ->
| _ ->
let afterResult = tryTest test suite (suite.After)
match testResult with
| Failed -> testResult
| _ -> afterResult

failureMessage <- null
result
else
Expand Down Expand Up @@ -238,35 +238,32 @@ let run () =
reporter.suiteEnd()

(* documented/testing *)
let runFor browsers =
let runFor (browsers: Browsers) =
// suites are in reverse order and have to be reversed before running the tests
let currentSuites = suites
match box browsers with
| :? (canopy.types.BrowserStartMode list) as browsers ->

match browsers with
| BrowserStartModes browsers ->
let newSuites =
browsers
|> List.rev
|> List.map (fun browser ->
|> List.collect (fun browser ->
let suite = new suite()
suite.Context <- sprintf "Running tests with %s browser" (toString browser)
suite.Once <- fun _ -> start browser
suite.Once <- fun _ -> start browser
let currentSuites2 = currentSuites |> List.map(fun suite -> suite.Clone())
currentSuites2 |> List.iter (fun suite -> suite.Context <- sprintf "(%s) %s" (toString browser) suite.Context)
currentSuites2 @ [suite])
|> List.concat
suites <- newSuites
| :? (IWebDriver list) as browsers ->
| WebDrivers browsers ->
let newSuites =
browsers
|> List.rev
|> List.map (fun browser ->
|> List.collect (fun browser ->
let suite = new suite()
suite.Context <- sprintf "Running tests with %s browser" (browser.ToString())
suite.Context <- sprintf "Running tests with %s browser" (browser.ToString())
suite.Once <- fun _ -> switchTo browser
let currentSuites2 = currentSuites |> List.map(fun suite -> suite.Clone())
currentSuites2 |> List.iter (fun suite -> suite.Context <- sprintf "(%s) %s" (browser.ToString()) suite.Context)
currentSuites2 @ [suite])
|> List.concat
suites <- newSuites
| _ -> raise <| Exception "I dont know what you have given me"
6 changes: 5 additions & 1 deletion src/canopy/types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ type IReporter =
abstract member quit : unit -> unit
abstract member suiteBegin : unit -> unit
abstract member suiteEnd : unit -> unit
abstract member setEnvironment : string -> unit
abstract member setEnvironment : string -> unit

type Browsers =
| BrowserStartModes of BrowserStartMode list
| WebDrivers of IWebDriver list

0 comments on commit cfe3fa1

Please sign in to comment.