Fable.Mocha icon indicating copy to clipboard operation
Fable.Mocha copied to clipboard

Option to fail on focused tests

Open forki opened this issue 6 years ago • 3 comments

For expecto I built an option to let the whole test suite fail if there are focused tests. This is important for CI and detects the case when a dev commits a focus by accident. Is this supported as well? Easiest thing that I think would work is a function that maps recursively over test lists and returns true if a focus was set.

forki avatar Nov 08 '19 16:11 forki

Runner configuration are not supported in the Mocha.runTests function because it only accepts a test suite. It is possible to add another function Mocha.runTestsWithConfig that takes a configuration record with options such as this one. This is defintely nice to have and a PR would really appreciated :smile:

Zaid-Ajaj avatar Nov 08 '19 16:11 Zaid-Ajaj

I don't really think I want to deal with runner config. I just want to habe a function that takes a test list and returns true if a focus was set. This would be a useful piece

Zaid Ajaj [email protected] schrieb am Fr., 8. Nov. 2019, 17:25:

Runner configuration are not supported in the Mocha.runTests function because it only accepts a test suite. It is possible to add another function Mocha.runTestsWithConfig that takes a configuration record with options such as this one. This is defintely nice to have and a PR would really appreciated 😄

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Zaid-Ajaj/Fable.Mocha/issues/12?email_source=notifications&email_token=AAAOANDQFZVX7OAK4OLFJZLQSWHHDA5CNFSM4JKZTJBKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEDST2CA#issuecomment-551894280, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAOANGFHSKZLJWOLRKVCBDQSWHHDANCNFSM4JKZTJBA .

forki avatar Nov 08 '19 16:11 forki

This can be done externally by pattern matching on the test type:

  let rec findFocused (tests: TestCase list) : string list =
    tests
    |> List.collect (
      function
      | SyncTest(name, _, Focused)
      | AsyncTest(name, _, Focused) -> [ name ]
      | SyncTest(_)
      | AsyncTest(_) -> []
      | TestList(name, tests)
      | TestListSequential(name, tests) ->
        findFocused tests |> List.map (fun test -> $"{name} > {test}")
    )

  let failOnFocusedInCI tests =
    if getEnv "CI" |> Option.contains "true" then
      let focused = findFocused [ tests ]
      if focused.Length > 0 then
        let focused = String.Join("\n", focused |> Seq.map (fun test -> $"- {test}"))
        failwith $"Found focused tests:\n%s{focused}"

joprice avatar Jul 30 '24 14:07 joprice