Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve failure message when not in browser #38

Open
TysonMN opened this issue Sep 12, 2021 · 3 comments
Open

Improve failure message when not in browser #38

TysonMN opened this issue Sep 12, 2021 · 3 comments

Comments

@TysonMN
Copy link

TysonMN commented Sep 12, 2021

Consider this code:

Fable.Mocha/src/Mocha.fs

Lines 44 to 54 in 8bcf86d

let inline equal (actual: 'a) (expected: 'a) msg : unit =
if actual = expected || not (Env.isBrowser()) then
Assert.AreEqual(actual, expected, msg)
else
let valueType = actual.GetType()
let primitiveTypes = [ typeof<int>; typeof<bool>; typeof<double>; typeof<string>; typeof<decimal>; typeof<Guid> ]
let errorMsg =
if List.contains valueType primitiveTypes then
sprintf "<span style='color:black'>Expected:</span> <br /><div style='margin-left:20px; color:crimson'>%s</div><br /><span style='color:black'>Actual:</span> </br ><div style='margin-left:20px;color:crimson'>%s</div><br /><span style='color:black'>Message:</span> </br ><div style='margin-left:20px; color:crimson'>%s</div>" (string expected) (string actual) msg
else
sprintf "<span style='color:black'>Expected:</span> <br /><div style='margin-left:20px; color:crimson'>%A</div><br /><span style='color:black'>Actual:</span> </br ><div style='margin-left:20px;color:crimson'>%A</div><br /><span style='color:black'>Message:</span> </br ><div style='margin-left:20px; color:crimson'>%s</div>" expected actual msg

I see a lot of effort being put in there to the browser case. In particular, errorMsg includes Expected: and Actual:. I don't see that same level of information in the error message in the non-browser case.

More specifically, here is the output for some failed test when running npm test on this commit. In particular, line 321 says Error: Should be equal...but what should be equal?

In contrast, here is the corresponding output when running dotnet test. In particular, lines 223 to 225 say

Expecto.AssertException: Should be equal.
expected: 1
  actual: 0

That is much clearer.

Can the error message for the non-browser case be improved to show the expected and actual values?

@Zaid-Ajaj
Copy link
Owner

Hi @TysonMN, I am revisiting this issue and I don't exactly understand the problem (I can't see the logs from the link).

The thing is, running the tests outside of the browser is handled by either mocha (running compiled Fable code in node.js) or by Expecto when running using dotnet so in your case, are you saying that mocha isn't showing the exact error message?

@TysonMN
Copy link
Author

TysonMN commented Feb 4, 2022

Oh, access to those logs requires being signed in and beyond that those logs were deleted according to the retention policy. That is my fault for not copying more details into this issue.

The basic narrative is still here though. When running npm test on that commit, the test fails with the message

Error: Should be equal

but when running dotnet test, the test fails with the message

Expecto.AssertException: Should be equal.
expected: 1
  actual: 0

I think the problem is the lack of information in the error message from mocha. The message should be improved by also showing the expected and actual values like Expeto does when running dotnet test.

Is that clear? Please let me know if there is anything else I can do to help resolve this issue.

@Zaid-Ajaj
Copy link
Owner

@TysonMN I see the problem now, it is probably the call

Assert.AreEqual(actual, expected, msg) 

That is the issue here. I will see what I can do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants