zeptometer / jest-pdf-snapshot

Jest matcher for pdf comparison.
MIT License
10 stars 1 forks source link

Use compare-pdf instead of diff-pdf #59

Open thomaschaaf opened 3 years ago

thomaschaaf commented 3 years ago

With compare-pdf with the native option you can get a version that only uses node native functions (pdfjs + canvas) resulting in fewer dependencies for the ci.

zeptometer commented 3 years ago

Wow, that will make set-up much easier. I was not aware of that option, thank you for sharing! I'll keep this issue as todo.

thomaschaaf commented 3 years ago

I didn't update the tests but I started here: https://github.com/zeptometer/jest-pdf-snapshot/compare/master...thomaschaaf:master

zeptometer commented 3 years ago

Got it, thank you for your work. In regards to tests, you don't have to care about integration tests, as it's flaky currently. You can run only unit tests with yarn test --group=unit --color. CI doesn't run integration tests either.

bibekg commented 3 years ago

Hi @thomaschaaf, have you had a chance to work on this since February? I'm trying to use this package now but am blocked because installing diff-pdf on my CI where tests would run is quite an arduous process that would make my builds take several minutes longer. Having compare-pdf as the dep would make things a lot quicker!

bibekg commented 3 years ago

I tried using your version directly

import { toMatchPdfSnapshot } from 'jest-pdf-snapshot-thomaschaaf'

and am getting the following error several times for a single call to expect(pdf).toMatchPdfSnapshot(). It seems to all be coming from pdfjs-dist?

  ●  Cannot log after tests are done. Did you forget to wait for something async in your test?
    Attempted to log "Warning: getPathGenerator - ignoring character: "Error: Requesting object that isn't resolved yet Courier_path_S.".".

      at console (node_modules/@jest/console/build/CustomConsole.js:186:10)
      at warn (node_modules/pdfjs-dist/legacy/build/webpack:/pdfjs-dist/build/pdf/src/shared/util.js:366:5)
      at FontFaceObject.font [as getPathGenerator] (node_modules/pdfjs-dist/legacy/build/webpack:/pdfjs-dist/build/pdf/src/display/font_loader.js:411:7)
      at CanvasGraphics.paintChar (node_modules/pdfjs-dist/legacy/build/webpack:/pdfjs-dist/build/pdf/src/display/canvas.js:1639:21)
      at CanvasGraphics_showText [as showText] (node_modules/pdfjs-dist/legacy/build/webpack:/pdfjs-dist/build/pdf/src/display/canvas.js:1853:13)
      at CanvasGraphics_executeOperatorList [as executeOperatorList] (node_modules/pdfjs-dist/legacy/build/webpack:/pdfjs-dist/build/pdf/src/display/canvas.js:1007:11)
      at InternalRenderTask.fn (node_modules/pdfjs-dist/legacy/build/webpack:/pdfjs-dist/build/pdf/src/display/api.js:3102:30)
      at tryCatch (node_modules/pdfjs-dist/legacy/build/webpack:/pdfjs-dist/build/pdf/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:63:37)
      at Generator.invoke [as _invoke] (node_modules/pdfjs-dist/legacy/build/webpack:/pdfjs-dist/build/pdf/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:293:22)
      at Generator.next (node_modules/pdfjs-dist/legacy/build/webpack:/pdfjs-dist/build/pdf/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:118:16)
thomaschaaf commented 3 years ago

@bibekg

packackes:

"pdfjs": "^2.4.2",
"jest-pdf-snapshot-thomaschaaf": "^0.6.2",
import { toMatchPdfSnapshot } from 'jest-pdf-snapshot-thomaschaaf';

expect.extend({ toMatchPdfSnapshot });
describe('basic-pdf-renderer', () => {
  it('should work with a single array element', async () => {
    const renderer = new BasicPdf();
    const response = await renderer.render();

    // @ts-ignore
    await expect(response.data).toMatchPdfSnapshot();
  }, 15000);
});

this is how I am using it. Sorry if it doesn't work. But from the sound of the log it looks like Courier_path_S is not present in the pdf but used?