From 07bb2279c8ca8951b505fa0f8fa6f8f77626a8a2 Mon Sep 17 00:00:00 2001 From: Blair55 Date: Sun, 6 Nov 2016 15:27:20 +0000 Subject: [PATCH] Basic JUnitReporter implementation --- src/canopy/reporters.fs | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/src/canopy/reporters.fs b/src/canopy/reporters.fs index cdc5045b..82153f15 100644 --- a/src/canopy/reporters.fs +++ b/src/canopy/reporters.fs @@ -380,3 +380,66 @@ type LiveHtmlReporter(browser : BrowserStartMode, driverPath : string, ?pinBrows member this.setEnvironment env = environment <- env + +type JUnitReporter(resultFilePath:string) = + + let consoleReporter : IReporter = new ConsoleReporter() :> IReporter + + let passedTests = ResizeArray<_>() + let failedTests = ResizeArray<_>() + + interface IReporter with + + member this.pass id = + consoleReporter.pass id + passedTests.Add(id) + + member this.fail ex id ss url = + consoleReporter.fail ex id ss url + failedTests.Add(ex, id) + + member this.describe d = + consoleReporter.describe d + + member this.contextStart c = + consoleReporter.contextStart c + + member this.contextEnd c = + consoleReporter.contextEnd c + + member this.summary minutes seconds passed failed skipped = + consoleReporter.summary minutes seconds passed failed skipped + let testCount = passed + failed + let passedTestsXml = + passedTests + |> Seq.map(sprintf "") + let failedTestsXml = + failedTests + |> Seq.map(fun (ex, id) -> sprintf "%s" id ex.Message) + let allTestsXml = String.Join(String.Empty, Seq.concat [passedTestsXml; failedTestsXml]) + let xml = sprintf "%s" testCount allTestsXml + let resultFile = System.IO.FileInfo(resultFilePath) + resultFile.Directory.Create() + consoleReporter.write <| sprintf "Saving results to %s" resultFilePath + let enc = new System.Text.UTF8Encoding(false) + let bytes = enc.GetBytes xml + use fs = new System.IO.FileStream(resultFilePath, System.IO.FileMode.OpenOrCreate) + fs.Write(bytes, 0, bytes.Length) + + member this.write w = + consoleReporter.write w + + member this.suggestSelectors selector suggestions = + consoleReporter.suggestSelectors selector suggestions + + member this.testStart id = + consoleReporter.testStart id + + member this.testEnd id = () + member this.quit () = () + member this.suiteBegin () = () + member this.suiteEnd () = () + member this.coverage url ss _ = () + member this.todo _ = () + member this.skip id = () + member this.setEnvironment env = ()