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/fileset/tests/test.js
var EventEmitter = require('events').EventEmitter;
var fileset      = require('../');
var assert       = require('assert');
var test         = require('./helper');

// Given a **.md pattern
test('Given a **.md pattern', function() {

  return {
    'should return the list of matching file in this repo': function(em) {
      fileset('*.md', function(err, results) {
        if(err) return em.emit('error', err);
        assert.ok(Array.isArray(results), 'should be an array');
        assert.ok(results.length, 'should return at least one element');
        assert.equal(results.length, 2, 'actually, should return only two');
        em.emit('end');
      });
    }
  }
});

test('Say we want the **.js files, but not those in node_modules', function() {

  return {
    'Should recursively walk the dir and return the matching list': function(em) {
      fileset('**/*.js', 'node_modules/**', function(err, results) {
        if(err) return em.emit('error', err);
        assert.ok(Array.isArray(results), 'should be an array');
        assert.equal(results.length, 5);
        em.emit('end');
      });
    },

    'Should support multiple paths at once': function(em) {
      fileset('**/*.js *.md', 'node_modules/**', function(err, results) {
        if(err) return em.emit('error', err);
        assert.ok(Array.isArray(results), 'should be an array');
        assert.equal(results.length, 7);

        assert.deepEqual(results, [
          'CHANGELOG.md',
          'README.md',
          'lib/fileset.js',
          'tests/fixtures/an (odd) filename.js',
          'tests/helper.js',
          'tests/test-sync.js',
          'tests/test.js'
        ]);

        em.emit('end');
      });
    },

    'Should support multiple paths for excludes as well': function(em) {
      fileset('**/*.js *.md', 'node_modules/** **.md tests/*.js', function(err, results) {
        if(err) return em.emit('error', err);
        assert.ok(Array.isArray(results), 'should be an array');
        assert.equal(results.length, 2);

        assert.deepEqual(results, [
          'lib/fileset.js',
          'tests/fixtures/an (odd) filename.js',
        ]);

        em.emit('end');
      });
    }
  }
});


test('Testing out emmited events', function() {

  // todos: the tests for match, include, exclude events, but seems like it's ok
  return {
    'Should recursively walk the dir and return the matching list': function(em) {
      fileset('**/*.js', 'node_modules/**')
        .on('error', em.emit.bind(em, 'error'))
        .on('end', function(results) {
          assert.ok(Array.isArray(results), 'should be an array');
          assert.equal(results.length, 5);
          em.emit('end');
        });
    },

    'Should support multiple paths at once': function(em) {
      fileset('**/*.js *.md', 'node_modules/**')
        .on('error', em.emit.bind(em, 'error'))
        .on('end', function(results) {
          assert.ok(Array.isArray(results), 'should be an array');
          assert.equal(results.length, 7);

          assert.deepEqual(results, [
            'CHANGELOG.md',
            'README.md',
            'lib/fileset.js',
            'tests/fixtures/an (odd) filename.js',
            'tests/helper.js',
            'tests/test-sync.js',
            'tests/test.js'
          ]);

          em.emit('end');
        });
    }
  }
});


test('Testing patterns passed as arrays', function() {

  return {
    'Should match files passed as an array with odd filenames': function(em) {
      fileset(['lib/*.js', 'tests/fixtures/an (odd) filename.js'], ['node_modules/**'])
        .on('error', em.emit.bind(em, 'error'))
        .on('end', function(results) {
          assert.ok(Array.isArray(results), 'should be an array');
          assert.equal(results.length, 2);

          assert.deepEqual(results, [
            'lib/fileset.js',
            'tests/fixtures/an (odd) filename.js',
          ]);

          em.emit('end');
        });
    }
  }

});



test.run();