diff --git a/src/Fable.Build/Main.fs b/src/Fable.Build/Main.fs index 14d5e85a21..114dc2200a 100644 --- a/src/Fable.Build/Main.fs +++ b/src/Fable.Build/Main.fs @@ -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) diff --git a/src/Fable.Build/SimpleExec.Extensions.fs b/src/Fable.Build/SimpleExec.Extensions.fs index 7696f8fa38..f9f7046194 100644 --- a/src/Fable.Build/SimpleExec.Extensions.fs +++ b/src/Fable.Build/SimpleExec.Extensions.fs @@ -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 + ) diff --git a/src/Fable.Build/Test/JavaScript.fs b/src/Fable.Build/Test/JavaScript.fs index 1377711305..235cf74c72 100644 --- a/src/Fable.Build/Test/JavaScript.fs +++ b/src/Fable.Build/Test/JavaScript.fs @@ -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) @@ -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 @@ -123,13 +167,19 @@ 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) @@ -137,5 +187,7 @@ let handle (args: string list) = testReact isWatch else if isStandaloneOnly then Standalone.handleStandaloneFast () + else if isAdaptiveOnly then + testAdaptive isWatch else handleMainTests isWatch noDotnet