error-on-broken.js 768 B

123456789101112131415161718192021222324252627282930313233
  1. var fs = require('fs')
  2. var path = require('path')
  3. var zlib = require('zlib')
  4. var tap = require('tap')
  5. var tar = require('../tar.js')
  6. var file = path.join(__dirname, 'cb-never-called-1.0.1.tgz')
  7. var target = path.join(__dirname, 'tmp/extract-test')
  8. tap.test('preclean', function (t) {
  9. require('rimraf').sync(__dirname + '/tmp/extract-test')
  10. t.pass('cleaned!')
  11. t.end()
  12. })
  13. tap.test('extract test', function (t) {
  14. var extract = tar.Extract(target)
  15. var inp = fs.createReadStream(file)
  16. inp.pipe(zlib.createGunzip()).pipe(extract)
  17. extract.on('error', function (er) {
  18. t.equal(er.message, 'unexpected eof', 'error noticed')
  19. t.end()
  20. })
  21. extract.on('end', function () {
  22. t.fail('shouldn\'t reach this point due to errors')
  23. t.end()
  24. })
  25. })