Skip to content

Commit

Permalink
Fixed test projects running on incorrect ports, added local introspec…
Browse files Browse the repository at this point in the history
…tion update in `build.fsx`
  • Loading branch information
Andrii Chebukin authored and xperiandri committed Jan 24, 2023
1 parent a73b688 commit fb6f128
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
7 changes: 5 additions & 2 deletions FSharp.Data.GraphQL.Integration.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 17
VisualStudioVersion = 17.5.33312.197
MinimumVisualStudioVersion = 15.0.26124.0
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "FSharp.Data.GraphQL.IntegrationTests", "tests\FSharp.Data.GraphQL.IntegrationTests\FSharp.Data.GraphQL.IntegrationTests.fsproj", "{09D910E6-94EF-46AF-94DF-10A9FEC837C0}"
EndProject
Expand All @@ -14,6 +14,9 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{BDE03396-2ED6-4153-B94C-351BAB3F67BD}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{BA7F22E2-D411-4229-826B-F55FF171D12A}"
ProjectSection(SolutionItems) = preProject
build.fsx = build.fsx
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
1 change: 1 addition & 0 deletions FSharp.Data.GraphQL.sln
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
global.json = global.json
LICENSE.txt = LICENSE.txt
Packages.props = Packages.props
Prepare template project for packing.ps1 = Prepare template project for packing.ps1
README.md = README.md
RELEASE_NOTES.md = RELEASE_NOTES.md
EndProjectSection
Expand Down
21 changes: 17 additions & 4 deletions build.fsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
open System.Net.Http


#r "nuget: Fake.Api.GitHub"
#r "nuget: Fake.Core.ReleaseNotes"
#r "nuget: Fake.Core.Target"
Expand Down Expand Up @@ -72,7 +75,7 @@ Target.create "Build" <| fun _ ->
Configuration = DotNet.BuildConfiguration.Release
MSBuildParams = { o.MSBuildParams with DisableInternalBinLog = true } })

let startGraphQLServer (project : string) (streamRef : DataRef<Stream>) =
let startGraphQLServer (project : string) port (streamRef : DataRef<Stream>) =
DotNet.build
(fun options ->
{ options with
Expand All @@ -90,7 +93,7 @@ let startGraphQLServer (project : string) (streamRef : DataRef<Stream>) =
</> DotNetMoniker
</> (projectName + ".dll")

CreateProcess.fromRawCommandLine "dotnet" $"{serverExe} --urls=http://localhost:8086/"
CreateProcess.fromRawCommandLine "dotnet" $"{serverExe} --urls=http://localhost:%i{port}/"
|> CreateProcess.withStandardInput (CreatePipe streamRef)
|> Proc.start
|> ignore
Expand Down Expand Up @@ -123,7 +126,7 @@ Target.create "StartStarWarsServer" <| fun _ ->
</> "star-wars-api"
</> "FSharp.Data.GraphQL.Samples.StarWarsApi.fsproj"

startGraphQLServer project starWarsServerStream
startGraphQLServer project 8086 starWarsServerStream

Target.createFinal "StopStarWarsServer" <| fun _ ->
try
Expand All @@ -141,14 +144,23 @@ Target.create "StartIntegrationServer" <| fun _ ->
</> "FSharp.Data.GraphQL.IntegrationTests.Server"
</> "FSharp.Data.GraphQL.IntegrationTests.Server.fsproj"

startGraphQLServer project integrationServerStream
startGraphQLServer project 8085 integrationServerStream

Target.createFinal "StopIntegrationServer" <| fun _ ->
try
integrationServerStream.Value.Write ([| 0uy |], 0, 1)
with e ->
printfn "%s" e.Message

Target.create "UpdateIntrospectionFile" <| fun _ ->
let client = new HttpClient ()
let result = client.GetAsync("http://localhost:8086").Result
let file = new FileStream("tests/FSharp.Data.GraphQL.IntegrationTests/introspection.json", FileMode.Create, FileAccess.Write, FileShare.None)
result.Content.CopyTo(file, null, System.Threading.CancellationToken.None)
file.Close()
result.Dispose()
client.Dispose()

Target.create "RunUnitTests" <| fun _ ->
runTests "tests/FSharp.Data.GraphQL.Tests/FSharp.Data.GraphQL.Tests.fsproj"

Expand Down Expand Up @@ -249,6 +261,7 @@ Target.create "PackAll" ignore
==> "RunUnitTests"
==> "StartStarWarsServer"
==> "StartIntegrationServer"
==> "UpdateIntrospectionFile"
==> "RunIntegrationTests"
==> "All"
=?> ("GenerateDocs", Environment.environVar "APPVEYOR" = "True")
Expand Down
5 changes: 1 addition & 4 deletions tests/FSharp.Data.GraphQL.IntegrationTests.Server/Program.fs
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
namespace FSharp.Data.GraphQL.IntegrationTests.Server
namespace FSharp.Data.GraphQL.IntegrationTests.Server

open Microsoft.AspNetCore
open Microsoft.AspNetCore.Hosting

module Program =
let exitCode = 0

let [<Literal>] BaseAddress = "localhost:8085"

let buildWebHost args =
WebHost
.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseUrls(sprintf "http://%s" BaseAddress)

[<EntryPoint>]
let main args =
Expand Down

0 comments on commit fb6f128

Please sign in to comment.