Skip to content

Commit

Permalink
Add support for quicktest
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Mangel committed Sep 18, 2023
1 parent ac1a4c8 commit 19773b5
Show file tree
Hide file tree
Showing 10 changed files with 215 additions and 30 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ temp*/
*.fs.dart
src/fable-library/*.js
src/fable-library/BigInt/*.js
src/quicktest/**/*.js
src/quicktest-py/**/*.py
src/quicktest-rust/**/*.rs
src/quicktest-dart/**/*.dart
**/fable_modules/**

## Ignore Visual Studio temporary files, build results, and
Expand Down
6 changes: 6 additions & 0 deletions Build.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<Compile Include="build2/Tests/Rust.fs" />
<Compile Include="build2/Tests/Dart.fs" />
<Compile Include="build2/Tests/TypeScript.fs" />
<Compile Include="build2/Quicktest/Core.fs" />
<Compile Include="build2/Quicktest/TypeScript.fs" />
<Compile Include="build2/Quicktest/JavaScript.fs" />
<Compile Include="build2/Quicktest/Python.fs" />
<Compile Include="build2/Quicktest/Rust.fs" />
<Compile Include="build2/Quicktest/Dart.fs" />
<Compile Include="build2/Main.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
26 changes: 0 additions & 26 deletions build2/Fun.Build.Extensions.fs

This file was deleted.

29 changes: 25 additions & 4 deletions build2/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@ Available commands:
--dart Build fable-library for Dart
--rust Build fable-library for Rust
tests
quicktests Watch for changes and re-run the quicktests
This is useful to work on a feature in an isolated
manner to avoid all the noise coming from the main tests
Subcommands:
javascript Run for JavaScript
typescript Run for TypeScript
python Run for Python
dart Run for Dart
rust Run for Rust
Options:
--fast Skip building fable-library if folder already exists
tests Run the main tests suite
Subcommands:
javascript Run the tests for JavaScript
typescript Run the tests for TypeScript
Expand All @@ -28,8 +42,8 @@ Available commands:
rust Run the tests for Rust
Options for all:
--watch
--fast
--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:
Expand Down Expand Up @@ -64,7 +78,14 @@ let main argv =
| "dart" :: args -> Tests.Dart.handle args
| "rust" :: args -> Tests.Rust.handle args
| _ -> printHelp ()

| "quicktest" :: args ->
match args with
| "javascript" :: _ -> Quicktest.JavaScript.handle args
| "typescript" :: _ -> Quicktest.TypeScript.handle args
| "python" :: _ -> Quicktest.Python.handle args
| "dart" :: _ -> Quicktest.Dart.handle args
| "rust" :: _ -> Quicktest.Rust.handle args
| _ -> printHelp ()
| "--help" :: _
| _ -> printHelp ()

Expand Down
59 changes: 59 additions & 0 deletions build2/Quicktest/Core.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module Build.Quicktest.Core

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

type RunMode =
| RunScript
| RunCommand of string

type QuicktestConfig = {
Language: string
FableLibBuilder: BuildFableLibrary
ProjectDir: string
Extension: string
RunMode: RunMode
}

let genericQuicktest (config: QuicktestConfig) (args: string list) =
let skipFableLibrary = args |> List.contains "--fast"

config.FableLibBuilder.Run(skipFableLibrary)

let appendRunMode (cmdLine: CmdLine) =
match config.RunMode with
| RunScript -> cmdLine |> CmdLine.appendRaw "--runScript"
| RunCommand command ->
cmdLine
// Use appendRaw to avoid quoting the command
|> CmdLine.appendRaw "--run"
|> CmdLine.appendRaw command

let projectDir = Path.Resolve config.ProjectDir

Command.Fable(
CmdLine.empty
|> CmdLine.appendRaw "clean"

|> CmdLine.appendRaw projectDir
|> CmdLine.appendPrefix "--lang" config.Language
|> CmdLine.appendPrefix "--extension" config.Extension
|> CmdLine.appendRaw "--yes"
, workingDirectory = projectDir
)

Command.WatchFableAsync(
CmdLine.empty
|> CmdLine.appendRaw projectDir
|> CmdLine.appendPrefix "--lang" config.Language
|> CmdLine.appendPrefix "--extension" config.Extension
|> CmdLine.appendPrefix "--exclude" "Fable.Core"
|> CmdLine.appendRaw "--noCache"
|> CmdLine.appendRaw "--watch"
|> appendRunMode,
workingDirectory = projectDir
)
|> Async.AwaitTask
|> Async.RunSynchronously
15 changes: 15 additions & 0 deletions build2/Quicktest/Dart.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Build.Quicktest.Dart

open Build.FableLibrary
open Build.Quicktest.Core

let handle (args: string list) =
genericQuicktest
{
Language = "dart"
FableLibBuilder = BuildFableLibraryDart()
ProjectDir = "src/quicktest-dart"
Extension = ".dart"
RunMode = RunScript
}
args
18 changes: 18 additions & 0 deletions build2/Quicktest/JavaScript.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Build.Quicktest.JavaScript

open Build.FableLibrary
open BlackFox.CommandLine
open Build.Utils
open SimpleExec
open Build.Quicktest.Core

let handle (args: string list) =
genericQuicktest
{
Language = "javascript"
FableLibBuilder = BuildFableLibraryJavaScript()
ProjectDir = "src/quicktest"
Extension = ".js"
RunMode = RunScript
}
args
17 changes: 17 additions & 0 deletions build2/Quicktest/Python.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Build.Quicktest.Python

open Build.FableLibrary
open Build.Quicktest.Core



let handle (args: string list) =
genericQuicktest
{
Language = "python"
FableLibBuilder = BuildFableLibraryPython()
ProjectDir = "src/quicktest-py"
Extension = ".py"
RunMode = RunScript
}
args
15 changes: 15 additions & 0 deletions build2/Quicktest/Rust.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Build.Quicktest.Rust

open Build.FableLibrary
open Build.Quicktest.Core

let handle (args: string list) =
genericQuicktest
{
Language = "rust"
FableLibBuilder = BuildFableLibraryRust()
ProjectDir = "src/quicktest-rust"
Extension = ".rs"
RunMode = RunScript
}
args
58 changes: 58 additions & 0 deletions build2/Quicktest/TypeScript.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module Build.Quicktest.TypeScript

open Build.FableLibrary
open Build.Quicktest.Core
open BlackFox.CommandLine
open Build.Utils
open System.IO

let handle (args: string list) =

let srcDir = Path.Resolve "src/quicktest"
let outDir = Path.Resolve "build/quicktest-ts"
let mainFile = outDir </> "Quicktest.fs.js"

// Make sure the output directory exists, so nodemon doesn't complain
FileInfo(mainFile).Create() |> ignore

let tscCommand =
CmdLine.empty
|> CmdLine.appendRaw "npx"
|> CmdLine.appendRaw "tsc"
|> CmdLine.appendRaw "-w"
|> CmdLine.appendPrefix "-p" srcDir
|> CmdLine.appendPrefix "--outDir" outDir
|> CmdLine.toString

let nodemonCommand =
CmdLine.empty
|> CmdLine.appendRaw "npx"
|> CmdLine.appendRaw "nodemon"
|> CmdLine.appendPrefix "--delay" "500ms"
|> CmdLine.appendPrefix "-w" outDir
|> CmdLine.appendRaw mainFile
|> CmdLine.toString

let appendQuotedCommand (arg: string) (cmd: CmdLine) =
cmd
|> CmdLine.appendRaw "\""
|> CmdLine.appendRaw arg
|> CmdLine.appendRaw "\""

let runCommand =
CmdLine.empty
|> CmdLine.appendRaw "npx"
|> CmdLine.appendRaw "concurrently"
|> appendQuotedCommand tscCommand
|> appendQuotedCommand nodemonCommand
|> CmdLine.toString

genericQuicktest
{
Language = "typescript"
FableLibBuilder = BuildFableLibraryTypeScript()
ProjectDir = "src/quicktest"
Extension = ".fs.ts"
RunMode = RunCommand runCommand
}
args

0 comments on commit 19773b5

Please sign in to comment.