Skip to content
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
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@
// "type": "node",
// "request": "launch",
// "name": "Run bench-compiler JS tests",
// "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
// "args": ["out-tests"],
// "program": "out-tests/Main.js",
// "args": ["--test"],
// "cwd": "${workspaceRoot}/src/fable-standalone/test/bench-compiler"
// },
// {
Expand Down
1,175 changes: 245 additions & 930 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,27 @@
"name": "fable-compiler",
"scripts": {
"tsc": "tsc",
"mocha": "mocha",
"rollup": "rollup",
"terser": "terser",
"build": "dotnet fsi build_old.fsx",
"publish": "dotnet fsi build_old.fsx publish",
"test": "dotnet run --project src/Fable.Build/Fable.Build.fsproj -- test",
"tests": "mocha temp/tests/JavaScript/Main --reporter dot -t 10000",
"tests": "node --test-reporter spec --test-timeout 20000 --test temp/tests/JavaScript/Main/Main.js",
"tests-ts": "tsc -p temp/tests/TypeScript --outDir temp/tests/TypeScriptCompiled",
"posttests-ts": "node --test-reporter spec --test-timeout 20000 --test temp/tests/TypeScriptCompiled/temp/tests/TypeScript/Main.js",
"build-compiler-js": "dotnet fable src/fable-compiler-js/src/fable-compiler-js.fsproj -o build/fable-compiler-js/out",
"postbuild-compiler-js": "rollup build/fable-compiler-js/out/app.js --file src/fable-compiler-js/dist/app.js --format umd --name Fable",
"minify-compiler-js": "terser src/fable-compiler-js/dist/app.js -o src/fable-compiler-js/dist/app.min.js --mangle --compress",
"test-js": "node src/fable-compiler-js/dist/app.js tests/Main/Fable.Tests.fsproj build/tests-js",
"posttest-js": "mocha build/tests-js --reporter dot -t 10000",
"test-ts": "tsc -p build/tests/TypeScript --outDir build/tests/TypeScriptCompiled",
"posttest-ts": "mocha build/tests/TypeScriptCompiled/build/tests/TypeScript -reporter dot -t 10000"
"tests-compiler-js": "node src/fable-compiler-js/dist/app.js tests/Main/Fable.Tests.fsproj temp/tests-compiler-js",
"posttests-compiler-js": "node --test-reporter spec --test-timeout 20000 --test temp/tests-compiler-js/Main.js"
},
"dependencies": {
"@types/node": "^25.6.0",
"@types/node": "^25.8.0",
"concurrently": "^9.2.1",
"ghreleases": "^3.0.2",
"mocha": "^11.7.5",
"nodemon": "^3.1.14",
"rollup": "^4.60.3",
"terser": "^5.46.2",
"rollup": "^4.60.4",
"terser": "^5.47.1",
"typescript": "^5.9.3"
},
"devDependencies": {
Expand Down
4 changes: 3 additions & 1 deletion src/Fable.Build/Test/Integration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ let private testProjectConfig (projectDirName: string) (configuration: string op
|> CmdLine.appendPrefix "--exclude" "Fable.Core"
|> CmdLine.appendPrefixIfSome "--configuration" configuration

let testArgs = "--test-reporter spec --test-timeout 20000 --test Main.js"

Command.Fable(fableArgs)

Command.Run("npx", "npx mocha . --reporter dot -t 10000", workingDirectory = destinationDir)
Command.Run("node", testArgs, workingDirectory = destinationDir)

let handle (args: string list) =
BuildFableLibraryJavaScript().Run()
Expand Down
30 changes: 14 additions & 16 deletions src/Fable.Build/Test/JavaScript.fs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ let private testAdaptive (isWatch: bool) =

let destinationDir = Path.Resolve("temp", "tests", "JavaScript", folderName)

let mochaCommand =
let testCommand =
CmdLine.empty
|> CmdLine.appendRaw "npx"
|> CmdLine.appendRaw "mocha"
|> CmdLine.appendRaw destinationDir
|> CmdLine.appendPrefix "--reporter" "dot"
|> CmdLine.appendPrefix "-t" "10000"
|> CmdLine.appendRaw "node"
|> CmdLine.appendPrefix "--test-reporter" "spec"
|> CmdLine.appendPrefix "--test-timeout" "20000"
|> CmdLine.appendPrefix "--test" (destinationDir </> "Main.js")
|> CmdLine.toString

Directory.clean destinationDir
Expand All @@ -77,9 +76,9 @@ let private testAdaptive (isWatch: bool) =
CmdLine.empty
|> CmdLine.appendRaw "--watch"
|> CmdLine.appendRaw "--runWatch"
|> CmdLine.appendRaw mochaCommand
|> CmdLine.appendRaw testCommand
else
CmdLine.empty |> CmdLine.appendRaw "--run" |> CmdLine.appendRaw mochaCommand
CmdLine.empty |> CmdLine.appendRaw "--run" |> CmdLine.appendRaw testCommand
]

if isWatch then
Expand All @@ -93,13 +92,12 @@ let private handleMainTests (isWatch: bool) (noDotnet: bool) =

let destinationDir = Path.Resolve("temp", "tests", "JavaScript", folderName)

let mochaCommand =
let testCommand =
CmdLine.empty
|> CmdLine.appendRaw "npx"
|> CmdLine.appendRaw "mocha"
|> CmdLine.appendRaw destinationDir
|> CmdLine.appendPrefix "--reporter" "dot"
|> CmdLine.appendPrefix "-t" "10000"
|> CmdLine.appendRaw "node"
|> CmdLine.appendPrefix "--test-reporter" "spec"
|> CmdLine.appendPrefix "--test-timeout" "20000"
|> CmdLine.appendPrefix "--test" (destinationDir </> "Main.js")
|> CmdLine.toString

Directory.clean destinationDir
Expand All @@ -118,9 +116,9 @@ let private handleMainTests (isWatch: bool) (noDotnet: bool) =
CmdLine.empty
|> CmdLine.appendRaw "--watch"
|> CmdLine.appendRaw "--runWatch"
|> CmdLine.appendRaw mochaCommand
|> CmdLine.appendRaw testCommand
else
CmdLine.empty |> CmdLine.appendRaw "--run" |> CmdLine.appendRaw mochaCommand
CmdLine.empty |> CmdLine.appendRaw "--run" |> CmdLine.appendRaw testCommand
]

if isWatch then
Expand Down
4 changes: 2 additions & 2 deletions src/Fable.Build/Test/Standalone.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open SimpleExec
let private mainTestProject =
Path.Resolve("tests", "Js", "Main", "Fable.Tests.fsproj")

let private mochaCommand = "npx mocha . --reporter dot -t 10000"
let private testArgs = "--test-reporter spec --test-timeout 20000 --test Main.js"

let handleStandaloneFast () =
let fableCompilerJsDir = Path.Resolve("src", "fable-compiler-js", "src")
Expand Down Expand Up @@ -41,7 +41,7 @@ let handleStandaloneFast () =
workingDirectory = fableCompilerJsDir
)

Command.Run("npx", mochaCommand, workingDirectory = standaloneBuildDest)
Command.Run("node", testArgs, workingDirectory = standaloneBuildDest)

let handle (args: string list) =
BuildFableLibraryJavaScript().Run()
Expand Down
10 changes: 6 additions & 4 deletions src/Fable.Build/Test/TypeScript.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ let handle (args: string list) =
Shell.copyFile fableDest (projectDir </> "tsconfig.json")

let tscArgs = $"tsc --outDir {tscDest}"
let mochaArgs = "mocha temp/tests/TypeScript --reporter dot -t 10000"

let testArgs =
"--test-reporter spec --test-timeout 20000 --test temp/tests/TypeScript/Main.js"

let fableArgs =
CmdLine.concat
Expand Down Expand Up @@ -53,8 +55,8 @@ let handle (args: string list) =
// Avoid polluting the logs when a lot of files change at once
|> CmdLine.appendPrefix "--delay" "1s"
|> CmdLine.appendRaw "--exec"
|> CmdLine.appendRaw "\""
|> CmdLine.appendRaw mochaArgs
|> CmdLine.appendRaw "\"node"
|> CmdLine.appendRaw testArgs
|> CmdLine.appendRaw "\""
|> CmdLine.toString

Expand All @@ -80,4 +82,4 @@ let handle (args: string list) =

Command.Run("npx", tscArgs, workingDirectory = fableDest)

Command.Run("npx", mochaArgs, workingDirectory = tscDest)
Command.Run("node", testArgs, workingDirectory = tscDest)
5 changes: 2 additions & 3 deletions src/fable-standalone/test/bench-compiler/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
"build-tests-ts": "npm run build-tests-js -- --fableLib ./out-lib-ts --lang TypeScript",
"build-tests-opt": "npm run build-tests-js -- --optimize",
"build-tests-node": "npm run fable-node -- ../../../../tests/Js/Main/Fable.Tests.fsproj --outDir ./out-tests --fableLib ./out-lib-js --sourceMaps",
"postbuild-tests-js": "npm run mocha -- out-tests --colors --reporter dot -t 10000",
"postbuild-tests-node": "npm run mocha -- out-tests --colors --reporter dot -t 10000",
"postbuild-tests-js": "node --test-reporter spec --test-timeout 20000 --test out-tests/Main.js",
"postbuild-tests-node": "node --test-reporter spec --test-timeout 20000 --test out-tests/Main.js",

"build-tests-rust": "npm run fable -- ../../../../tests/Rust/Fable.Tests.Rust.fsproj --outDir ./out-tests-rust --fableLib ./out-lib-rust --lang Rust",
"build-tests-dart": "npm run fable -- ../../../../tests/Dart/src/Fable.Tests.Dart.fsproj --outDir ./out-tests-dart --fableLib ./out-lib-dart --lang Dart",
Expand All @@ -84,7 +84,6 @@

"tsc": "node ../../../../node_modules/typescript/bin/tsc",
"babel": "node ../../../../node_modules/@babel/cli/bin/babel",
"mocha": "node ../../../../node_modules/mocha/bin/mocha",
"rollup": "node ../../../../node_modules/rollup/dist/bin/rollup",
"terser": "node ../../../../node_modules/terser/bin/terser",
"webpack": "node ../../../../node_modules/webpack-cli/bin/cli.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
<Compile Include="Main.fs" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ open Fable.Core
open Fable.Core.JsInterop
open Fable.Core.Testing

let [<Global>] describe (name: string) (f: unit->unit) : unit = jsNative
let [<Global>] it (msg: string) (f: unit->unit) : unit = jsNative
let inline describe (name: string) (f: unit->unit) : unit = import "describe" "node:test"
let inline it (msg: string) (f: unit->unit) : unit = import "it" "node:test"

let equals expected actual = Assert.AreEqual(actual, expected)

describe "ConsoleApp" (fun () ->
Expand Down
5 changes: 3 additions & 2 deletions tests/Integration/ProjectConfigs/CustomConfiguration/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ open Fable.Core
open Fable.Core.JsInterop
open Fable.Core.Testing

let [<Global>] describe (name: string) (f: unit->unit) : unit = jsNative
let [<Global>] it (msg: string) (f: unit->unit) : unit = jsNative
let inline describe (name: string) (f: unit->unit) : unit = import "describe" "node:test"
let inline it (msg: string) (f: unit->unit) : unit = import "it" "node:test"

let equals expected actual = Assert.AreEqual(actual, expected)

describe "CustomConfiguration" (fun () ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ open Fable.Core
open Fable.Core.JsInterop
open Fable.Core.Testing

let [<Global>] describe (name: string) (f: unit->unit) : unit = jsNative
let [<Global>] it (msg: string) (f: unit->unit) : unit = jsNative
let inline describe (name: string) (f: unit->unit) : unit = import "describe" "node:test"
let inline it (msg: string) (f: unit->unit) : unit = import "it" "node:test"

let equals expected actual = Assert.AreEqual(actual, expected)

describe "DebugWithExtraDefines" (fun () ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ open Fable.Core
open Fable.Core.JsInterop
open Fable.Core.Testing

let [<Global>] describe (name: string) (f: unit->unit) : unit = jsNative
let [<Global>] it (msg: string) (f: unit->unit) : unit = jsNative
let inline describe (name: string) (f: unit->unit) : unit = import "describe" "node:test"
let inline it (msg: string) (f: unit->unit) : unit = import "it" "node:test"

let equals expected actual = Assert.AreEqual(actual, expected)

describe "ReleaseNoExtraDefines" (fun () ->
Expand Down
4 changes: 2 additions & 2 deletions tests/Js/Adaptive/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ let allTests =
open Fable.Core
open Fable.Core.JsInterop

let [<Global>] describe (name: string) (f: unit->unit) : unit = jsNative
let [<Global>] it (msg: string) (f: unit->unit) : unit = jsNative
let inline describe (name: string) (f: unit->unit) : unit = import "describe" "node:test"
let inline it (msg: string) (f: unit->unit) : unit = import "it" "node:test"


let rec flattenTest (test: Util.Testing.TestKind) : unit =
Expand Down
24 changes: 12 additions & 12 deletions tests/Js/Main/DateTimeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,18 +1127,6 @@ let tests =

t |> equal (TimeSpan(0, 13, 23, 30, 1))

testCaseAsync "Timer with AutoReset = true works" <| fun () ->
async {
let res = ref 0
let t = new Timers.Timer(50.)
t.Elapsed.Add(fun ev -> res := !res + 5)
t.Start()
do! Async.Sleep 125
t.Stop()
do! Async.Sleep 50
equal 10 !res
}

testCaseAsync "Timer with AutoReset = false works" <| fun () ->
async {
let res = ref 0
Expand All @@ -1151,6 +1139,18 @@ let tests =
equal 5 !res
}

testCaseAsync "Timer with AutoReset = true works" <| fun () ->
async {
let res = ref 0
let t = new Timers.Timer(50.)
t.Elapsed.Add(fun ev -> res := !res + 5)
t.Start()
do! Async.Sleep 125
t.Stop()
do! Async.Sleep 50
equal 10 !res
}

testCaseAsync "Timer.Elapsed.Subscribe works" <| fun () ->
async {
let res = ref 0
Expand Down
2 changes: 1 addition & 1 deletion tests/Js/Main/InlineIfLambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let tests =
let result =
applyPairTwice
(fun a b ->
printfn "Adding %d and %d" a b
// printfn "Adding %d and %d" a b
a + b
)
10
Expand Down
4 changes: 2 additions & 2 deletions tests/Js/Main/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ open Fable.Core.JsInterop
// but not available in node.js runtime
importSideEffects "./js/polyfill.js"

let [<Global>] describe (name: string) (f: unit->unit) : unit = jsNative
let [<Global>] it (msg: string) (f: unit->unit) : unit = jsNative
let inline describe (name: string) (f: unit->unit) : unit = import "describe" "node:test"
let inline it (msg: string) (f: unit->unit) : unit = import "it" "node:test"


let rec flattenTest (test: Util.Testing.TestKind) : unit =
Expand Down
2 changes: 1 addition & 1 deletion tests/Python/TestInlineIfLambda.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ let ``test InlineIfLambda with two parameters works`` () =
let result =
applyPairTwice
(fun a b ->
printfn "Adding %d and %d" a b
// printfn "Adding %d and %d" a b
a + b
)
10
Expand Down
10 changes: 2 additions & 8 deletions tests/TypeScript/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,8 @@ open Fable.Core.JsInterop
// but not available in node.js runtime
importSideEffects "../Js/Main/js/polyfill.js"

let [<Global>] describe (name: string) (f: unit->unit) : unit = jsNative
let [<Global>] it (msg: string) (f: unit->unit) : unit = jsNative

// TODO: Emit declarations automatically when there are global variables
emitJsStatement () """
declare var it: any;
declare var describe: any;
"""
let inline describe (name: string) (f: unit->unit) : unit = import "describe" "node:test"
let inline it (msg: string) (f: unit->unit) : unit = import "it" "node:test"

let rec flattenTest (test: Util.Testing.TestKind) : unit =
match test with
Expand Down
Loading