<commit_before>var test = require('tape')
var tapSpec = require('tap-spec')
function noop (err) { if (err) throw err }

test.createStream()
  .pipe(tapSpec())
  .pipe(process.stdout)

var fs = require('fs')
var path = require('path')
var pdf = require('../')
var html = fs.readFileSync(path.join(__dirname, 'example.html'), 'utf8')

//
// API
//
test('pdf.create(html[, options]) throws an error when executing without html', function (t) {
  t.plan(3)

  t.throws(function () { pdf.create(null) }, 'pdf.create(null)')
  t.throws(function () { pdf.create(undefined) }, 'pdf.create(undefined)')
  t.throws(function () { pdf.create('') }, 'pdf.create("")')
})

test('pdf.create(html[, options], callback) returns error as first cb argument when executing without html', function (t) {
  t.plan(3)

  pdf.create(null, function (error) {
    t.assert(error instanceof Error, 'pdf.create(null, cb)')
  })

  pdf.create(undefined, function (error) {
    t.assert(error instanceof Error, 'pdf.create(undefined, cb)')
  })

  pdf.create('', function (error) {
    t.assert(error instanceof Error, 'pdf.create("", cb)')
  })
})

test('pdf.create(html[, options]).toFile([filename, ]callback)', function (t) {
  t.plan(5)

  pdf.create(html).toFile(function (err, pdf) {
    t.error(err)
    t.assert(typeof pdf.filename === 'string', `toFile(callback) returns {filename: '${pdf.filename}'} as second cb argument`)
    fs.unlink(pdf.filename, noop)
  })

  var file = path.join(__dirname, 'simple.pdf')
  pdf.create(html).toFile(file, function (err, pdf) {
    t.error(err)
    t.assert(pdf.filename === file, `toFile(filename, callback) returns {filename: '${pdf.filename}'} as second cb argument`)
    t.assert(fs.existsSync(file), 'writes the file to the given destination')
  })
})

test('pdf.create(html).toBuffer(callback)', function (t) {
  t.plan(3)

  pdf.create(html).toBuffer(function (err, pdf) {
    t.error(err)
    t.assert(Buffer.isBuffer(pdf), 'toBuffer(callback) returns a buffer instance as second cb argument')
    t.assert(/^\%PDF-1.4/.test(pdf.slice(0, 100).toString()), 'the PDF buffer has a PDF Header')
  })
})

test('pdf.create(html, {directory: "/tmp"}).toBuffer(callback)', function (t) {
  t.plan(2)

  pdf.create(html, {directory: '/tmp'}).toBuffer(function (err, pdf) {
    t.error(err)
    t.assert(Buffer.isBuffer(pdf), 'uses the passed directory as tmp dir')
  })
})

test('pdf.create(html[, options]).toStream(callback)', function (t) {
  t.plan(3)
<commit_msg>Add test to ensure that renderDelay will render after a specific time<commit_after>var test = require('tape')
var tapSpec = require('tap-spec')
function noop (err) { if (err) throw err }

test.createStream()
  .pipe(tapSpec())
  .pipe(process.stdout)

var fs = require('fs')
var path = require('path')
var pdf = require('../')
var html = fs.readFileSync(path.join(__dirname, 'example.html'), 'utf8')

//
// API
//
test('pdf.create(html[, options]) throws an error when executing without html', function (t) {
  t.plan(3)

  t.throws(function () { pdf.create(null) }, 'pdf.create(null)')
  t.throws(function () { pdf.create(undefined) }, 'pdf.create(undefined)')
  t.throws(function () { pdf.create('') }, 'pdf.create("")')
})

test('pdf.create(html[, options], callback) returns error as first cb argument when executing without html', function (t) {
  t.plan(3)

  pdf.create(null, function (error) {
    t.assert(error instanceof Error, 'pdf.create(null, cb)')
  })

  pdf.create(undefined, function (error) {
    t.assert(error instanceof Error, 'pdf.create(undefined, cb)')
  })

  pdf.create('', function (error) {
    t.assert(error instanceof Error, 'pdf.create("", cb)')
  })
})

test('pdf.create(html[, options]).toFile([filename, ]callback)', function (t) {
  t.plan(5)

  pdf.create(html).toFile(function (err, pdf) {
    t.error(err)
    t.assert(typeof pdf.filename === 'string', `toFile(callback) returns {filename: '${pdf.filename}'} as second cb argument`)
    fs.unlink(pdf.filename, noop)
  })

  var file = path.join(__dirname, 'simple.pdf')
  pdf.create(html).toFile(file, function (err, pdf) {
    t.error(err)
    t.assert(pdf.filename === file, `toFile(filename, callback) returns {filename: '${pdf.filename}'} as second cb argument`)
    t.assert(fs.existsSync(file), 'writes the file to the given destination')
  })
})

test('pdf.create(html).toBuffer(callback)', function (t) {
  t.plan(3)

  pdf.create(html).toBuffer(function (err, pdf) {
    t.error(err)
    t.assert(Buffer.isBuffer(pdf), 'toBuffer(callback) returns a buffer instance as second cb argument')
    t.assert(/^\%PDF-1.4/.test(pdf.slice(0, 100).toString()), 'the PDF buffer has a PDF Header')
  })
})

test('pdf.create(html, {directory: "/tmp"}).toBuffer(callback)', function (t) {
  t.plan(2)

  pdf.create(html, {directory: '/tmp'}).toBuffer(function (err, pdf) {
    t.error(err)
    t.assert(Buffer.isBuffer(pdf), 'uses the passed directory as tmp dir')
  })
})

test('pdf.create(html, {renderDelay: 1000}).toBuffer(callback)', function (t) {
  t.plan(2)

  pdf.create(html, {renderDelay: 1000}).toBuffer(function (err, pdf) {
    t.error(err)
    t.assert(Buffer.isBuffer(pdf), 'still returns after renderDelay')
  })
})


test('pdf.create(html[, options]).toStream(callback)', function (t) {
  t.plan(3)

{'fraction_non_alphanumeric': 0.18963887313291738, 'fraction_numerical': 0.006617508035545471, 'mean_word_length': 4.44238683127572, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1247954', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1783, 'n_words': 418}