forked from fable-compiler/Fable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJavaScript.fs
More file actions
181 lines (148 loc) · 6.3 KB
/
Copy pathJavaScript.fs
File metadata and controls
181 lines (148 loc) · 6.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
module Build.Test.JavaScript
open Build.FableLibrary
open System.IO
open System
open BlackFox.CommandLine
open Build.Utils
open Build
open SimpleExec
let private mainTestSourceDir = Path.Resolve("tests", "Js", "Main")
let private mainTestProject =
Path.Resolve("tests", "Js", "Main", "Fable.Tests.fsproj")
let private testReact (isWatch: bool) =
let workingDirectory = Path.Resolve("tests", "React")
Command.Run("npm", "install", workingDirectory = workingDirectory)
if isWatch then
Async.Parallel
[
Command.WatchFableAsync(
CmdLine.appendRaw "watch"
>> CmdLine.appendRaw "--noCache"
// There seems to be some strange console Log writting
>> CmdLine.appendRaw "--verbose"
>> CmdLine.appendRaw "--runWatch"
>> CmdLine.appendRaw "npx jest",
workingDirectory = workingDirectory
)
|> Async.AwaitTask
// Running both command in the same shell don't seems to be working as expected.
// For now, we expect the user to use `./build.sh test javascript --react-only --watch`
// and `npx jest --watch` in a second terminal
// Command.RunAsync("npx", "jest --watch", workingDirectory = workingDirectory)
// |> Async.AwaitTask
]
|> Async.RunSynchronously
|> ignore
else
Command.Fable(CmdLine.appendRaw "--noCache", workingDirectory = workingDirectory)
Command.Run("npx", "jest", workingDirectory = workingDirectory)
let private testAdaptive (isWatch: bool) =
let folderName = "Adaptive"
let sourceDir = Path.Resolve("tests", "Js", folderName)
let destinationDir = Path.Resolve("temp", "tests", "JavaScript", folderName)
let testCommand =
CmdLine.empty
|> CmdLine.appendRaw "node"
|> CmdLine.appendPrefix "--test-reporter" "spec"
|> CmdLine.appendPrefix "--test-timeout" "20000"
|> CmdLine.appendPrefix "--test" (destinationDir </> "Main.js")
|> CmdLine.toString
Directory.clean destinationDir
let fableArgs =
CmdLine.concat
[
CmdLine.empty
|> CmdLine.appendRaw sourceDir
|> CmdLine.appendPrefix "--outDir" destinationDir
|> CmdLine.appendPrefix "--lang" "javascript"
|> CmdLine.appendPrefix "--exclude" "Fable.Core"
|> CmdLine.appendRaw "--noCache"
if isWatch then
CmdLine.empty
|> CmdLine.appendRaw "--watch"
|> CmdLine.appendRaw "--runWatch"
|> CmdLine.appendRaw testCommand
else
CmdLine.empty |> CmdLine.appendRaw "--run" |> CmdLine.appendRaw testCommand
]
if isWatch then
Command.WatchFable(fableArgs, workingDirectory = destinationDir)
else
Command.Fable(fableArgs, workingDirectory = destinationDir)
let private handleMainTests (isWatch: bool) (noDotnet: bool) =
let folderName = "Main"
let sourceDir = Path.Resolve("tests", "Js", folderName)
let destinationDir = Path.Resolve("temp", "tests", "JavaScript", folderName)
let testCommand =
CmdLine.empty
|> CmdLine.appendRaw "node"
|> CmdLine.appendPrefix "--test-reporter" "spec"
|> CmdLine.appendPrefix "--test-timeout" "20000"
|> CmdLine.appendPrefix "--test" (destinationDir </> "Main.js")
|> CmdLine.toString
Directory.clean destinationDir
let fableArgs =
CmdLine.concat
[
CmdLine.empty
|> CmdLine.appendRaw sourceDir
|> CmdLine.appendPrefix "--outDir" destinationDir
|> CmdLine.appendPrefix "--lang" "javascript"
|> CmdLine.appendPrefix "--exclude" "Fable.Core"
|> CmdLine.appendRaw "--noCache"
if isWatch then
CmdLine.empty
|> CmdLine.appendRaw "--watch"
|> CmdLine.appendRaw "--runWatch"
|> CmdLine.appendRaw testCommand
else
CmdLine.empty |> CmdLine.appendRaw "--run" |> CmdLine.appendRaw testCommand
]
if isWatch then
// In watch mode, we only test the Main tests to not pollute the logs too much
Async.Parallel
[
if not noDotnet then
Command.RunAsync(
"dotnet",
"watch run -c Release",
workingDirectory = Path.Combine("tests", "Js", "Main")
)
|> Async.AwaitTask
Command.WatchFableAsync(fableArgs, workingDirectory = destinationDir)
|> Async.AwaitTask
]
|> Async.RunSynchronously
|> ignore
else
Command.Run("dotnet", "run -c Release", workingDirectory = Path.Combine("tests", "Js", "Main"))
// Test the Main tests against JavaScript
Command.Fable(fableArgs, workingDirectory = destinationDir)
testReact false
testAdaptive false
// let isCI = Environment.GetEnvironmentVariable("CI") |> Option.ofObj
// standalone will be tested by a separate CI job
// if isCI.IsSome then
// Standalone.handleStandaloneFast ()
let handle (args: string list) =
let isReactOnly = args |> List.contains "--react-only"
let isStandaloneOnly = args |> List.contains "--standalone-only"
let isAdaptiveOnly = args |> List.contains "--adaptive-only"
let forceFableLibrary = args |> List.contains "--force-fable-library"
let isWatch = args |> List.contains "--watch"
let noDotnet = args |> List.contains "--no-dotnet"
match (isReactOnly, isStandaloneOnly, isAdaptiveOnly) with
| (true, true, _)
| (true, _, true)
| (_, true, true) ->
failwith "Cannot use '--react-only', '--standalone-only' and '--adaptive-only' at the same time"
| _ -> ()
BuildFableLibraryJavaScript().Run(forceFableLibrary)
if isReactOnly then
testReact isWatch
else if isStandaloneOnly then
Standalone.handleStandaloneFast ()
else if isAdaptiveOnly then
testAdaptive isWatch
else
handleMainTests isWatch noDotnet