HEX
Server: LiteSpeed
System: Linux houston.panomity.com 6.8.0-100-generic #100-Ubuntu SMP PREEMPT_DYNAMIC Tue Jan 13 16:40:06 UTC 2026 x86_64
User: nudepix (1011)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //opt/coauthor/node_modules/level-concat-iterator/test.js
var test = require('tape')
var collect = require('.')

test('calls back with error if iterator.next errors', function (t) {
  t.plan(3)

  var iterator = {
    next: function (cb) {
      t.pass('iterator.next called')
      process.nextTick(cb, new Error('iterator.next'))
    },
    end: function (cb) {
      t.pass('iterator.end called')
      process.nextTick(cb)
    }
  }

  collect(iterator, function (err) {
    t.is(err.message, 'iterator.next', 'correct error')
  })
})

test('happy path calls back with an array', function (t) {
  t.plan(6)

  var i = 0
  var data = [
    { key: 'key1', value: 'value1' },
    { key: 'key2', value: 'value2' }
  ]

  var iterator = {
    next: function (cb) {
      t.pass('iterator.next called')
      if (i < data.length) {
        process.nextTick(cb, null, data[i].key, data[i].value)
        ++i
      } else {
        process.nextTick(cb)
      }
    },
    end: function (cb) {
      t.pass('iterator.end called')
      process.nextTick(cb)
    }
  }

  collect(iterator, function (err, result) {
    t.error(err, 'no error')
    t.same(result, data)
  })
})

test('calls back with error and data if iterator.end errors', function (t) {
  t.plan(6)

  var i = 0
  var data = [
    { key: 'key1', value: 'value1' },
    { key: 'key2', value: 'value2' }
  ]

  var iterator = {
    next: function (cb) {
      t.pass('iterator.next called')
      if (i < data.length) {
        process.nextTick(cb, null, data[i].key, data[i].value)
        ++i
      } else {
        process.nextTick(cb)
      }
    },
    end: function (cb) {
      t.pass('iterator.end called')
      process.nextTick(cb, new Error('iterator.end'))
    }
  }

  collect(iterator, function (err, result) {
    t.is(err.message, 'iterator.end', 'correct error')
    t.same(result, data)
  })
})

test('calls back with error and partial data if iterator.end errors', function (t) {
  t.plan(5)

  var i = 0
  var data = [
    { key: 'key1', value: 'value1' },
    { key: 'key2', value: 'value2' }
  ]

  var iterator = {
    next: function (cb) {
      t.pass('iterator.next called')
      if (i === 0) {
        process.nextTick(cb, null, data[i].key, data[i].value)
        i++
      } else {
        process.nextTick(cb)
      }
    },
    end: function (cb) {
      t.pass('iterator.end called')
      process.nextTick(cb, new Error('foo'))
    }
  }

  collect(iterator, function (err, result) {
    t.is(err.message, 'foo', 'correct error')
    t.same(result, [].concat(data[0]))
  })
})