Skip to content

Commit

Permalink
Merge pull request #3710 from fable-compiler/activate_adaptive_tests
Browse files Browse the repository at this point in the history
Add Js Adaptive tests
  • Loading branch information
MangelMaxime authored Jan 23, 2024
2 parents 36a61be + 6fcf246 commit 187db25
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/Fable.Build/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ Available commands:
--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)
--react-only Run only the tests for React (can be run in watch mode)
--standalone-only Run only the tests for the standalone version of Fable
(can be run in watch mode)
--adaptive-only Run only the tests for the adaptive version of Fable
(can 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
33 changes: 33 additions & 0 deletions src/Fable.Build/SimpleExec.Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,36 @@ type Command with
?noEcho = noEcho,
?echoPrefix = echoPrefix
)

static member WatchFable
(
args: CmdLine,
?workingDirectory,
?noEcho,
?echoPrefix
)
=
let localFableDir = __SOURCE_DIRECTORY__ </> ".." </> "Fable.Cli"

let args =
CmdLine.concat
[
CmdLine.empty
|> CmdLine.appendRaw "watch"
|> CmdLine.appendPrefix "--project" localFableDir
|> CmdLine.appendRaw "run"
// Without the release mode, Fable stack overflow when compiling the tests
|> CmdLine.appendPrefix "-c" "Release"
|> CmdLine.appendRaw "--"

args
]
|> CmdLine.toString

Command.Run(
"dotnet",
args,
?workingDirectory = workingDirectory,
?noEcho = noEcho,
?echoPrefix = echoPrefix
)
56 changes: 54 additions & 2 deletions src/Fable.Build/Test/JavaScript.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,49 @@ let private testReact (isWatch: bool) =

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

let private testAdaptive (isWatch: bool) =
let folderName = "Adaptive"
let sourceDir = Path.Resolve("tests", "Js", folderName)

let destinationDir = Path.Resolve("temp", "tests", "JavaScript", folderName)

let mochaCommand =
CmdLine.empty
|> CmdLine.appendRaw "npx"
|> CmdLine.appendRaw "mocha"
|> CmdLine.appendRaw destinationDir
|> CmdLine.appendPrefix "--reporter" "dot"
|> CmdLine.appendPrefix "-t" "10000"
|> CmdLine.toString

Directory.clean destinationDir

let fableArgs =
CmdLine.concat
[
CmdLine.empty
|> CmdLine.appendRaw sourceDir
|> CmdLine.appendPrefix "--outDir" destinationDir
|> CmdLine.appendPrefix "--lang" "javascript"
|> CmdLine.appendPrefix "--exclude" "Fable.Core"
|> CmdLine.appendRaw "--noCache"

if isWatch then
CmdLine.empty
|> CmdLine.appendRaw "--watch"
|> CmdLine.appendRaw "--runWatch"
|> CmdLine.appendRaw mochaCommand
else
CmdLine.empty
|> CmdLine.appendRaw "--run"
|> CmdLine.appendRaw mochaCommand
]

if isWatch then
Command.WatchFable(fableArgs, workingDirectory = destinationDir)
else
Command.Fable(fableArgs, workingDirectory = destinationDir)

let private handleMainTests (isWatch: bool) (noDotnet: bool) =
let folderName = "Main"
let sourceDir = Path.Resolve("tests", "Js", folderName)
Expand Down Expand Up @@ -113,6 +156,7 @@ let private handleMainTests (isWatch: bool) (noDotnet: bool) =
Command.Fable(fableArgs, workingDirectory = destinationDir)

testReact false
testAdaptive false

// let isCI = Environment.GetEnvironmentVariable("CI") |> Option.ofObj

Expand All @@ -123,19 +167,27 @@ let private handleMainTests (isWatch: bool) (noDotnet: bool) =
let handle (args: string list) =
let isReactOnly = args |> List.contains "--react-only"
let isStandaloneOnly = args |> List.contains "--standalone-only"
let isAdaptiveOnly = args |> List.contains "--adaptive-only"
let skipFableLibrary = args |> List.contains "--skip-fable-library"
let isWatch = args |> List.contains "--watch"
let noDotnet = args |> List.contains "--no-dotnet"

if isStandaloneOnly && isReactOnly then
match (isReactOnly, isStandaloneOnly, isAdaptiveOnly) with
| (true, true, _)
| (true, _, true)
| (_, true, true) ->
failwith
"Cannot use --react-only and --standalone-only at the same time"
"Cannot use '--react-only', '--standalone-only' and '--adaptive-only' at the same time"

| _ -> ()

BuildFableLibraryJavaScript().Run(skipFableLibrary)

if isReactOnly then
testReact isWatch
else if isStandaloneOnly then
Standalone.handleStandaloneFast ()
else if isAdaptiveOnly then
testAdaptive isWatch
else
handleMainTests isWatch noDotnet

0 comments on commit 187db25

Please sign in to comment.