Skip to content

Commit 80ca8ff

Browse files
committed
fix: [JS/TS/Tests] Remove mocha to resolve package vulnerabilities
1 parent ba9857a commit 80ca8ff

18 files changed

Lines changed: 301 additions & 989 deletions

File tree

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@
151151
// "type": "node",
152152
// "request": "launch",
153153
// "name": "Run bench-compiler JS tests",
154-
// "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
155-
// "args": ["out-tests"],
154+
// "program": "out-tests/Main.js",
155+
// "args": ["--test"],
156156
// "cwd": "${workspaceRoot}/src/fable-standalone/test/bench-compiler"
157157
// },
158158
// {

package-lock.json

Lines changed: 245 additions & 930 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,27 @@
44
"name": "fable-compiler",
55
"scripts": {
66
"tsc": "tsc",
7-
"mocha": "mocha",
87
"rollup": "rollup",
98
"terser": "terser",
109
"build": "dotnet fsi build_old.fsx",
1110
"publish": "dotnet fsi build_old.fsx publish",
1211
"test": "dotnet run --project src/Fable.Build/Fable.Build.fsproj -- test",
13-
"tests": "mocha temp/tests/JavaScript/Main --reporter dot -t 10000",
12+
"tests": "node --test temp/tests/JavaScript/Main/Main.js",
1413
"build-compiler-js": "dotnet fable src/fable-compiler-js/src/fable-compiler-js.fsproj -o build/fable-compiler-js/out",
1514
"postbuild-compiler-js": "rollup build/fable-compiler-js/out/app.js --file src/fable-compiler-js/dist/app.js --format umd --name Fable",
1615
"minify-compiler-js": "terser src/fable-compiler-js/dist/app.js -o src/fable-compiler-js/dist/app.min.js --mangle --compress",
1716
"test-js": "node src/fable-compiler-js/dist/app.js tests/Main/Fable.Tests.fsproj build/tests-js",
18-
"posttest-js": "mocha build/tests-js --reporter dot -t 10000",
17+
"posttest-js": "node --test build/tests-js/Main.js",
1918
"test-ts": "tsc -p build/tests/TypeScript --outDir build/tests/TypeScriptCompiled",
20-
"posttest-ts": "mocha build/tests/TypeScriptCompiled/build/tests/TypeScript -reporter dot -t 10000"
19+
"posttest-ts": "node --test build/tests/TypeScriptCompiled/build/tests/TypeScript/Main.js"
2120
},
2221
"dependencies": {
23-
"@types/node": "^25.6.0",
22+
"@types/node": "^25.8.0",
2423
"concurrently": "^9.2.1",
2524
"ghreleases": "^3.0.2",
26-
"mocha": "^11.7.5",
2725
"nodemon": "^3.1.14",
28-
"rollup": "^4.60.3",
29-
"terser": "^5.46.2",
26+
"rollup": "^4.60.4",
27+
"terser": "^5.47.1",
3028
"typescript": "^5.9.3"
3129
},
3230
"devDependencies": {

src/Fable.Build/Test/Integration.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ let private testProjectConfig (projectDirName: string) (configuration: string op
2929
|> CmdLine.appendPrefix "--exclude" "Fable.Core"
3030
|> CmdLine.appendPrefixIfSome "--configuration" configuration
3131

32+
let testArgs = "--test-reporter spec --test-timeout 10000 --test Main.js"
33+
3234
Command.Fable(fableArgs)
3335

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

3638
let handle (args: string list) =
3739
BuildFableLibraryJavaScript().Run()

src/Fable.Build/Test/JavaScript.fs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,12 @@ let private testAdaptive (isWatch: bool) =
5252

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

55-
let mochaCommand =
55+
let testCommand =
5656
CmdLine.empty
57-
|> CmdLine.appendRaw "npx"
58-
|> CmdLine.appendRaw "mocha"
59-
|> CmdLine.appendRaw destinationDir
60-
|> CmdLine.appendPrefix "--reporter" "dot"
61-
|> CmdLine.appendPrefix "-t" "10000"
57+
|> CmdLine.appendRaw "node"
58+
|> CmdLine.appendPrefix "--test-reporter" "spec"
59+
|> CmdLine.appendPrefix "--test-timeout" "10000"
60+
|> CmdLine.appendPrefix "--test" (destinationDir </> "Main.js")
6261
|> CmdLine.toString
6362

6463
Directory.clean destinationDir
@@ -77,9 +76,9 @@ let private testAdaptive (isWatch: bool) =
7776
CmdLine.empty
7877
|> CmdLine.appendRaw "--watch"
7978
|> CmdLine.appendRaw "--runWatch"
80-
|> CmdLine.appendRaw mochaCommand
79+
|> CmdLine.appendRaw testCommand
8180
else
82-
CmdLine.empty |> CmdLine.appendRaw "--run" |> CmdLine.appendRaw mochaCommand
81+
CmdLine.empty |> CmdLine.appendRaw "--run" |> CmdLine.appendRaw testCommand
8382
]
8483

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

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

96-
let mochaCommand =
95+
let testCommand =
9796
CmdLine.empty
98-
|> CmdLine.appendRaw "npx"
99-
|> CmdLine.appendRaw "mocha"
100-
|> CmdLine.appendRaw destinationDir
101-
|> CmdLine.appendPrefix "--reporter" "dot"
102-
|> CmdLine.appendPrefix "-t" "10000"
97+
|> CmdLine.appendRaw "node"
98+
|> CmdLine.appendPrefix "--test-reporter" "spec"
99+
|> CmdLine.appendPrefix "--test-timeout" "10000"
100+
|> CmdLine.appendPrefix "--test" (destinationDir </> "Main.js")
103101
|> CmdLine.toString
104102

105103
Directory.clean destinationDir
@@ -118,9 +116,9 @@ let private handleMainTests (isWatch: bool) (noDotnet: bool) =
118116
CmdLine.empty
119117
|> CmdLine.appendRaw "--watch"
120118
|> CmdLine.appendRaw "--runWatch"
121-
|> CmdLine.appendRaw mochaCommand
119+
|> CmdLine.appendRaw testCommand
122120
else
123-
CmdLine.empty |> CmdLine.appendRaw "--run" |> CmdLine.appendRaw mochaCommand
121+
CmdLine.empty |> CmdLine.appendRaw "--run" |> CmdLine.appendRaw testCommand
124122
]
125123

126124
if isWatch then

src/Fable.Build/Test/Standalone.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ open SimpleExec
1111
let private mainTestProject =
1212
Path.Resolve("tests", "Js", "Main", "Fable.Tests.fsproj")
1313

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

1616
let handleStandaloneFast () =
1717
let fableCompilerJsDir = Path.Resolve("src", "fable-compiler-js", "src")
@@ -41,7 +41,7 @@ let handleStandaloneFast () =
4141
workingDirectory = fableCompilerJsDir
4242
)
4343

44-
Command.Run("npx", mochaCommand, workingDirectory = standaloneBuildDest)
44+
Command.Run("node", testArgs, workingDirectory = standaloneBuildDest)
4545

4646
let handle (args: string list) =
4747
BuildFableLibraryJavaScript().Run()

src/Fable.Build/Test/TypeScript.fs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ let handle (args: string list) =
2424
Shell.copyFile fableDest (projectDir </> "tsconfig.json")
2525

2626
let tscArgs = $"tsc --outDir {tscDest}"
27-
let mochaArgs = "mocha temp/tests/TypeScript --reporter dot -t 10000"
27+
28+
let testArgs =
29+
"--test-randomize --test-reporter spec --test-timeout 10000 --test temp/tests/TypeScript/Main.js"
2830

2931
let fableArgs =
3032
CmdLine.concat
@@ -53,8 +55,8 @@ let handle (args: string list) =
5355
// Avoid polluting the logs when a lot of files change at once
5456
|> CmdLine.appendPrefix "--delay" "1s"
5557
|> CmdLine.appendRaw "--exec"
56-
|> CmdLine.appendRaw "\""
57-
|> CmdLine.appendRaw mochaArgs
58+
|> CmdLine.appendRaw "\"node"
59+
|> CmdLine.appendRaw testArgs
5860
|> CmdLine.appendRaw "\""
5961
|> CmdLine.toString
6062

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

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

83-
Command.Run("npx", mochaArgs, workingDirectory = tscDest)
85+
Command.Run("node", testArgs, workingDirectory = tscDest)

src/fable-standalone/test/bench-compiler/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
"build-tests-ts": "npm run build-tests-js -- --fableLib ./out-lib-ts --lang TypeScript",
7171
"build-tests-opt": "npm run build-tests-js -- --optimize",
7272
"build-tests-node": "npm run fable-node -- ../../../../tests/Js/Main/Fable.Tests.fsproj --outDir ./out-tests --fableLib ./out-lib-js --sourceMaps",
73-
"postbuild-tests-js": "npm run mocha -- out-tests --colors --reporter dot -t 10000",
74-
"postbuild-tests-node": "npm run mocha -- out-tests --colors --reporter dot -t 10000",
73+
"postbuild-tests-js": "node --test-reporter spec --test-timeout 10000 --test out-tests/Main.js",
74+
"postbuild-tests-node": "node --test-reporter spec --test-timeout 10000 --test out-tests/Main.js",
7575

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

8585
"tsc": "node ../../../../node_modules/typescript/bin/tsc",
8686
"babel": "node ../../../../node_modules/@babel/cli/bin/babel",
87-
"mocha": "node ../../../../node_modules/mocha/bin/mocha",
8887
"rollup": "node ../../../../node_modules/rollup/dist/bin/rollup",
8988
"terser": "node ../../../../node_modules/terser/bin/terser",
9089
"webpack": "node ../../../../node_modules/webpack-cli/bin/cli.js",

tests/Integration/ProjectConfigs/ConsoleApp/Fable.Tests.ConsoleApp.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<Compile Include="Program.fs" />
10+
<Compile Include="Main.fs" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

tests/Integration/ProjectConfigs/ConsoleApp/Program.fs renamed to tests/Integration/ProjectConfigs/ConsoleApp/Main.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ open Fable.Core
44
open Fable.Core.JsInterop
55
open Fable.Core.Testing
66

7-
let [<Global>] describe (name: string) (f: unit->unit) : unit = jsNative
8-
let [<Global>] it (msg: string) (f: unit->unit) : unit = jsNative
7+
let inline describe (name: string) (f: unit->unit) : unit = import "describe" "node:test"
8+
let inline it (msg: string) (f: unit->unit) : unit = import "it" "node:test"
9+
910
let equals expected actual = Assert.AreEqual(actual, expected)
1011

1112
describe "ConsoleApp" (fun () ->

0 commit comments

Comments
 (0)