VaKeR CYBER ARMY
Logo of a company Server : Apache/2.4.41 (Ubuntu)
System : Linux absol.cf 5.4.0-198-generic #218-Ubuntu SMP Fri Sep 27 20:18:53 UTC 2024 x86_64
User : www-data ( 33)
PHP Version : 7.4.33
Disable Function : 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,
Directory :  /usr/local/lib/node_modules/mqtt/node_modules/callback-stream/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/local/lib/node_modules/mqtt/node_modules/callback-stream/test.js
'use strict'

var test = require('tap').test
var callback = require('./')
var fs = require('fs')

test('call the callback after end with object mode', function (t) {
  var opts = { objectMode: true }
  var stream = callback(opts, function (err, results) {
    t.deepEqual(results, ['hello'], 'should return the ending value')
    t.end()
  })

  stream.end('hello')
})

test('support multiple writes with object mode', function (t) {
  var opts = { objectMode: true }
  var stream = callback(opts, function (err, results) {
    t.deepEqual(results, ['hello', 'world'], 'should return the ending value')
    t.end()
  })

  stream.write('hello')
  stream.end('world')
})

test('works without object mode', function (t) {
  var stream = callback(function (err, results) {
    t.equal(results.length, 1, 'should contain only one value')
    t.deepEqual(results[0].toString(), 'world', 'should return the ending value')
    t.end()
  })

  stream.end('world')
})

test('is pipeable', function (t) {
  var write = callback(function (err, results) {
    var actual = Buffer.concat(results).toString()
    var expected = fs.readFileSync('README.md').toString()
    t.equal(actual, expected, 'should have the same content of the file')
    t.end()
  })
  var read = fs.createReadStream('README.md')

  read.pipe(write)
})

test('callback.obj shortcut for objectMode', function (t) {
  var stream = callback.obj(function (err, results) {
    t.deepEqual(results, ['hello'], 'should return the ending value')
    t.end()
  })

  stream.end('hello')
})

VaKeR 2022