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

Restore as a standalone operation and remove from watch #634

Merged
merged 6 commits into from
Nov 22, 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
File renamed without changes.
3 changes: 2 additions & 1 deletion Content/default/Build.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ Target.create "Azure" (fun _ ->
deployment |> Deploy.execute "SAFE-App" Deploy.NoParameters |> ignore)

Target.create "Run" (fun _ ->
run dotnet [ "restore"; "Application.sln" ] "."
run dotnet [ "build" ] sharedPath

[
"server", dotnet [ "watch"; "run" ] serverPath
"server", dotnet [ "watch"; "run"; "--no-restore" ] serverPath
"client", dotnet [ "fable"; "watch"; "-o"; "output"; "-s"; "--run"; "npx"; "vite" ] clientPath
]
|> runParallel)
Expand Down
114 changes: 60 additions & 54 deletions tests/Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -155,65 +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 = """<title>SAFE Template</title>"""
//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 = """<title>SAFE Template</title>"""
//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 "Bundle target for `{type}` run successfully"
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))
]