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

mini.test: ignore regions in reference_screenshot #512

Closed
2 tasks done
9999years opened this issue Oct 11, 2023 · 3 comments
Closed
2 tasks done

mini.test: ignore regions in reference_screenshot #512

9999years opened this issue Oct 11, 2023 · 3 comments
Labels
feature-request Request for a feature to existing module mini.test

Comments

@9999years
Copy link

Contributing guidelines

Module(s)

mini.test

Description

I'm working on a Neovim plugin to integrate with a command-line tool broot. To verify its behavior, I'd like to use the expect.reference_screenshot function. Unfortunately, broot includes an absolute path as part of its UI, so I get failures like this when running the tests in CI:

Reference:
--|---------|---------|---------|---------|
01|/Users/wiggles/broot.nvim/tests/data    

Observed:
--|---------|---------|---------|---------|
01|/private/tmp/nix-build-broot.nvim-tests.

It would be nice if I could designate 'volatile' regions of the screenshot like this and have them ignored in the reference_screenshot function.

For instance, here I could ignore the first line.

What do you think?

@echasnovski
Copy link
Owner

Thanks for the suggestion!

Indeed, having to deal with different paths in local and CI tests is somewhat of a pain. I tend to mock any related functionality in tests. Like if path comes from vim.fn.getcwd(), I'll add vim.fn.getcwd = function() return 'mock/current-dir' end in related test. Not sure how to go with this approach in case of a CLI app though.

Having ignoreable screenshot regions is an approach I didn't think about. It is interesting, but I am not sure about the proper function API here. Some ideas:

  • ignore_lines with array of lines to ignore. Seems easy enough to implement.
  • ignore_region with a from_line, to_line, from_col, to_col fields. It is relatively easy to implement and document, but only allows ignoring only single contiguous region.
  • ignore_regions with array of previous ones. Seems a bit too complicated.

I'll definitely think about this.

echasnovski added a commit that referenced this issue Oct 17, 2023
`expect.reference_screenshot()`.

Details:
- Resolves #512.
@echasnovski
Copy link
Owner

Thanks again for the suggestion!

This should now be (at least partially) possible with ignore_lines option of expect.reference_screenshot. So something like expect.reference_screenshot(screenshot, path, { ignore_lines = { 2, 3 } }) will compare screenshots but if they don't match on lines 2 or 3 (either in text or highlight attribute), it will still return true.

I figured that only ignoring lines is a reasonable compromise between implementation complexity and covering many use cases.

@9999years
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for a feature to existing module mini.test
Projects
None yet
Development

No branches or pull requests

2 participants