Skip to content

Commit

Permalink
Run test both in debug and production mode
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Sep 10, 2019
1 parent e549bb1 commit 7fe56ba
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 17 deletions.
30 changes: 19 additions & 11 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() =
Expand Down
6 changes: 6 additions & 0 deletions src/fable-compiler-js/src/ProjectParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ let parseCompilerOptions projectText =
// get conditional defines
let defines =
Regex.Matches(projectText, @"<DefineConstants[^>]*>([^<]*)<\/DefineConstants[^>]*>")
|> Seq.cast<Match>
|> Seq.collect (fun m -> m.Groups.[1].Value.Split(';'))
|> Seq.append ["FABLE_COMPILER"]
|> Seq.map (fun s -> s.Trim())
Expand All @@ -40,6 +41,7 @@ let parseCompilerOptions projectText =
// get disabled warnings
let nowarns =
Regex.Matches(projectText, @"<NoWarn[^>]*>([^<]*)<\/NoWarn[^>]*>")
|> Seq.cast<Match>
|> Seq.collect (fun m -> m.Groups.[1].Value.Split(';'))
|> Seq.map (fun s -> s.Trim())
|> Seq.distinct
Expand All @@ -49,6 +51,7 @@ let parseCompilerOptions projectText =
// get warnings as errors
let warnAsErrors =
Regex.Matches(projectText, @"<WarningsAsErrors[^>]*>([^<]*)<\/WarningsAsErrors[^>]*>")
|> Seq.cast<Match>
|> Seq.collect (fun m -> m.Groups.[1].Value.Split(';'))
|> Seq.map (fun s -> s.Trim())
|> Seq.distinct
Expand All @@ -58,6 +61,7 @@ let parseCompilerOptions projectText =
// get other flags
let otherFlags =
Regex.Matches(projectText, @"<OtherFlags[^>]*>([^<]*)<\/OtherFlags[^>]*>")
|> Seq.cast<Match>
|> Seq.collect (fun m -> m.Groups.[1].Value.Split(' '))
|> Seq.map (fun s -> s.Trim())
|> Seq.distinct
Expand Down Expand Up @@ -105,6 +109,7 @@ let parseProjectFile projectFileName =
// get project references
let projectRefs =
Regex.Matches(projectText, @"<ProjectReference\s+[^>]*Include\s*=\s*(""[^""]*|'[^']*)")
|> Seq.cast<Match>
|> Seq.map (fun m -> m.Groups.[1].Value.TrimStart('"').TrimStart(''').Trim().Replace("\\", "/"))
|> Seq.toArray

Expand All @@ -118,6 +123,7 @@ let parseProjectFile projectFileName =
let sourceFilesRegex = @"<Compile\s+[^>]*Include\s*=\s*(""[^""]*|'[^']*)"
let sourceFiles =
Regex.Matches(projectText, sourceFilesRegex)
|> Seq.cast<Match>
|> Seq.map (fun m -> m.Groups.[1].Value.TrimStart('"').TrimStart(''').Trim().Replace("\\", "/"))
|> Seq.toArray

Expand Down
9 changes: 6 additions & 3 deletions src/fable-compiler-js/src/app.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ let getMetadataDir(): string = importDefault "fable-metadata"
let getFableLibDir(): string = importMember "./util.js"
#endif

[<Emit("process.argv.slice(2)")>]
let argv: string[] = jsNative

let references = Fable.Standalone.Metadata.references_core
let metadataPath = getMetadataDir().TrimEnd('\\', '/') + "/" // .NET BCL binaries (metadata)

Expand Down Expand Up @@ -127,10 +130,10 @@ let parseArguments (argv: string[]) =
run opts projectFileName outDir
| _ -> printfn "%s" usage

[<EntryPoint>]
let main argv =
let main() =
try
parseArguments argv
with ex ->
printfn "Error: %A" ex.Message
0

main()
5 changes: 2 additions & 3 deletions src/fable-compiler-js/src/fable-compiler-js.fsproj
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
<DefineConstants>$(DefineConstants);FABLE_COMPILER</DefineConstants>
</PropertyGroup>

<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions src/fable-library/System.Text.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 7fe56ba

Please sign in to comment.