HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux wordpress-ubuntu-s-2vcpu-4gb-fra1-01 5.4.0-169-generic #187-Ubuntu SMP Thu Nov 23 14:52:28 UTC 2023 x86_64
User: root (0)
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: /var/www/zaklada/html/node_modules/fs-promise/test/basic.js
'use strict';
/*globals describe, it, beforeEach, afterEach */
var fsp = require('..'),
    path = require('path'),
    assert = require('assert'),
    Prom = require('any-promise'),
    testdir = path.join(__dirname, 'tmp'),
    testdir2 = path.join(__dirname, 'tmp2')


describe('basic', function(){
  beforeEach(function(){
    return fsp.mkdir(testdir).then(existstmp(true));
  });

  afterEach(function(){
    return fsp.remove(testdir).then(existstmp(false));
  });

  it('should create files and readdir', function(){
    return fsp.ensureFile(file('hello')).then(readtmp).then(function(files){
      assert.deepEqual(files.sort(), ['hello']);
      return fsp.ensureFile(file('world'));
    }).then(readtmp).then(function(files){
      assert.deepEqual(files.sort(), ['hello', 'world']);
      return fsp.exists(testdir2)
    }).then(function(exists){
      assert.equal(exists, false);
      return fsp.move(testdir, testdir2)
    }).then(function(){
      return Prom.all([fsp.exists(testdir), fsp.exists(testdir2)])
    }).then(function(exists){
      return assert.deepEqual(exists, [false, true])
    }).then(function(){
      return fsp.copy(testdir2, testdir)
    }).then(function(){
      return Prom.all([fsp.exists(testdir), fsp.exists(testdir2)])
    }).then(function(exists){
      return assert.deepEqual(exists, [true, true])
    }).then(readtmps).then(function(files){
      assert.deepEqual(files[0].sort(), files[1].sort());
      return fsp.emptyDir(testdir2);
    }).then(readtmp2).then(function(files){
      assert.deepEqual(files, []);
    }).then(function(){
      fsp.remove(testdir2);
    })
  });

  it('should pass through Sync as value', function(){
    return fsp.ensureFile(file('hello')).then(function(files){
      assert(fsp.existsSync(file('hello')));
      assert(!fsp.existsSync(file('world')));
      return fsp.ensureFile(file('world'));
    }).then(readtmp).then(function(files){
      assert(fsp.existsSync(file('hello')));
      assert(fsp.existsSync(file('world')));
    });
  });

  it('should copy with pipe read/write stream', function(){
    return fsp.writeFile(file('hello1'), 'hello world').then(function(){
      return fsp.readFile(file('hello1'), {encoding:'utf8'});
    }).then(function(contents){
      assert.equal(contents, 'hello world');
      var read = fsp.createReadStream(file('hello1')),
          write = fsp.createWriteStream(file('hello2')),
          promise = new Prom(function(resolve, reject){
            read.on('end', resolve);
            write.on('error', reject);
            read.on('error', reject);
          });
      read.pipe(write);
      return promise;
    }).then(function(){
      return fsp.readFile(file('hello2'), {encoding:'utf8'});
    }).then(function(contents){
      assert.equal(contents, 'hello world');
    });
  });

  it('should pass third argument from write #7', function testWriteFsp() {
    return fsp.open(file('some.txt'), 'w+').then(function (fd){
      return fsp.write(fd, "hello fs-promise").then(function(result) {
        var written = result[0];
        var text = result[1];
        assert.equal(text.substring(0, written), "hello fs-promise".substring(0, written))
        return fsp.close(fd);
      })
    })
  });

});

function file(){
  var args = [].slice.call(arguments);
  args.unshift(testdir);
  return path.join.apply(path, args);
}

function existstmp(shouldExist){
  return function(){
    return fsp.exists(testdir).then(function(exists){
        assert.equal(exists, shouldExist);
      });
  };
}

function readtmp(){
  return fsp.readdir(testdir);
}

function readtmp2(){
  return fsp.readdir(testdir2);
}

function readtmps(){
  return Prom.all([readtmp(), readtmp2()]);
}