From e4b084098b6dc0ff82c3bda064f17cb305ab2fd0 Mon Sep 17 00:00:00 2001 From: Jaz Thomson Date: Fri, 18 Oct 2024 15:48:21 +0100 Subject: [PATCH 1/6] Don't restore as part of dotnet watch operation --- Content/default/Build.fs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Content/default/Build.fs b/Content/default/Build.fs index 42bf08ff..6b1b36fa 100644 --- a/Content/default/Build.fs +++ b/Content/default/Build.fs @@ -45,11 +45,12 @@ Target.create "Azure" (fun _ -> deployment |> Deploy.execute "SAFE-App" Deploy.NoParameters |> ignore) Target.create "Run" (fun _ -> + run dotnet [ "restore"; "SAFE.App.sln" ] "." run dotnet [ "build" ] sharedPath [ - "server", dotnet [ "watch"; "run" ] serverPath - "client", dotnet [ "fable"; "watch"; "-o"; "output"; "-s"; "--run"; "npx"; "vite" ] clientPath + "server", dotnet [ "watch"; "run"; "--no-restore" ] serverPath + "client", dotnet [ "fable"; "watch"; "--noRestore"; "-o"; "output"; "-s"; "--run"; "npx"; "vite" ] clientPath ] |> runParallel) From 3cc702418a0336584dd771bd2126ce91cf4896ef Mon Sep 17 00:00:00 2001 From: Joost Kaptein Date: Fri, 15 Nov 2024 17:22:02 +0000 Subject: [PATCH 2/6] fixed sln name --- Content/default/{SAFE.App.sln => Application.sln} | 0 Content/default/Build.fs | 3 +-- 2 files changed, 1 insertion(+), 2 deletions(-) rename Content/default/{SAFE.App.sln => Application.sln} (100%) diff --git a/Content/default/SAFE.App.sln b/Content/default/Application.sln similarity index 100% rename from Content/default/SAFE.App.sln rename to Content/default/Application.sln diff --git a/Content/default/Build.fs b/Content/default/Build.fs index 6b1b36fa..33a72c00 100644 --- a/Content/default/Build.fs +++ b/Content/default/Build.fs @@ -45,8 +45,7 @@ Target.create "Azure" (fun _ -> deployment |> Deploy.execute "SAFE-App" Deploy.NoParameters |> ignore) Target.create "Run" (fun _ -> - run dotnet [ "restore"; "SAFE.App.sln" ] "." - run dotnet [ "build" ] sharedPath + run dotnet [ "build"; "Application.sln" ] "." [ "server", dotnet [ "watch"; "run"; "--no-restore" ] serverPath From 96b7cad68641c16874cf1055c0bdbdaefd39ec97 Mon Sep 17 00:00:00 2001 From: Joost Kaptein Date: Fri, 22 Nov 2024 12:27:07 +0000 Subject: [PATCH 3/6] Make template execution test output more readable --- tests/Tests.fs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/Tests.fs b/tests/Tests.fs index c4959040..648c57fa 100644 --- a/tests/Tests.fs +++ b/tests/Tests.fs @@ -45,10 +45,10 @@ let run exe arg dir = CreateProcess.fromRawCommandLine exe arg |> CreateProcess.withWorkingDirectory dir - |> CreateProcess.ensureExitCode |> CreateProcess.redirectOutputIfNotRedirected |> Proc.run - |> ignore + |> (fun x -> Expect.equal x.ExitCode 0 $"Unexpected exit code when running {exe} {arg} in {dir}") + open System.Threading.Tasks @@ -209,11 +209,10 @@ let testTemplateBuild templateType = testCase $"{templateType}" <| fun () -> eventX "Run target for `{type}` run successfully" >> setField "type" templateType) if templateType = Normal then - run dotnet "run -- bundle" dir + run dotnet "run bundle" dir logger.info( eventX "Bundle target for `{type}` run successfully" >> setField "type" templateType) finally killProcessTree proc.Id extraProc |> Option.map (fun (p,_) -> p.Id) |> Option.iter killProcessTree - From 4b8bd1c47be9279a5acccb6bc3b362ce19186fe6 Mon Sep 17 00:00:00 2001 From: Joost Kaptein Date: Fri, 22 Nov 2024 12:56:55 +0000 Subject: [PATCH 4/6] Ensure resources are free before running bundle test --- tests/Tests.fs | 111 ++++++++++++++++++++++++++----------------------- 1 file changed, 59 insertions(+), 52 deletions(-) diff --git a/tests/Tests.fs b/tests/Tests.fs index 648c57fa..1b79f5a7 100644 --- a/tests/Tests.fs +++ b/tests/Tests.fs @@ -155,64 +155,71 @@ type TemplateType = Normal | Minimal let path = __SOURCE_DIRECTORY__ ".." "Content" -let testTemplateBuild templateType = testCase $"{templateType}" <| fun () -> +let testTemplateBuild templateType = let dir = if templateType = Normal then path "default" else path "minimal" + testList $"{templateType}" [ - run dotnet "tool restore" dir + testCase "run" (fun () -> - if templateType = Minimal then - // run build on Shared to avoid race condition between Client and Server - run dotnet "build" (dir "src" "Shared") + run dotnet "tool restore" dir - if templateType = Normal then - run dotnet "run" (dir "tests" "Server") + if templateType = Minimal then + // run build on Shared to avoid race condition between Client and Server + run dotnet "build" (dir "src" "Shared") - let proc = if templateType = Normal then - start dotnet "run" dir - else - run npm "install" dir - start dotnet "fable watch --run vite" (dir "src" "Client" ) + run dotnet "run" (dir "tests" "Server") - let extraProc = - if templateType = Normal then None - else - let proc = start dotnet "run" (dir "src" "Server") - let wait = waitForStdOut proc "Now listening on:" - Some (proc, wait) - - let stdOutPhrase = "ready in" - let htmlSearchPhrase = """SAFE Template""" - //vite will not serve up from root - let clientUrl = "http://localhost:8080/index.html" - let serverUrl, searchPhrase = - match templateType with - | Normal -> "http://localhost:5000/api/ITodosApi/getTodos", "Create new SAFE project" // JSON should contain a todo with such description - | Minimal -> "http://localhost:5000/api/hello", "Hello from SAFE!" - try - let timeout = TimeSpan.FromMinutes 5. - waitForStdOut proc stdOutPhrase timeout |> Async.RunSynchronously - logger.info( - eventX "Requesting `{url}`" - >> setField "url" clientUrl) - let response = waitAndRetry 3 5 (fun () -> get clientUrl) - Expect.stringContains response htmlSearchPhrase - (sprintf "html fragment not found for %A" templateType) - extraProc |> Option.iter (fun (_, wait) -> Async.RunSynchronously (wait timeout)) - logger.info( - eventX "Requesting `{url}`" - >> setField "url" serverUrl) - let response = get serverUrl - Expect.stringContains response searchPhrase - (sprintf "plaintext fragment not found for %A at %s" templateType serverUrl) - logger.info( - eventX "Run target for `{type}` run successfully" - >> setField "type" templateType) - if templateType = Normal then - run dotnet "run bundle" dir + let proc = + if templateType = Normal then + start dotnet "run" dir + else + run npm "install" dir + start dotnet "fable watch --run vite" (dir "src" "Client" ) + + let extraProc = + if templateType = Normal then None + else + let proc = start dotnet "run" (dir "src" "Server") + let wait = waitForStdOut proc "Now listening on:" + Some (proc, wait) + + let stdOutPhrase = "ready in" + let htmlSearchPhrase = """SAFE Template""" + //vite will not serve up from root + let clientUrl = "http://localhost:8080/index.html" + let serverUrl, searchPhrase = + match templateType with + | Normal -> "http://localhost:5000/api/ITodosApi/getTodos", "Create new SAFE project" // JSON should contain a todo with such description + | Minimal -> "http://localhost:5000/api/hello", "Hello from SAFE!" + try + let timeout = TimeSpan.FromMinutes 5. + waitForStdOut proc stdOutPhrase timeout |> Async.RunSynchronously logger.info( - eventX "Bundle target for `{type}` run successfully" + eventX "Requesting `{url}`" + >> setField "url" clientUrl) + let response = waitAndRetry 3 5 (fun () -> get clientUrl) + Expect.stringContains response htmlSearchPhrase + (sprintf "html fragment not found for %A" templateType) + extraProc |> Option.iter (fun (_, wait) -> Async.RunSynchronously (wait timeout)) + logger.info( + eventX "Requesting `{url}`" + >> setField "url" serverUrl) + let response = get serverUrl + Expect.stringContains response searchPhrase + (sprintf "plaintext fragment not found for %A at %s" templateType serverUrl) + logger.info( + eventX "Run target for `{type}` run successfully" >> setField "type" templateType) - finally - killProcessTree proc.Id - extraProc |> Option.map (fun (p,_) -> p.Id) |> Option.iter killProcessTree + finally + killProcessTree proc.Id + extraProc |> Option.map (fun (p,_) -> p.Id) |> Option.iter killProcessTree + ) + + if templateType = Normal then + testCase "Bundle" (fun () -> + run dotnet "run bundle" dir + logger.info( + eventX "Bundle target for `{type}` run successfully" + >> setField "type" templateType)) + ] From 82f12f09f9494940910acaf2eb1c4fb8c0d1d57a Mon Sep 17 00:00:00 2001 From: Joost Kaptein Date: Fri, 22 Nov 2024 13:45:54 +0000 Subject: [PATCH 5/6] restore full solution, only build shared --- Content/default/Build.fs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Content/default/Build.fs b/Content/default/Build.fs index 33a72c00..10331c88 100644 --- a/Content/default/Build.fs +++ b/Content/default/Build.fs @@ -45,7 +45,8 @@ Target.create "Azure" (fun _ -> deployment |> Deploy.execute "SAFE-App" Deploy.NoParameters |> ignore) Target.create "Run" (fun _ -> - run dotnet [ "build"; "Application.sln" ] "." + run dotnet [ "restore"; "Application.sln" ] "." + run dotnet [ "build" ] sharedPath [ "server", dotnet [ "watch"; "run"; "--no-restore" ] serverPath From 123f6a303f657e037bbb0de706304022e3b45a4f Mon Sep 17 00:00:00 2001 From: Joost Kaptein Date: Fri, 22 Nov 2024 14:04:28 +0000 Subject: [PATCH 6/6] do allow restore for fable --- Content/default/Build.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content/default/Build.fs b/Content/default/Build.fs index 10331c88..02349d29 100644 --- a/Content/default/Build.fs +++ b/Content/default/Build.fs @@ -50,7 +50,7 @@ Target.create "Run" (fun _ -> [ "server", dotnet [ "watch"; "run"; "--no-restore" ] serverPath - "client", dotnet [ "fable"; "watch"; "--noRestore"; "-o"; "output"; "-s"; "--run"; "npx"; "vite" ] clientPath + "client", dotnet [ "fable"; "watch"; "-o"; "output"; "-s"; "--run"; "npx"; "vite" ] clientPath ] |> runParallel)