|
| 1 | +module EasyBuild.Commands.Test |
| 2 | + |
| 3 | +open Spectre.Console.Cli |
| 4 | +open System.ComponentModel |
| 5 | +open BlackFox.CommandLine |
| 6 | +open SimpleExec |
| 7 | +open EasyBuild.Workspace |
| 8 | +open System.IO |
| 9 | + |
| 10 | +type TestSettings() = |
| 11 | + inherit CommandSettings() |
| 12 | + |
| 13 | + [<CommandOption("-w|--watch")>] |
| 14 | + [<Description("Watch for changes and re-run the tests")>] |
| 15 | + member val IsWatch: bool = false with get, set |
| 16 | + |
| 17 | +let cleanUp (dir: string) = |
| 18 | + let dir = DirectoryInfo(dir) |
| 19 | + |
| 20 | + if dir.Exists then |
| 21 | + dir.Delete(true) |
| 22 | + |
| 23 | +let private outDir = "fableBuild" |
| 24 | + |
| 25 | +let private runTestForJavaScript isWatch cwd = |
| 26 | + let fableArgs = |
| 27 | + CmdLine.concat |
| 28 | + [ |
| 29 | + CmdLine.empty |
| 30 | + |> CmdLine.appendRaw "fable" |
| 31 | + |> CmdLine.appendPrefix "--outDir" outDir |
| 32 | + |> CmdLine.appendRaw "--noCache" |
| 33 | + |> CmdLine.appendRaw "--test:MSBuildCracker" |
| 34 | + |
| 35 | + if isWatch then |
| 36 | + CmdLine.empty |
| 37 | + |> CmdLine.appendRaw "--watch" |
| 38 | + |> CmdLine.appendRaw "--runScript" |
| 39 | + else |
| 40 | + CmdLine.empty |> CmdLine.appendRaw "--runScript" |
| 41 | + ] |
| 42 | + |> CmdLine.toString |
| 43 | + |
| 44 | + Command.Run("dotnet", fableArgs, workingDirectory = cwd) |
| 45 | + |
| 46 | +type TestJavaScriptCommand() = |
| 47 | + inherit Command<TestSettings>() |
| 48 | + interface ICommandLimiter<TestSettings> |
| 49 | + |
| 50 | + override _.Execute(context: CommandContext, settings: TestSettings) = |
| 51 | + // Remove generated files because this folder is used for both JavaScript and TypeScript tests |
| 52 | + cleanUp |
| 53 | + VirtualWorkspace.tests.``Thoth.Json.Tests.JavaScript``.fableBuild.``.`` |
| 54 | + |
| 55 | + runTestForJavaScript |
| 56 | + settings.IsWatch |
| 57 | + Workspace.tests.``Thoth.Json.Tests.JavaScript``.``.`` |
| 58 | + |
| 59 | + 0 |
| 60 | + |
| 61 | + |
| 62 | +type TestNewtonsoftCommand() = |
| 63 | + inherit Command<TestSettings>() |
| 64 | + interface ICommandLimiter<TestSettings> |
| 65 | + |
| 66 | + override _.Execute(context: CommandContext, settings: TestSettings) = |
| 67 | + Command.Run( |
| 68 | + "dotnet", |
| 69 | + CmdLine.empty |
| 70 | + |> CmdLine.appendIf settings.IsWatch "watch" |
| 71 | + |> CmdLine.appendRaw "run" |
| 72 | + |> CmdLine.appendPrefix |
| 73 | + "--project" |
| 74 | + Workspace.tests.``Thoth.Json.Tests.Newtonsoft``.``.`` |
| 75 | + |> CmdLine.toString |
| 76 | + ) |
| 77 | + |
| 78 | + 0 |
| 79 | + |
| 80 | +type TestPythonCommand() = |
| 81 | + inherit Command<TestSettings>() |
| 82 | + interface ICommandLimiter<TestSettings> |
| 83 | + |
| 84 | + override _.Execute(context: CommandContext, settings: TestSettings) = |
| 85 | + let runArg = |
| 86 | + if settings.IsWatch then |
| 87 | + "--runWatch" |
| 88 | + else |
| 89 | + "--run" |
| 90 | + |
| 91 | + Command.Run( |
| 92 | + "dotnet", |
| 93 | + CmdLine.empty |
| 94 | + |> CmdLine.appendRaw "fable" |
| 95 | + |> CmdLine.appendPrefix "--outDir" outDir |
| 96 | + |> CmdLine.appendPrefix "--lang" "python" |
| 97 | + |> CmdLine.appendRaw "--noCache" |
| 98 | + |> CmdLine.appendRaw "--test:MSBuildCracker" |
| 99 | + |> CmdLine.appendIf settings.IsWatch "--watch" |
| 100 | + |> CmdLine.appendRaw runArg |
| 101 | + |> CmdLine.appendRaw "python" |
| 102 | + |> CmdLine.appendRaw "fableBuild/main.py" |
| 103 | + |> CmdLine.appendRaw "--silent" |
| 104 | + |> CmdLine.toString, |
| 105 | + workingDirectory = Workspace.tests.``Thoth.Json.Tests.Python``.``.`` |
| 106 | + ) |
| 107 | + |
| 108 | + 0 |
| 109 | + |
| 110 | +type TestLegacyCommand() = |
| 111 | + inherit Command<TestSettings>() |
| 112 | + interface ICommandLimiter<TestSettings> |
| 113 | + |
| 114 | + override _.Execute(context: CommandContext, settings: TestSettings) = |
| 115 | + runTestForJavaScript |
| 116 | + settings.IsWatch |
| 117 | + Workspace.tests.``Thoth.Json.Tests.Legacy``.``.`` |
| 118 | + |
| 119 | + 0 |
| 120 | + |
| 121 | +type TestTypeScriptCommand() = |
| 122 | + inherit Command<TestSettings>() |
| 123 | + interface ICommandLimiter<TestSettings> |
| 124 | + |
| 125 | + override _.Execute(context: CommandContext, settings: TestSettings) = |
| 126 | + // Remove generated files because this folder is used for both JavaScript and TypeScript tests |
| 127 | + cleanUp |
| 128 | + VirtualWorkspace.tests.``Thoth.Json.Tests.JavaScript``.fableBuild.``.`` |
| 129 | + |
| 130 | + Command.Run( |
| 131 | + "dotnet", |
| 132 | + CmdLine.empty |
| 133 | + |> CmdLine.appendRaw "fable" |
| 134 | + |> CmdLine.appendPrefix "--outDir" outDir |
| 135 | + |> CmdLine.appendPrefix "--lang" "typescript" |
| 136 | + |> CmdLine.appendRaw "--noCache" |
| 137 | + |> CmdLine.appendRaw "--test:MSBuildCracker" |
| 138 | + |> CmdLine.appendIf settings.IsWatch "--watch" |
| 139 | + |> CmdLine.appendRaw "--runWatch" |
| 140 | + |> CmdLine.appendRaw "npx tsc" |
| 141 | + |> CmdLine.toString, |
| 142 | + workingDirectory = |
| 143 | + Workspace.tests.``Thoth.Json.Tests.JavaScript``.``.`` |
| 144 | + ) |
| 145 | + |
| 146 | + 0 |
| 147 | + |
| 148 | +type TestCommand() = |
| 149 | + inherit Command<TestSettings>() |
| 150 | + interface ICommandLimiter<TestSettings> |
| 151 | + |
| 152 | + override _.Execute(context: CommandContext, settings: TestSettings) = |
| 153 | + TestJavaScriptCommand().Execute(context, settings) |> ignore |
| 154 | + // Not stable offically supported, yet as there are bugs that needs to be fixed in Fable |
| 155 | + // TestTypeScriptCommand().Execute(context, settings) |> ignore |
| 156 | + TestNewtonsoftCommand().Execute(context, settings) |> ignore |
| 157 | + TestPythonCommand().Execute(context, settings) |> ignore |
| 158 | + TestLegacyCommand().Execute(context, settings) |> ignore |
| 159 | + |
| 160 | + 0 |
0 commit comments