From 7fe56ba19f9e601b0c3b16f5325feb209db19579 Mon Sep 17 00:00:00 2001 From: Alfonso Garcia-Caro Date: Mon, 9 Sep 2019 15:39:58 +0200 Subject: [PATCH] Run test both in debug and production mode --- build.fsx | 30 ++++++++++++------- src/fable-compiler-js/src/ProjectParser.fs | 6 ++++ src/fable-compiler-js/src/app.fs | 9 ++++-- .../src/fable-compiler-js.fsproj | 5 ++-- src/fable-library/System.Text.fs | 1 + 5 files changed, 34 insertions(+), 17 deletions(-) diff --git a/build.fsx b/build.fsx index b57d4e24d3..d111862ac9 100644 --- a/build.fsx +++ b/build.fsx @@ -98,9 +98,10 @@ let buildCompilerJs testLocal = let buildStandalone() = let projectDir = "src/fable-standalone" let libraryDir = "build/fable-library" - cleanDirs [projectDir "dist"] - buildLibrary() + if pathExists libraryDir |> not then + buildLibrary() + cleanDirs [projectDir "dist"] // bundle.min.js buildWebpack projectDir fileSizeInBytes (projectDir "dist/bundle.min.js") / 1000 @@ -135,20 +136,27 @@ let test() = if pathExists "build/fable-library" |> not then buildLibrary() - cleanDirs ["build/tests"] - buildSplitter "tests" - run "npx mocha build/tests --reporter dot -t 10000" - runInDir "tests/Main" "dotnet run" + let runTestsInNodeWithArgs args = + cleanDirs ["build/tests"] + buildSplitterWithArgs "tests" args + run "npx mocha build/tests --reporter dot -t 10000" + + runTestsInNodeWithArgs "--debug" + runTestsInNodeWithArgs "" runInDir "tests/Fable.Cli.Test" "dotnet run" if envVarOrNone "APPVEYOR" |> Option.isSome then buildStandalone() // Test fable-compiler-js locally - buildCompilerJs true - run "node src/fable-compiler-js tests/Main/Fable.Tests.fsproj build/tests-js --commonjs" - run "npx mocha build/tests-js --reporter dot -t 10000" - // runInDir "src/fable-compiler-js/test" "node .. test_script.fsx --commonjs" - // runInDir "src/fable-compiler-js/test" "node bin/test_script.js" + // Not sure why, but building fable-compiler-js immediately after fable-standalone + // is failing, let's wait a couple of seconds to see if that helps + JS.setTimeout (fun () -> + buildCompilerJs true + run "node src/fable-compiler-js tests/Main/Fable.Tests.fsproj build/tests-js --commonjs" + run "npx mocha build/tests-js --reporter dot -t 10000" + // runInDir "src/fable-compiler-js/test" "node .. test_script.fsx --commonjs" + // runInDir "src/fable-compiler-js/test" "node bin/test_script.js" + ) 2000 |> ignore let coverage() = diff --git a/src/fable-compiler-js/src/ProjectParser.fs b/src/fable-compiler-js/src/ProjectParser.fs index eac497e38b..3018967a4b 100644 --- a/src/fable-compiler-js/src/ProjectParser.fs +++ b/src/fable-compiler-js/src/ProjectParser.fs @@ -30,6 +30,7 @@ let parseCompilerOptions projectText = // get conditional defines let defines = Regex.Matches(projectText, @"]*>([^<]*)<\/DefineConstants[^>]*>") + |> Seq.cast |> Seq.collect (fun m -> m.Groups.[1].Value.Split(';')) |> Seq.append ["FABLE_COMPILER"] |> Seq.map (fun s -> s.Trim()) @@ -40,6 +41,7 @@ let parseCompilerOptions projectText = // get disabled warnings let nowarns = Regex.Matches(projectText, @"]*>([^<]*)<\/NoWarn[^>]*>") + |> Seq.cast |> Seq.collect (fun m -> m.Groups.[1].Value.Split(';')) |> Seq.map (fun s -> s.Trim()) |> Seq.distinct @@ -49,6 +51,7 @@ let parseCompilerOptions projectText = // get warnings as errors let warnAsErrors = Regex.Matches(projectText, @"]*>([^<]*)<\/WarningsAsErrors[^>]*>") + |> Seq.cast |> Seq.collect (fun m -> m.Groups.[1].Value.Split(';')) |> Seq.map (fun s -> s.Trim()) |> Seq.distinct @@ -58,6 +61,7 @@ let parseCompilerOptions projectText = // get other flags let otherFlags = Regex.Matches(projectText, @"]*>([^<]*)<\/OtherFlags[^>]*>") + |> Seq.cast |> Seq.collect (fun m -> m.Groups.[1].Value.Split(' ')) |> Seq.map (fun s -> s.Trim()) |> Seq.distinct @@ -105,6 +109,7 @@ let parseProjectFile projectFileName = // get project references let projectRefs = Regex.Matches(projectText, @"]*Include\s*=\s*(""[^""]*|'[^']*)") + |> Seq.cast |> Seq.map (fun m -> m.Groups.[1].Value.TrimStart('"').TrimStart(''').Trim().Replace("\\", "/")) |> Seq.toArray @@ -118,6 +123,7 @@ let parseProjectFile projectFileName = let sourceFilesRegex = @"]*Include\s*=\s*(""[^""]*|'[^']*)" let sourceFiles = Regex.Matches(projectText, sourceFilesRegex) + |> Seq.cast |> Seq.map (fun m -> m.Groups.[1].Value.TrimStart('"').TrimStart(''').Trim().Replace("\\", "/")) |> Seq.toArray diff --git a/src/fable-compiler-js/src/app.fs b/src/fable-compiler-js/src/app.fs index e038a4e857..88df614375 100644 --- a/src/fable-compiler-js/src/app.fs +++ b/src/fable-compiler-js/src/app.fs @@ -16,6 +16,9 @@ let getMetadataDir(): string = importDefault "fable-metadata" let getFableLibDir(): string = importMember "./util.js" #endif +[] +let argv: string[] = jsNative + let references = Fable.Standalone.Metadata.references_core let metadataPath = getMetadataDir().TrimEnd('\\', '/') + "/" // .NET BCL binaries (metadata) @@ -127,10 +130,10 @@ let parseArguments (argv: string[]) = run opts projectFileName outDir | _ -> printfn "%s" usage -[] -let main argv = +let main() = try parseArguments argv with ex -> printfn "Error: %A" ex.Message - 0 + +main() diff --git a/src/fable-compiler-js/src/fable-compiler-js.fsproj b/src/fable-compiler-js/src/fable-compiler-js.fsproj index cfad1181f7..6c91060406 100644 --- a/src/fable-compiler-js/src/fable-compiler-js.fsproj +++ b/src/fable-compiler-js/src/fable-compiler-js.fsproj @@ -1,8 +1,7 @@ - - Exe - netcoreapp2.1 + netstandard2.0 + $(DefineConstants);FABLE_COMPILER diff --git a/src/fable-library/System.Text.fs b/src/fable-library/System.Text.fs index fd646b21bf..5de694cd43 100644 --- a/src/fable-library/System.Text.fs +++ b/src/fable-library/System.Text.fs @@ -7,5 +7,6 @@ type StringBuilder(value: string, capacity: int) = new (value: string) = StringBuilder(value, 16) new () = StringBuilder(null, 16) member x.Append(s: string) = buf.Add(s); x + member x.Append(c: char) = buf.Add(string c); x member x.AppendFormat(fmt: string, o: obj) = buf.Add(System.String.Format(fmt, o)); x override __.ToString() = System.String.Concat(buf)