Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Js Adaptive tests #3710

Merged
merged 1 commit into from
Jan 23, 2024
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
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
Loading