var Bundler = require('../')
var extract = require('tar-stream').extract()
var gunzip = require('gunzip-maybe')
var concat = require('concat-stream')
var path = require('path')
var test = require('tape')
var fs = require('fs')

var fixtures = {
  'text_file/test.txt': {
    source: path.join(__dirname, '/fixtures/test.txt'),
    content: fs.readFileSync(path.join(__dirname, '/fixtures/test.txt'))
  },
  'export.xml': {
    source: path.join(__dirname, '/fixtures/export.xml'),
    content: fs.readFileSync(path.join(__dirname, '/fixtures/export.xml'))
  }
}

test('create bundle', function (assert) {
  var bundle = Bundler()

  bundle.add(fixtures['text_file/test.txt'].source)

  extract.on('entry', function (header, stream, next) {
    if (header.name in fixtures) {
      stream.pipe(concat(function (text) {
        assert.deepEqual(text, fixtures[header.name].content)
        next()
      }))
    } else return next()
  })

  extract.on('finish', function () {
    assert.end()
  })

  bundle.createBundle()
    .pipe(gunzip())
    .pipe(extract)
})

@@ -913,22 +913,15 @@
 lse 
-return 
 next()%0A
+
   %7D)
@@ -1026,16 +1026,16 @@
 nzip())%0A
-
     .pip
@@ -1048,8 +1048,398 @@
 act)%0A%7D)%0A
+%0Atest('configure bundle', function (assert) %7B%0A  var defaults = Bundler()%0A  var linkType = Bundler(%7B globalLinkType: 2 %7D)%0A  var unrestricted = Bundler(%7B globalUnrestricted: true %7D)%0A%0A  assert.equal(defaults.globalLinkType, 1)%0A  assert.equal(defaults.globalUnrestricted, false)%0A  assert.equal(linkType.globalLinkType, 2)%0A  assert.equal(unrestricted.globalUnrestricted, true)%0A  assert.end()%0A%7D)%0A

Add bundle configuration tests