Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,22 @@
"version": "6.3.9",
"commands": [
"fantomas"
]
],
"rollForward": false
},
"paket": {
"version": "8.0.3",
"commands": [
"paket"
]
],
"rollForward": false
},
"fable": {
"version": "4.23.0",
"commands": [
"fable"
],
"rollForward": false
}
}
}
23 changes: 23 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: SAFE meta automated tests

on: push

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install Node
uses: actions/setup-node@v4
with:
node-version: 18

- name: Tool Restore
run: dotnet tool restore

- name: Test
working-directory: ./Build
run: dotnet run --project Build.fsproj -- Test
15 changes: 15 additions & 0 deletions Build/Build.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
open Fake.Core
open Fake.Core.TargetOperators
open Fake.IO
open Fake.JavaScript


let execContext = Context.FakeExecutionContext.Create false "build.fsx" []
Context.setExecutionContext (Context.RuntimeContext.Fake execContext)
Expand All @@ -23,8 +25,21 @@ module Processes =
let sourceFolder = Path.getFullName """../src"""
let outputFolder = Path.getFullName """../nugetPackages"""

let clientTestFolder = Path.getFullName """../test/SAFE.Client.Tests"""

let projects = [ "SAFE.Client"; "SAFE.Server" ]

Target.create "Test" (fun _ ->
Npm.install (fun o -> {
o with
WorkingDirectory = clientTestFolder
})

Npm.run "test" (fun o -> {
o with
WorkingDirectory = clientTestFolder
}))

Target.create "Bundle" (fun _ ->
let version = Environment.environVarOrFail "VERSION"
let releaseNotes = Environment.environVarOrFail "RELEASE_NOTES_URL"
Expand Down
3 changes: 2 additions & 1 deletion Build/paket.references
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Fake.Core.Target
Fake.Core.Target
Fake.JavaScript.Npm
10 changes: 9 additions & 1 deletion SAFE.Meta.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SAFE.Server", "src\SAFE.Ser
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Build", "Build\Build.fsproj", "{F49104E3-DBA9-4A2D-B839-B4E60BCAE698}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Test", "Test", "{387BFC82-96EA-4C10-A08E-C25588EE2223}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "SAFE.Client.Tests", "test\SAFE.Client.Tests\SAFE.Client.Tests.fsproj", "{ECC5C643-1340-4718-8381-E3D1E835C3E3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -32,9 +36,13 @@ Global
{F49104E3-DBA9-4A2D-B839-B4E60BCAE698}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F49104E3-DBA9-4A2D-B839-B4E60BCAE698}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F49104E3-DBA9-4A2D-B839-B4E60BCAE698}.Release|Any CPU.Build.0 = Release|Any CPU
{ECC5C643-1340-4718-8381-E3D1E835C3E3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECC5C643-1340-4718-8381-E3D1E835C3E3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECC5C643-1340-4718-8381-E3D1E835C3E3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECC5C643-1340-4718-8381-E3D1E835C3E3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{5BCFE180-027E-40F9-847B-7B36F10BD5D7} = {59161B7D-F517-4F4B-B28D-33E34B8A930E}
{0C8F62AC-D5D8-43E6-A4C7-159E530C3CE5} = {59161B7D-F517-4F4B-B28D-33E34B8A930E}
EndGlobalSection
EndGlobal
EndGlobal
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ framework: net8.0
storage: none

nuget Fake.Core.Target
nuget Fake.JavaScript.Npm
nuget FSharp.Core ~> 8

nuget Fable.Remoting.Giraffe ~> 5
Expand Down
41 changes: 24 additions & 17 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,22 @@ NUGET
Fake.Core.CommandLineParsing (6.1)
FParsec (>= 1.1.1)
FSharp.Core (>= 8.0.301)
Fake.Core.Context (6.1)
Fake.Core.Context (6.1.3)
FSharp.Core (>= 8.0.301)
Fake.Core.Environment (6.1)
Fake.Core.Environment (6.1.3)
FSharp.Core (>= 8.0.301)
Fake.Core.FakeVar (6.1)
Fake.Core.Context (>= 6.1)
Fake.Core.FakeVar (6.1.3)
Fake.Core.Context (>= 6.1.3)
FSharp.Core (>= 8.0.301)
Fake.Core.Process (6.1)
Fake.Core.Environment (>= 6.1)
Fake.Core.FakeVar (>= 6.1)
Fake.Core.String (>= 6.1)
Fake.Core.Trace (>= 6.1)
Fake.IO.FileSystem (>= 6.1)
Fake.Core.Process (6.1.3)
Fake.Core.Environment (>= 6.1.3)
Fake.Core.FakeVar (>= 6.1.3)
Fake.Core.String (>= 6.1.3)
Fake.Core.Trace (>= 6.1.3)
Fake.IO.FileSystem (>= 6.1.3)
FSharp.Core (>= 8.0.301)
System.Collections.Immutable (>= 8.0)
Fake.Core.String (6.1)
Fake.Core.String (6.1.3)
FSharp.Core (>= 8.0.301)
Fake.Core.Target (6.1)
Fake.Core.CommandLineParsing (>= 6.1)
Expand All @@ -108,13 +108,20 @@ NUGET
Fake.Core.Trace (>= 6.1)
FSharp.Control.Reactive (>= 5.0.2)
FSharp.Core (>= 8.0.301)
Fake.Core.Trace (6.1)
Fake.Core.Environment (>= 6.1)
Fake.Core.FakeVar (>= 6.1)
Fake.Core.Trace (6.1.3)
Fake.Core.Environment (>= 6.1.3)
Fake.Core.FakeVar (>= 6.1.3)
FSharp.Core (>= 8.0.301)
Fake.IO.FileSystem (6.1)
Fake.Core.String (>= 6.1)
Fake.Core.Trace (>= 6.1)
Fake.IO.FileSystem (6.1.3)
Fake.Core.String (>= 6.1.3)
Fake.Core.Trace (>= 6.1.3)
FSharp.Core (>= 8.0.301)
Fake.JavaScript.Npm (6.1.3)
Fake.Core.Process (>= 6.1.3)
Fake.Testing.Common (>= 6.1.3)
FSharp.Core (>= 8.0.301)
Fake.Testing.Common (6.1.3)
Fake.Core.Trace (>= 6.1.3)
FSharp.Core (>= 8.0.301)
Feliz (2.8)
Fable.ReactDom.Types (>= 18.2)
Expand Down
129 changes: 129 additions & 0 deletions test/SAFE.Client.Tests/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
module Client.Tests

open Fable.Mocha
open SAFE

[<RequireQualifiedAccess>]
type RemoteDataCase =
| NotStarted
| LoadingEmpty
| LoadingPopulated
| Loaded

member this.Label =
match this with
| NotStarted -> "Not started"
| LoadingEmpty -> "Loading empty"
| LoadingPopulated -> "Loading populated"
| Loaded -> "loaded"

member this.Example =
match this with
| NotStarted -> RemoteData.NotStarted
| LoadingEmpty -> Loading None
| LoadingPopulated -> Loading(Some true)
| Loaded -> RemoteData.Loaded true

module RemoteDataCase =
let all = [
RemoteDataCase.NotStarted
RemoteDataCase.LoadingEmpty
RemoteDataCase.LoadingPopulated
RemoteDataCase.Loaded
]


let inline testListForAll<'T when 'T: equality>
title
(transformation: RemoteData<bool> -> 'T)
(expectedMaker: RemoteDataCase -> 'T)
=

testList
title
(all
|> List.map (fun case ->
let expected = expectedMaker case

(fun _ -> Expect.equal (transformation case.Example) expected "")
|> testCase case.Label))

let remoteData =
testList "RemoteData" [
RemoteDataCase.testListForAll "defaultValue" (fun case -> case.DefaultValue false) (function
| RemoteDataCase.NotStarted
| RemoteDataCase.LoadingEmpty -> false
| RemoteDataCase.LoadingPopulated
| RemoteDataCase.Loaded -> true)

RemoteDataCase.testListForAll "HasLoaded" (_.HasLoaded) (function
| RemoteDataCase.NotStarted
| RemoteDataCase.LoadingEmpty
| RemoteDataCase.LoadingPopulated -> false
| RemoteDataCase.Loaded -> true)

RemoteDataCase.testListForAll "AsOption" (_.AsOption) (function
| RemoteDataCase.NotStarted
| RemoteDataCase.LoadingEmpty -> None
| RemoteDataCase.LoadingPopulated
| RemoteDataCase.Loaded -> Some true)

RemoteDataCase.testListForAll "hasStarted" (_.HasStarted) (function
| RemoteDataCase.NotStarted -> false
| RemoteDataCase.LoadingEmpty
| RemoteDataCase.LoadingPopulated
| RemoteDataCase.Loaded -> true)

RemoteDataCase.testListForAll "hasData" (_.HasData) (function
| RemoteDataCase.NotStarted
| RemoteDataCase.LoadingEmpty -> false
| RemoteDataCase.LoadingPopulated
| RemoteDataCase.Loaded -> true)

RemoteDataCase.testListForAll "isStillLoading" (_.IsStillLoading) (function
| RemoteDataCase.NotStarted -> false
| RemoteDataCase.LoadingEmpty
| RemoteDataCase.LoadingPopulated -> true
| RemoteDataCase.Loaded -> false)

RemoteDataCase.testListForAll "isRefresing" (_.IsRefreshing) (function
| RemoteDataCase.NotStarted -> false
| RemoteDataCase.LoadingEmpty -> false
| RemoteDataCase.LoadingPopulated -> true
| RemoteDataCase.Loaded -> false)

RemoteDataCase.testListForAll "hasNotStarted" (_.HasNotStarted) (function
| RemoteDataCase.NotStarted -> true
| RemoteDataCase.LoadingEmpty
| RemoteDataCase.LoadingPopulated
| RemoteDataCase.Loaded -> false)

RemoteDataCase.testListForAll "map" (_.Map(not)) (function
| RemoteDataCase.NotStarted -> NotStarted
| RemoteDataCase.LoadingEmpty -> Loading None
| RemoteDataCase.LoadingPopulated -> Loading(Some false)
| RemoteDataCase.Loaded -> Loaded false)

testList "bind" [
RemoteDataCase.testListForAll "toLoaded" (_.Bind(Loaded)) (function
| RemoteDataCase.NotStarted -> NotStarted
| RemoteDataCase.LoadingEmpty -> Loading None
| RemoteDataCase.LoadingPopulated
| RemoteDataCase.Loaded -> Loaded true)

RemoteDataCase.testListForAll "toNotStarted" (_.Bind(fun _ -> NotStarted)) (function
| RemoteDataCase.NotStarted -> NotStarted
| RemoteDataCase.LoadingEmpty -> Loading None
| RemoteDataCase.LoadingPopulated
| RemoteDataCase.Loaded -> NotStarted)
]

RemoteDataCase.testListForAll "startLoading" (_.StartLoading()) (function
| RemoteDataCase.NotStarted -> Loading None
| RemoteDataCase.LoadingEmpty -> Loading None
| RemoteDataCase.LoadingPopulated -> Loading (Some true)
| RemoteDataCase.Loaded -> Loading (Some true))
]

[<EntryPoint>]
let main _ = Mocha.runTests remoteData
17 changes: 17 additions & 0 deletions test/SAFE.Client.Tests/SAFE.Client.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>SAFE.Client</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
<Content Include="paket.references" />
<Content Include="package-lock.json" />
<Content Include="package.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\SAFE.Client\SAFE.Client.fsproj" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
Loading