Skip to content

Commit 4b8bd1c

Browse files
committed
Ensure resources are free before running bundle test
1 parent 96b7cad commit 4b8bd1c

File tree

1 file changed

+59
-52
lines changed

1 file changed

+59
-52
lines changed

tests/Tests.fs

+59-52
Original file line numberDiff line numberDiff line change
@@ -155,64 +155,71 @@ type TemplateType = Normal | Minimal
155155

156156
let path = __SOURCE_DIRECTORY__ </> ".." </> "Content"
157157

158-
let testTemplateBuild templateType = testCase $"{templateType}" <| fun () ->
158+
let testTemplateBuild templateType =
159159
let dir = if templateType = Normal then path </> "default" else path </> "minimal"
160+
testList $"{templateType}" [
160161

161-
run dotnet "tool restore" dir
162+
testCase "run" (fun () ->
162163

163-
if templateType = Minimal then
164-
// run build on Shared to avoid race condition between Client and Server
165-
run dotnet "build" (dir </> "src" </> "Shared")
164+
run dotnet "tool restore" dir
166165

167-
if templateType = Normal then
168-
run dotnet "run" (dir </> "tests" </> "Server")
166+
if templateType = Minimal then
167+
// run build on Shared to avoid race condition between Client and Server
168+
run dotnet "build" (dir </> "src" </> "Shared")
169169

170-
let proc =
171170
if templateType = Normal then
172-
start dotnet "run" dir
173-
else
174-
run npm "install" dir
175-
start dotnet "fable watch --run vite" (dir </> "src" </> "Client" )
171+
run dotnet "run" (dir </> "tests" </> "Server")
176172

177-
let extraProc =
178-
if templateType = Normal then None
179-
else
180-
let proc = start dotnet "run" (dir </> "src" </> "Server")
181-
let wait = waitForStdOut proc "Now listening on:"
182-
Some (proc, wait)
183-
184-
let stdOutPhrase = "ready in"
185-
let htmlSearchPhrase = """<title>SAFE Template</title>"""
186-
//vite will not serve up from root
187-
let clientUrl = "http://localhost:8080/index.html"
188-
let serverUrl, searchPhrase =
189-
match templateType with
190-
| Normal -> "http://localhost:5000/api/ITodosApi/getTodos", "Create new SAFE project" // JSON should contain a todo with such description
191-
| Minimal -> "http://localhost:5000/api/hello", "Hello from SAFE!"
192-
try
193-
let timeout = TimeSpan.FromMinutes 5.
194-
waitForStdOut proc stdOutPhrase timeout |> Async.RunSynchronously
195-
logger.info(
196-
eventX "Requesting `{url}`"
197-
>> setField "url" clientUrl)
198-
let response = waitAndRetry 3 5 (fun () -> get clientUrl)
199-
Expect.stringContains response htmlSearchPhrase
200-
(sprintf "html fragment not found for %A" templateType)
201-
extraProc |> Option.iter (fun (_, wait) -> Async.RunSynchronously (wait timeout))
202-
logger.info(
203-
eventX "Requesting `{url}`"
204-
>> setField "url" serverUrl)
205-
let response = get serverUrl
206-
Expect.stringContains response searchPhrase
207-
(sprintf "plaintext fragment not found for %A at %s" templateType serverUrl)
208-
logger.info(
209-
eventX "Run target for `{type}` run successfully"
210-
>> setField "type" templateType)
211-
if templateType = Normal then
212-
run dotnet "run bundle" dir
173+
let proc =
174+
if templateType = Normal then
175+
start dotnet "run" dir
176+
else
177+
run npm "install" dir
178+
start dotnet "fable watch --run vite" (dir </> "src" </> "Client" )
179+
180+
let extraProc =
181+
if templateType = Normal then None
182+
else
183+
let proc = start dotnet "run" (dir </> "src" </> "Server")
184+
let wait = waitForStdOut proc "Now listening on:"
185+
Some (proc, wait)
186+
187+
let stdOutPhrase = "ready in"
188+
let htmlSearchPhrase = """<title>SAFE Template</title>"""
189+
//vite will not serve up from root
190+
let clientUrl = "http://localhost:8080/index.html"
191+
let serverUrl, searchPhrase =
192+
match templateType with
193+
| Normal -> "http://localhost:5000/api/ITodosApi/getTodos", "Create new SAFE project" // JSON should contain a todo with such description
194+
| Minimal -> "http://localhost:5000/api/hello", "Hello from SAFE!"
195+
try
196+
let timeout = TimeSpan.FromMinutes 5.
197+
waitForStdOut proc stdOutPhrase timeout |> Async.RunSynchronously
213198
logger.info(
214-
eventX "Bundle target for `{type}` run successfully"
199+
eventX "Requesting `{url}`"
200+
>> setField "url" clientUrl)
201+
let response = waitAndRetry 3 5 (fun () -> get clientUrl)
202+
Expect.stringContains response htmlSearchPhrase
203+
(sprintf "html fragment not found for %A" templateType)
204+
extraProc |> Option.iter (fun (_, wait) -> Async.RunSynchronously (wait timeout))
205+
logger.info(
206+
eventX "Requesting `{url}`"
207+
>> setField "url" serverUrl)
208+
let response = get serverUrl
209+
Expect.stringContains response searchPhrase
210+
(sprintf "plaintext fragment not found for %A at %s" templateType serverUrl)
211+
logger.info(
212+
eventX "Run target for `{type}` run successfully"
215213
>> setField "type" templateType)
216-
finally
217-
killProcessTree proc.Id
218-
extraProc |> Option.map (fun (p,_) -> p.Id) |> Option.iter killProcessTree
214+
finally
215+
killProcessTree proc.Id
216+
extraProc |> Option.map (fun (p,_) -> p.Id) |> Option.iter killProcessTree
217+
)
218+
219+
if templateType = Normal then
220+
testCase "Bundle" (fun () ->
221+
run dotnet "run bundle" dir
222+
logger.info(
223+
eventX "Bundle target for `{type}` run successfully"
224+
>> setField "type" templateType))
225+
]

0 commit comments

Comments
 (0)