foliojs / pdfkit

A JavaScript PDF generation library for Node and the browser
http://pdfkit.org/
MIT License
9.89k stars 1.15k forks source link

Headless PDF testing #522

Open Chris0lsen opened 8 years ago

Chris0lsen commented 8 years ago

I'm writing tests for a chunk of code that spits out a report using PDFKit, and I think it'd be helpful to have an API for asserting that things ended up where you expected them to on the page. Even just getter methods for seeing the values in the pdfkit object - unless these are already present, and I'm just not seeing them (I don't work in coffeescript, so I could very well be overlooking something).

I don't know if anybody else would find value in this, but I can think of a few cases where regression testing could come in handy:

TimPerry commented 8 years ago

How did you get on with this? Would it be viable to use something like phantomjs to render it and then snapshot it? I guess casperjs wouldn't be viable as you don't have a DOM to use for assertions but perhaps there is something to be done is this project or another to resolve that?

Chris0lsen commented 8 years ago

Hi Tim,

I've skipped writing tests for this, for now. The problem got me thinking, though, and I'll bet that, until there is an accessible PDFKit DOM, you could use ResembleJS to compare your test output to a master - but that doesn't lead to very dynamic tests...

tamlyn commented 6 years ago

I think this kind of thing is probably out of scope for this package but it would be helpful to document an approach using other tools.

I'd like to do better than my current test suite which consists of

expect(document.substring(0, 6)).toBe('%PDF-1')