Skip to content

Commit

Permalink
Extract business card test into separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
marcbachmann committed Oct 14, 2017
1 parent 63ba98f commit 89a41e3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
Binary file modified examples/businesscard/businesscard.pdf
Binary file not shown.
28 changes: 28 additions & 0 deletions examples/businesscard/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var test = require('tape')
var pdf = require('../../')
var path = require('path')
var fs = require('fs')

test('allows custom html and css', function (t) {
t.plan(3)

var template = path.join(__dirname, 'businesscard.html')
var filename = template.replace('.html', '.pdf')
var templateHtml = fs.readFileSync(template, 'utf8')

var image = path.join('file://', __dirname, 'image.png')
templateHtml = templateHtml.replace('{{image}}', image)

var options = {
width: '50mm',
height: '90mm'
}

pdf
.create(templateHtml, options)
.toFile(filename, function (err, pdf) {
t.error(err)
t.assert(pdf.filename, 'Returns the filename')
t.assert(fs.existsSync(pdf.filename), 'Saves the file to the desired destination')
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"html-pdf": "bin/index.js"
},
"scripts": {
"test": "standard && node test/index.js"
"test": "standard && tape test/index.js examples/*/test.js"
},
"author": "Marc Bachmann",
"license": "MIT",
Expand Down
27 changes: 0 additions & 27 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,33 +115,6 @@ test('pdf.create(html[, options]).toStream(callback)', function (t) {
})
})

//
// Options
//
test('allows custom html and css', function (t) {
t.plan(3)

var template = path.join(__dirname, '../examples/businesscard/businesscard.html')
var filename = template.replace('.html', '.pdf')
var templateHtml = fs.readFileSync(template, 'utf8')

var image = path.join('file://', __dirname, '../examples/businesscard/image.png')
templateHtml = templateHtml.replace('{{image}}', image)

var options = {
width: '50mm',
height: '90mm'
}

pdf
.create(templateHtml, options)
.toFile(filename, function (err, pdf) {
t.error(err)
t.assert(pdf.filename, 'Returns the filename')
t.assert(fs.existsSync(pdf.filename), 'Saves the file to the desired destination')
})
})

test('allows invalid phantomPath', function (t) {
t.plan(3)

Expand Down

0 comments on commit 89a41e3

Please sign in to comment.