Skip to content

Commit

Permalink
Use Expecto and canopy for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Feb 20, 2017
1 parent 2f45e71 commit bc7c107
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 233 deletions.
41 changes: 41 additions & 0 deletions Tests.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26206.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{63297B98-5CED-492C-A5B7-A5B4F73CF142}"
ProjectSection(SolutionItems) = preProject
paket.dependencies = paket.dependencies
paket.lock = paket.lock
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{BF60BC93-E09B-4E5F-9D85-95A519479D54}"
ProjectSection(SolutionItems) = preProject
build.fsx = build.fsx
package.json = package.json
prepare-tests.cmd = prepare-tests.cmd
README.md = README.md
RELEASE_NOTES.md = RELEASE_NOTES.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{ED8079DD-2B06-4030-9F0F-DC548F98E1C4}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "UITests", "test\UITests\UITests.fsproj", "{95D2789C-8B80-49E7-915A-AC670C36D3FB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{95D2789C-8B80-49E7-915A-AC670C36D3FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95D2789C-8B80-49E7-915A-AC670C36D3FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95D2789C-8B80-49E7-915A-AC670C36D3FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95D2789C-8B80-49E7-915A-AC670C36D3FB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{95D2789C-8B80-49E7-915A-AC670C36D3FB} = {ED8079DD-2B06-4030-9F0F-DC548F98E1C4}
EndGlobalSection
EndGlobal
44 changes: 43 additions & 1 deletion build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ open Fake.ReleaseNotesHelper
open Fake.UserInputHelper
open System
open System.IO
open Fake.Testing.Expecto


let project = "Suave/Fable sample"
Expand All @@ -36,6 +37,10 @@ let dotnetExePath =

let deployDir = "./deploy"


// Pattern specifying assemblies to be tested using expecto
let testExecutables = "test/**/bin/Release/*Tests*.exe"

// --------------------------------------------------------------------------------------
// END TODO: The rest of the file includes standard build steps
// --------------------------------------------------------------------------------------
Expand Down Expand Up @@ -193,13 +198,48 @@ Target "BuildClient" (fun _ ->
run npmTool "run build" clientPath
)


let vsProjProps =
#if MONO
[ ("DefineConstants","MONO"); ("Configuration", configuration) ]
#else
[ ("Configuration", configuration); ("Platform", "Any CPU") ]
#endif

Target "BuildTests" (fun _ ->
!! "./Tests.sln"
|> MSBuildReleaseExt "" vsProjProps "Rebuild"
|> ignore
)

Target "RunTests" (fun _ ->
ActivateFinalTarget "KillProcess"

let serverProcess =
let info = System.Diagnostics.ProcessStartInfo()
info.FileName <- dotnetExePath
info.WorkingDirectory <- serverPath
info.Arguments <- " run"
info.UseShellExecute <- false
System.Diagnostics.Process.Start info

!! testExecutables
|> Expecto (fun p -> { p with Parallel = false } )
|> ignore

serverProcess.Kill()
)

// --------------------------------------------------------------------------------------
// Run the Website


let ipAddress = "localhost"
let port = 8080

FinalTarget "KillProcess" (fun _ ->
killProcess "dotnet"
killProcess "dotnet.exe")


Target "Run" (fun _ ->
let dotnetwatch = async {
Expand Down Expand Up @@ -238,6 +278,8 @@ Target "BuildAll" DoNothing
==> "AssemblyInfo"
==> "BuildClient"
==> "Build"
==> "BuildTests"
==> "RunTests"
==> "All"
==> "Release"

Expand Down
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ group Test
nuget FSharp.Core redirects: force
nuget Canopy
nuget Expecto
nuget Selenium.WebDriver.ChromeDriver

group Build
source https://nuget.org/api/v2
Expand Down
1 change: 1 addition & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ NUGET
System.Security.Cryptography.X509Certificates (>= 4.3) - framework: >= net46
System.Threading.Timer (>= 4.3) - framework: >= net451
Selenium.WebDriver (3.0)
Selenium.WebDriver.ChromeDriver (2.27)
System.AppContext (4.3) - framework: >= net463
System.Collections.Concurrent (4.3) - framework: >= net463
System.Console (4.3) - framework: >= net463
Expand Down
36 changes: 0 additions & 36 deletions test/UITests/Auth.fs

This file was deleted.

24 changes: 0 additions & 24 deletions test/UITests/Program.fs

This file was deleted.

31 changes: 31 additions & 0 deletions test/UITests/Runner.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module UITests.Runner

open System.IO
open canopy
open Expecto
open System.Diagnostics
open System

let rec findPackages (di:DirectoryInfo) =
if di = null then failwith "Could not find packages folder"
let packages = DirectoryInfo(Path.Combine(di.FullName,"packages"))
if packages.Exists then di else
findPackages di.Parent

let rootDir = findPackages (DirectoryInfo (Directory.GetCurrentDirectory()))

let startChrome() =
canopy.configuration.chromeDir <- Path.Combine(rootDir.FullName,"packages","test/Selenium.WebDriver.ChromeDriver/driver")
start chrome

[<EntryPoint>]
let main args =
try
try
startChrome()
runTestsWithArgs { defaultConfig with ``parallel`` = false } args Tests.tests
with e ->
printfn "Error: %s" e.Message
-1
finally
quit()
48 changes: 0 additions & 48 deletions test/UITests/Server.fs

This file was deleted.

6 changes: 0 additions & 6 deletions test/UITests/ServerTypes.fs

This file was deleted.

30 changes: 30 additions & 0 deletions test/UITests/Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module UITests.Tests

open canopy
open System.IO
open Expecto
open System
open System.Threading

let serverUrl = "http://localhost:8085/"

let tests =
testList "client tests" [
testCase "sound check - server is online" <| fun () ->
url serverUrl
waitForElement ".elmish-app"


testCase "login with test user" <| fun () ->
url serverUrl
waitForElement ".elmish-app"

click "Login"

"#username" << "test"
"#password" << "test"

click "Log In"

waitForElement "Isaac Abraham"
]
43 changes: 0 additions & 43 deletions test/UITests/TokenUtils.fs

This file was deleted.

Loading

0 comments on commit bc7c107

Please sign in to comment.