Skip to content

Commit

Permalink
Split Standalone tests into their own category
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Mangel committed Sep 25, 2023
1 parent b401006 commit 1eb6288
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 42 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"christian-kohler.npm-intellisense",
"ionutvmi.path-autocomplete",
"ms-python.vscode-pylance",
"rust-lang.rust-analyzer"
"rust-lang.rust-analyzer",
"tintoy.msbuild-project-tools"
],
"settings": {
"terminal.integrated.defaultProfile.linux": "zsh",
Expand Down
1 change: 1 addition & 0 deletions Build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Compile Include="build2/FableLibrary/TypeScript.fs" />
<Compile Include="build2/FableLibrary/JavaScript.fs" />
<Compile Include="build2/FableLibrary/Rust.fs" />
<Compile Include="build2/Tests/Standalone.fs" />
<Compile Include="build2/Tests/JavaScript.fs" />
<Compile Include="build2/Tests/Python.fs" />
<Compile Include="build2/Tests/Rust.fs" />
Expand Down
9 changes: 5 additions & 4 deletions build2/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ Available commands:
python Run the tests for Python
dart Run the tests for Dart
rust Run the tests for Rust
integration Run th integration test suite
integration Run the integration test suite
standalone Tests the standalone version of Fable
(Fable running on top of Node.js)
Options for all except integration:
Options for all except integration and standalone:
--watch Watch for changes and re-run the tests
--fast Skip building fable-library if folder already exists
--no-dotnet When in watch mode, do not run the .NET tests
Options for JavaScript:
--reat-only Run only the tests for React (can be run in watch mode)
--standalone-only Run only the tests for standalone (can't be run in watch mode)
Options for Rust:
--ast-only Run only the tests for the AST (can be run in watch mode)
Expand Down Expand Up @@ -80,6 +81,7 @@ let main argv =
| "dart" :: args -> Tests.Dart.handle args
| "rust" :: args -> Tests.Rust.handle args
| "integration" :: args -> Tests.Integration.handle args
| "standalone" :: _ -> Tests.Standalone.handle args
| _ -> printHelp ()
| "quicktest" :: args ->
match args with
Expand All @@ -88,7 +90,6 @@ let main argv =
| "python" :: _ -> Quicktest.Python.handle args
| "dart" :: _ -> Quicktest.Dart.handle args
| "rust" :: _ -> Quicktest.Rust.handle args
// Add standalone tests here
| _ -> printHelp ()
| "sync-fcs-repo":: _ -> FcsRepo.sync ()
| "copy-fcs-repo":: _ -> FcsRepo.copy ()
Expand Down
44 changes: 7 additions & 37 deletions build2/Tests/JavaScript.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,6 @@ let private testReact (isWatch: bool) =

Command.Run("npx", "jest", workingDirectory = workingDirectoy)

let private handleStandaloneFast () =
let fableCompilerJsDir = Path.Resolve("src", "fable-compiler-js", "src")
let fableCompilerJsEntry = Path.Combine(fableCompilerJsDir, "app.fs.js")
let standaloneBuildDest = Path.Resolve("build", "tests", "Standalone")

Command.Fable(
CmdLine.appendRaw "--noCache",
workingDirectory = Path.Resolve("src", "fable-standalone", "src")
)

Command.Fable(
CmdLine.appendPrefix "--exclude" "Fable.Core"
>> CmdLine.appendPrefix "--define" "LOCAL_TEST"
>> CmdLine.appendRaw "--noCache",
workingDirectory = fableCompilerJsDir
)

// Make sure the projects are restored
// Otherwise, on a first VM dependencies can be missing
Command.Run("dotnet", $"restore {mainTestProject}")

Command.Run(
"node",
CmdLine.empty
|> CmdLine.appendRaw fableCompilerJsEntry
|> CmdLine.appendRaw mainTestProject
|> CmdLine.appendRaw standaloneBuildDest
|> CmdLine.toString,
workingDirectory = fableCompilerJsDir
)

Command.Run("npx", mochaCommand, workingDirectory = standaloneBuildDest)

let private handleMainTests (isWatch: bool) (noDotnet: bool) =
let folderName = "Main"
let sourceDir = Path.Resolve("tests", "Js", folderName)
Expand Down Expand Up @@ -141,7 +108,7 @@ let private handleMainTests (isWatch: bool) (noDotnet: bool) =
let isCI = Environment.GetEnvironmentVariable("CI") |> Option.ofObj

if isCI.IsSome then
handleStandaloneFast ()
Standalone.handleStandaloneFast ()

let handle (args: string list) =
let isReactOnly = args |> List.contains "--react-only"
Expand All @@ -156,6 +123,9 @@ let handle (args: string list) =

BuildFableLibraryJavaScript().Run(skipFableLibrary)

if isReactOnly then testReact isWatch
else if isStandaloneOnly then handleStandaloneFast ()
else handleMainTests isWatch noDotnet
if isReactOnly then
testReact isWatch
else if isStandaloneOnly then
Standalone.handleStandaloneFast ()
else
handleMainTests isWatch noDotnet
50 changes: 50 additions & 0 deletions build2/Tests/Standalone.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
module Build.Tests.Standalone

open Build.FableLibrary
open System.IO
open System
open BlackFox.CommandLine
open Build.Utils
open Build
open SimpleExec

let private mainTestProject =
Path.Resolve("tests", "Js", "Main", "Fable.Tests.fsproj")

let private mochaCommand = "npx mocha . --reporter dot -t 10000"

let handleStandaloneFast () =
let fableCompilerJsDir = Path.Resolve("src", "fable-compiler-js", "src")
let fableCompilerJsEntry = Path.Combine(fableCompilerJsDir, "app.fs.js")
let standaloneBuildDest = Path.Resolve("build", "tests", "Standalone")

Command.Fable(
CmdLine.appendRaw "--noCache",
workingDirectory = Path.Resolve("src", "fable-standalone", "src")
)

Command.Fable(
CmdLine.appendPrefix "--exclude" "Fable.Core"
>> CmdLine.appendPrefix "--define" "LOCAL_TEST"
>> CmdLine.appendRaw "--noCache",
workingDirectory = fableCompilerJsDir
)

// Make sure the projects are restored
// Otherwise, on a first VM dependencies can be missing
Command.Run("dotnet", $"restore {mainTestProject}")

Command.Run(
"node",
CmdLine.empty
|> CmdLine.appendRaw fableCompilerJsEntry
|> CmdLine.appendRaw mainTestProject
|> CmdLine.appendRaw standaloneBuildDest
|> CmdLine.toString,
workingDirectory = fableCompilerJsDir
)

Command.Run("npx", mochaCommand, workingDirectory = standaloneBuildDest)

let handle (args: string list) =
handleStandaloneFast ()

0 comments on commit 1eb6288

Please sign in to comment.