Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Allow lazy `message` #47
Thanks for the addition but this should be implemented in Node.js first. I did think about something like that before as well but just accepting any function would prevent other usages for this variable. I'll soon have a look at it to implement something like this or please feel free to open a PR in Node.js directly.
ljharb left a comment
I don't think this is a great API; the user can already pass
See #47 (comment)
This problem is something that I ran into myself before as well and I think it's a good idea to implement something like this in general. The specific implementation aside.
I thought about adding a new assertion function which may be passed through as lazy message:
const assert = require('assert').strict assert.deepEqual(foo, bar, assert.lazy(() => 'I am a lazy message'))`
That way it's at least expressive for someone else who reads the code and functions won't be special handled in general. What do you think about that solution?
@ljharb we had expensive messages in Node.js before:
We compared some entries of a complex structure and in case of an error we'd inspect the structure to know how it looked like.
That caused some tests to time out at some point due to inspecting multiple megabytes for lots of test cases instead of only inspecting the object in case of an error.
How would your ideal API look like in that case? I tried to outline the limited possibilities right now.