Skip to content

Commit 542c564

Browse files
committed
DebugMode
1 parent 8c9bf45 commit 542c564

19 files changed

+772
-106
lines changed

TODO.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# TODO
22

3+
- Assert.expectToMatchSnaphot - element screenshot comparing
4+
35
- windows support
46
- setup automatic tests for each supported target
57
- screenshots of elements

host/loglist/loglist.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package loglist
2+
3+
var (
4+
logLinesPerTest = make(map[int64]([]string))
5+
currentTest int64 = 0
6+
)
7+
8+
// FIXME - good enough for know, but will be a pain point in the future
9+
10+
func IncrementCurrentTest() {
11+
currentTest++
12+
}
13+
14+
func GetCurrentTest() int64 {
15+
return currentTest
16+
}
17+
18+
func AddLogForTest(message string) {
19+
testIndex := currentTest
20+
21+
// make sure to make a copy of the str - this memory will be realocated
22+
bytesCopy := make([]byte, len(message))
23+
copy(bytesCopy, []byte(message))
24+
messageCopy := string(bytesCopy)
25+
26+
messages, ok := logLinesPerTest[testIndex]
27+
if ok {
28+
messages = append(messages, messageCopy)
29+
logLinesPerTest[testIndex] = messages
30+
} else {
31+
logLinesPerTest[testIndex] = []string{messageCopy}
32+
}
33+
}
34+
35+
func GetLogsForTest(testIndex int64) []string {
36+
messages, ok := logLinesPerTest[testIndex]
37+
if ok {
38+
return messages
39+
} else {
40+
return make([]string, 0)
41+
}
42+
}

host/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func main() {
1515
options := roc.Options{
1616
SetupOnly: false,
1717
PrintBrowserVersionOnly: false,
18+
DebugMode: false,
1819
}
1920

2021
// os.Args is a slice of strings
@@ -32,6 +33,9 @@ func main() {
3233
case "--headless":
3334
// TODO - this will be provided by the Roc app
3435
options.Headless = true
36+
case "--debug":
37+
// TODO - this will be provided by the Roc app
38+
options.DebugMode = true
3539
}
3640
}
3741

host/roc/app.go

+33-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "C"
66
import (
77
"fmt"
88
"host/driversetup"
9+
"host/loglist"
910
"host/setup"
1011
"host/utils"
1112
"host/webdriver"
@@ -19,10 +20,15 @@ type Options struct {
1920
SetupOnly bool
2021
PrintBrowserVersionOnly bool
2122
Headless bool
23+
DebugMode bool
2224
}
2325

2426
// TODO change when passing more than 1 value from Roc app is possible
25-
var headless = false
27+
var (
28+
headless = false
29+
// TODO should be passed from Roc app ?
30+
isDebugMode = false
31+
)
2632

2733
func Main(options Options) int {
2834
if options.PrintBrowserVersionOnly {
@@ -34,6 +40,10 @@ func Main(options Options) int {
3440
headless = true
3541
}
3642

43+
if options.DebugMode {
44+
isDebugMode = true
45+
}
46+
3747
err := driversetup.DownloadChromeAndDriver()
3848
if err != nil {
3949
fmt.Println(utils.FG_RED+"Setup failed with: "+utils.RESET, err)
@@ -85,9 +95,22 @@ func Main(options Options) int {
8595
}
8696
}
8797

98+
//export roc_fx_incrementTest
99+
func roc_fx_incrementTest() C.struct_ResultVoidStr {
100+
loglist.IncrementCurrentTest()
101+
return createRocResultStr(RocOk, "")
102+
}
103+
104+
//export roc_fx_getLogsForTest
105+
func roc_fx_getLogsForTest(testIndex int64) C.struct_ResultListStr {
106+
logs := loglist.GetLogsForTest(testIndex)
107+
return createRocResult_ListStr_Str(RocOk, logs, "")
108+
}
109+
88110
//export roc_fx_stdoutLine
89111
func roc_fx_stdoutLine(msg *RocStr) C.struct_ResultVoidStr {
90112
fmt.Println(msg)
113+
loglist.AddLogForTest(msg.String())
91114
return createRocResultStr(RocOk, "")
92115
}
93116

@@ -454,6 +477,15 @@ func roc_fx_getTimeMilis() C.struct_ResultI64Str {
454477
return createRocResultI64(RocOk, now, "")
455478
}
456479

480+
//export roc_fx_isDebugMode
481+
func roc_fx_isDebugMode() C.struct_ResultI64Str {
482+
isDebugModeInt := 0
483+
if isDebugMode {
484+
isDebugModeInt = 1
485+
}
486+
return createRocResultI64(RocOk, int64(isDebugModeInt), "")
487+
}
488+
457489
//export roc_fx_createDirIfNotExist
458490
func roc_fx_createDirIfNotExist(path *RocStr) C.struct_ResultVoidStr {
459491
err := os.MkdirAll(filepath.Dir(path.String()), os.ModePerm)

platform/BasicHtmlReporter.roc

+64-16
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ reporter = Reporting.createReporter "basicHtmlReporter" \results, meta ->
2323

2424
[{ filePath: "index.html", content: htmlStr }]
2525

26-
resultToHtml = \{ name, result, duration, screenshot } ->
26+
resultToHtml = \{ name, result, duration, screenshot, logs } ->
2727
safeName = name |> htmlEncode
2828
isOk = result |> Result.isOk
2929
class = if isOk then "ok" else "error"
30-
testDetails = getTestDetails result screenshot
30+
testDetails = getTestDetails result screenshot logs
3131
testDuration = (Num.toFrac duration) / 1000 |> fracToStr
3232

3333
"""
@@ -40,12 +40,32 @@ resultToHtml = \{ name, result, duration, screenshot } ->
4040
</li>
4141
"""
4242

43-
getTestDetails = \result, screenshot ->
43+
getTestDetails = \result, screenshot, logs ->
4444
when result is
45-
Ok {} -> ""
45+
Ok {} if logs |> List.isEmpty ->
46+
"""
47+
<div class="test-details">
48+
<div class="block">
49+
<div class="output">
50+
-
51+
</div>
52+
</div>
53+
</div>
54+
"""
55+
56+
Ok {} ->
57+
"""
58+
<div class="test-details">
59+
<div class="block">
60+
<div class="output">
61+
$(printLogs logs)
62+
</div>
63+
</div>
64+
</div>
65+
"""
66+
4667
Err err ->
4768
safeMsg = err |> handleError |> htmlEncode
48-
# optionalScreenshot = "wow"
4969
optionalScreenshot =
5070
when screenshot is
5171
NoScreenshot -> ""
@@ -57,13 +77,32 @@ getTestDetails = \result, screenshot ->
5777
<div class="test-details">
5878
<div class="block">
5979
<div class="output">
60-
$(safeMsg)
80+
$(printLogs logs)
81+
<div class="error-message">
82+
$(safeMsg)
83+
</div>
6184
</div>
6285
</div>
6386
$(optionalScreenshot)
6487
</div>
6588
"""
6689

90+
printLogs = \logs ->
91+
if logs |> List.isEmpty then
92+
""
93+
else
94+
items =
95+
logs
96+
|> List.map \log ->
97+
"""
98+
<li>$(log |> htmlEncode)</li>
99+
"""
100+
|> Str.joinWith ""
101+
102+
"""
103+
<ul class="log-list">$(items)</ul>
104+
"""
105+
67106
handleError = \errorTag ->
68107
when Error.webDriverErrorToStr errorTag is
69108
StringError msg -> msg
@@ -186,6 +225,11 @@ getHtml = \duration, successCount, errorCount, resultsContent ->
186225
list-style-type: square;
187226
}
188227
228+
ul.log-list {
229+
list-style-type: square;
230+
padding-left: 18px;
231+
}
232+
189233
li.ok {
190234
color: var(--ok-color);
191235
}
@@ -195,11 +239,18 @@ getHtml = \duration, successCount, errorCount, resultsContent ->
195239
}
196240
197241
.output {
242+
display: flex;
243+
flex-direction: column;
244+
gap: 1em;
198245
color: var(--text-color);
199246
font-family: system-ui, sans-serif;
200247
font-weight: normal;
201248
}
202249
250+
.error-message {
251+
color: var(--error-color);
252+
}
253+
203254
.test-header {
204255
cursor: pointer;
205256
display: flex;
@@ -215,10 +266,7 @@ getHtml = \duration, successCount, errorCount, resultsContent ->
215266
}
216267
217268
.test-details {
218-
219-
220269
max-height: 0;
221-
222270
overflow: hidden;
223271
transition: max-height 0.3s ease;
224272
}
@@ -276,15 +324,15 @@ getHtml = \duration, successCount, errorCount, resultsContent ->
276324
<script>
277325
document.querySelectorAll('.test-header').forEach(listItem => {
278326
listItem.addEventListener('click', () => {
279-
const accordionContent = listItem.nextElementSibling;
327+
const accordionContent = listItem.nextElementSibling;
280328

281-
listItem.classList.toggle('active');
329+
listItem.classList.toggle('active');
282330

283-
if (listItem.classList.contains('active')) {
284-
accordionContent.style.maxHeight = accordionContent.scrollHeight + 'px';
285-
} else {
286-
accordionContent.style.maxHeight = 0;
287-
}
331+
if (listItem.classList.contains('active')) {
332+
accordionContent.style.maxHeight = accordionContent.scrollHeight + 'px';
333+
} else {
334+
accordionContent.style.maxHeight = 0;
335+
}
288336
});
289337
});
290338

0 commit comments

Comments
 (0)