Open jennybc opened 3 months ago
The problem is the line breaks are calculated before the transform
takes effect, so the output potentially still depends on how long the transformed value was.
There isn't much we can do about this, other than set
withr::local_options(cli.width = Inf)
to get rid of the line breaks.
In short, if you use cli and transform
, then better use Inf
width.
In theory expect_snapshot()
could try to detect this situation, but I am not sure if it is worth it. We should definitely document it, though, possibly in the documentation of transform
.
I'm not sure what's going on with
width
vs.cli.width
, but I feel like there's something here.
cli.width
takes precedence, and since testthat sets that (as well) to a fixed width, that's what you need to set as well.
cli.width
takes precedence, and since testthat sets that (as well) to a fixed width, that's what you need to set as well.
AHA! I have not come across that in the docs I've been reading, so either that's user error or something else that should be documented.
I periodically struggle with linebreak differences in snapshot tests and I've seen it come up in Slack a few times. Highlights of the situation:
Snapshot test fails (seemingly) at random, locally, or in CI, for some jobs but not others, because of linebreak differences. The example I'm dealing with today looks like:
local_reproducible_output()
was supposed to design this away".expect_snapshot(transform =)
to replace, e.g. a volatile filepath (as is true above). @gaborcsardi indicates that one factor here is that the wrapping is done before thetransform
function is applied. Now that I think about it, at least in the cli case, I can see why it's this way.In my current example, this also did not work and it seems I had to specify
cli.width
instead of justwidth
.Various ideas that might help:
expect_snapshot(transform =)
is prone to creating linebreak problems and is best used in combination with explicit width setting. Make it wide folks!expect_snapshot()
get smarter aboutwidth
or gain awidth
argument?width
vs.cli.width
, but I feel like there's something here.