Skip to content

Commit d0dcfe5

Browse files
committed
build: add --temporal-only flag to the JavaScript test command
1 parent adb4ac4 commit d0dcfe5

2 files changed

Lines changed: 37 additions & 41 deletions

File tree

src/Fable.Build/Main.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ Available commands:
5959
(can be run in watch mode)
6060
--adaptive-only Run only the tests for the adaptive version of Fable
6161
(can be run in watch mode)
62+
--temporal-only Run only the main tests, compiled with the Temporal
63+
date/time representation (can be run in watch mode)
6264
6365
6466
Options for Rust:

src/Fable.Build/Test/JavaScript.fs

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -86,41 +86,20 @@ let private testAdaptive (isWatch: bool) =
8686
else
8787
Command.Fable(fableArgs, workingDirectory = destinationDir)
8888

89-
// Second JS pass with the Temporal date/time representation enabled (--test:js-temporal).
90-
let private handleMainTestsTemporal () =
91-
let folderName = "Main"
92-
let sourceDir = Path.Resolve("tests", "Js", folderName)
93-
94-
let destinationDir = Path.Resolve("temp", "tests", "JavaScriptTemporal", folderName)
95-
96-
Directory.clean destinationDir
97-
98-
// Compile the whole Main project with the Temporal representation enabled
99-
let fableArgs =
100-
CmdLine.empty
101-
|> CmdLine.appendRaw sourceDir
102-
|> CmdLine.appendPrefix "--outDir" destinationDir
103-
|> CmdLine.appendPrefix "--lang" "javascript"
104-
|> CmdLine.appendPrefix "--exclude" "Fable.Core"
105-
|> CmdLine.appendRaw "--noCache"
106-
|> CmdLine.appendRaw "--test:js-temporal"
107-
108-
Command.Fable(fableArgs, workingDirectory = destinationDir)
89+
type private DateTimeRepresentation =
90+
| JsDate
91+
| Temporal
10992

110-
let nodeArgs =
111-
CmdLine.empty
112-
|> CmdLine.appendPrefix "--test-reporter" "spec"
113-
|> CmdLine.appendPrefix "--test-timeout" "20000"
114-
|> CmdLine.appendPrefix "--test" (destinationDir </> "Main.js")
115-
|> CmdLine.toString
116-
117-
Command.Run("node", nodeArgs, workingDirectory = destinationDir)
118-
119-
let private handleMainTests (isWatch: bool) (noDotnet: bool) =
93+
let private runMainTests (representation: DateTimeRepresentation) (isWatch: bool) (noDotnet: bool) =
12094
let folderName = "Main"
12195
let sourceDir = Path.Resolve("tests", "Js", folderName)
12296

123-
let destinationDir = Path.Resolve("temp", "tests", "JavaScript", folderName)
97+
let outputFolder =
98+
match representation with
99+
| JsDate -> "JavaScript"
100+
| Temporal -> "JavaScriptTemporal"
101+
102+
let destinationDir = Path.Resolve("temp", "tests", outputFolder, folderName)
124103

125104
let testCommand =
126105
CmdLine.empty
@@ -141,6 +120,7 @@ let private handleMainTests (isWatch: bool) (noDotnet: bool) =
141120
|> CmdLine.appendPrefix "--lang" "javascript"
142121
|> CmdLine.appendPrefix "--exclude" "Fable.Core"
143122
|> CmdLine.appendRaw "--noCache"
123+
|> CmdLine.appendIf (representation = Temporal) "--test:js-temporal"
144124

145125
if isWatch then
146126
CmdLine.empty
@@ -152,7 +132,6 @@ let private handleMainTests (isWatch: bool) (noDotnet: bool) =
152132
]
153133

154134
if isWatch then
155-
// In watch mode, we only test the Main tests to not pollute the logs too much
156135
Async.Parallel
157136
[
158137
if not noDotnet then
@@ -168,14 +147,21 @@ let private handleMainTests (isWatch: bool) (noDotnet: bool) =
168147
]
169148
|> Async.RunSynchronously
170149
|> ignore
150+
else
151+
Command.Fable(fableArgs, workingDirectory = destinationDir)
152+
153+
let private handleMainTests (isWatch: bool) (noDotnet: bool) =
154+
if isWatch then
155+
// In watch mode, we only test the Main tests to not pollute the logs too much
156+
runMainTests JsDate isWatch noDotnet
171157
else
172158
Command.Run("dotnet", "run -c Release", workingDirectory = Path.Combine("tests", "Js", "Main"))
173159

174160
// Test the Main tests against JavaScript
175-
Command.Fable(fableArgs, workingDirectory = destinationDir)
161+
runMainTests JsDate false noDotnet
176162

177-
// Re-run the date/time suites with the Temporal representation enabled
178-
handleMainTestsTemporal ()
163+
// Re-run them with the Temporal date/time representation enabled
164+
runMainTests Temporal false noDotnet
179165

180166
testReact false
181167
testAdaptive false
@@ -190,17 +176,23 @@ let handle (args: string list) =
190176
let isReactOnly = args |> List.contains "--react-only"
191177
let isStandaloneOnly = args |> List.contains "--standalone-only"
192178
let isAdaptiveOnly = args |> List.contains "--adaptive-only"
179+
let isTemporalOnly = args |> List.contains "--temporal-only"
193180
let forceFableLibrary = args |> List.contains "--force-fable-library"
194181
let isWatch = args |> List.contains "--watch"
195182
let noDotnet = args |> List.contains "--no-dotnet"
196183

197-
match (isReactOnly, isStandaloneOnly, isAdaptiveOnly) with
198-
| (true, true, _)
199-
| (true, _, true)
200-
| (_, true, true) ->
201-
failwith "Cannot use '--react-only', '--standalone-only' and '--adaptive-only' at the same time"
184+
let exclusiveArgs =
185+
[
186+
"--react-only", isReactOnly
187+
"--standalone-only", isStandaloneOnly
188+
"--adaptive-only", isAdaptiveOnly
189+
"--temporal-only", isTemporalOnly
190+
]
191+
|> List.filter snd
192+
|> List.map (fun (name, _) -> $"'%s{name}'")
202193

203-
| _ -> ()
194+
if exclusiveArgs.Length > 1 then
195+
failwith $"""Cannot use %s{String.Join(", ", exclusiveArgs)} at the same time"""
204196

205197
BuildFableLibraryJavaScript().Run(forceFableLibrary)
206198

@@ -210,5 +202,7 @@ let handle (args: string list) =
210202
Standalone.handleStandaloneFast ()
211203
else if isAdaptiveOnly then
212204
testAdaptive isWatch
205+
else if isTemporalOnly then
206+
runMainTests Temporal isWatch noDotnet
213207
else
214208
handleMainTests isWatch noDotnet

0 commit comments

Comments
 (0)