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

Exclude regions from diff #15

Closed
maiers opened this issue Oct 2, 2020 · 7 comments
Closed

Exclude regions from diff #15

maiers opened this issue Oct 2, 2020 · 7 comments
Assignees

Comments

@maiers
Copy link

maiers commented Oct 2, 2020

It would be interesting to be able to exclude specific regions (containing for example the print date) from the diff. Would this be possible any way?

(Anyway it's a nice tool)

@moshensky
Copy link
Owner

Hi @maiers, one of the simplest solutions that I can see is to provide an option to define a rectangle that will always be of some solid color, but is it really needed? I initially created this lib to be able to test that some generated documents from templates don't get accidentally changed. For that reason I am able for my own use cases to use data that is not changing. What is your particular use case?

@maiers
Copy link
Author

maiers commented Oct 20, 2020

We generate a pdf report with the current date in the footer. While we could potentially fix the date for the tests, it would be nice to minimize interfering with the system under test.

@moshensky
Copy link
Owner

So would a solid rectangle defined by x0, y0, x1, y1 coordinates would be of any use to you?
Something like

comparePdfToSnapshot(pathToPdf, __dirname, 'my-awesome-report', {
  maskRegions: [{
    type: 'rectangle',
    x0: 300,
    y0: 200,
    x1: 330,
    y1: 210,
    color: 'black'
  }]
})

Where coordinates will depend on the pdf at hand. Pdfs are converted to images using 300dpi. Some trial and errors might be needed to pinpoint the date.

@maiers
Copy link
Author

maiers commented Oct 20, 2020

I believe this would be a sufficiently flexible solution.

@moshensky
Copy link
Owner

Good. I will add it over the weekend.

@moshensky moshensky mentioned this issue Oct 31, 2020
@moshensky
Copy link
Owner

@maiers, I have released new version with possibility to mask regions. Please check it out.

Options changed a bit to:

export type RectangleMask = Readonly<{
  type: 'rectangle-mask'
  x: number
  y: number
  width: number
  height: number
  color: HighlightColor
}>

example:

    comparePdfToSnapshot(singlePagePdfPath, __dirname, 'rectangle-masks', {
      maskRegions: [
        {
          type: 'rectangle-mask',
          x: 120,
          y: 150,
          width: 280,
          height: 200,
          color: 'Blue',
        },
      ],
    })

Many rectangle regions could be passed in.

@moshensky
Copy link
Owner

Closing. Feel free to reopen.

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