dimanche 13 octobre 2019

How to setup a test to confirm the output PDF is correct?

tldr; Looking for a way to check if merged output PDF matched expected PDF from PDFTK.

I wrote a small command-line app called pdfm for my wife :D The app is a wrapper around PDFTK. The app works fine but I'm trying to set up a simple test to ensure the output is as expected. The app takes two inputs --files and --output. --files is a text file with a list of files to be merged in the order listed. I wrote a test with three known input pdf's. The test calls the app and merges the three input pdfs as expected. I tried using md5 and Buffer.equals, neither of which work.

Here is the code for the test I made.

const fs = require('fs-extra')
const {spawn, exec} = require('child_process')
const path = require('path')
const moment = require("moment")
const dateFormat = 'YYYY.MM.DD'

let command = `node src/index.js --output ./test/test --files ./test/testfiles.pdfm`
let outfile = path.resolve(`./test/test-${moment().format(dateFormat)}.pdf`)
let expected = path.resolve(`./test/expected.pdf`)
exec(command, async (error, stdout, stderr) => {
        if (error) {
            console.error(error)
        } else {
            let file = fs.readFileSync(outfile)
            let expectedFile = fs.readFileSync(expected)
            // todo
            // md5()
            console.log(stdout)
            console.log(md5(file))
            console.log(expectedFile.equals(file))
        }
    }
)

Repo: https://github.com/MichaelLeeHobbs/pdfMerger

Aucun commentaire:

Enregistrer un commentaire