aboutsummaryrefslogtreecommitdiff
path: root/node_modules/readdirp/test
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/readdirp/test
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/readdirp/test')
-rw-r--r--node_modules/readdirp/test/bed/root_dir1/root_dir1_file1.ext10
-rw-r--r--node_modules/readdirp/test/bed/root_dir1/root_dir1_file2.ext20
-rw-r--r--node_modules/readdirp/test/bed/root_dir1/root_dir1_file3.ext30
-rw-r--r--node_modules/readdirp/test/bed/root_dir1/root_dir1_subdir1/root1_dir1_subdir1_file1.ext10
-rw-r--r--node_modules/readdirp/test/bed/root_dir2/root_dir2_file1.ext10
-rw-r--r--node_modules/readdirp/test/bed/root_dir2/root_dir2_file2.ext20
-rw-r--r--node_modules/readdirp/test/bed/root_file1.ext10
-rw-r--r--node_modules/readdirp/test/bed/root_file2.ext20
-rw-r--r--node_modules/readdirp/test/bed/root_file3.ext30
-rw-r--r--node_modules/readdirp/test/readdirp-stream.js338
-rw-r--r--node_modules/readdirp/test/readdirp.js289
11 files changed, 0 insertions, 627 deletions
diff --git a/node_modules/readdirp/test/bed/root_dir1/root_dir1_file1.ext1 b/node_modules/readdirp/test/bed/root_dir1/root_dir1_file1.ext1
deleted file mode 100644
index e69de29bb..000000000
--- a/node_modules/readdirp/test/bed/root_dir1/root_dir1_file1.ext1
+++ /dev/null
diff --git a/node_modules/readdirp/test/bed/root_dir1/root_dir1_file2.ext2 b/node_modules/readdirp/test/bed/root_dir1/root_dir1_file2.ext2
deleted file mode 100644
index e69de29bb..000000000
--- a/node_modules/readdirp/test/bed/root_dir1/root_dir1_file2.ext2
+++ /dev/null
diff --git a/node_modules/readdirp/test/bed/root_dir1/root_dir1_file3.ext3 b/node_modules/readdirp/test/bed/root_dir1/root_dir1_file3.ext3
deleted file mode 100644
index e69de29bb..000000000
--- a/node_modules/readdirp/test/bed/root_dir1/root_dir1_file3.ext3
+++ /dev/null
diff --git a/node_modules/readdirp/test/bed/root_dir1/root_dir1_subdir1/root1_dir1_subdir1_file1.ext1 b/node_modules/readdirp/test/bed/root_dir1/root_dir1_subdir1/root1_dir1_subdir1_file1.ext1
deleted file mode 100644
index e69de29bb..000000000
--- a/node_modules/readdirp/test/bed/root_dir1/root_dir1_subdir1/root1_dir1_subdir1_file1.ext1
+++ /dev/null
diff --git a/node_modules/readdirp/test/bed/root_dir2/root_dir2_file1.ext1 b/node_modules/readdirp/test/bed/root_dir2/root_dir2_file1.ext1
deleted file mode 100644
index e69de29bb..000000000
--- a/node_modules/readdirp/test/bed/root_dir2/root_dir2_file1.ext1
+++ /dev/null
diff --git a/node_modules/readdirp/test/bed/root_dir2/root_dir2_file2.ext2 b/node_modules/readdirp/test/bed/root_dir2/root_dir2_file2.ext2
deleted file mode 100644
index e69de29bb..000000000
--- a/node_modules/readdirp/test/bed/root_dir2/root_dir2_file2.ext2
+++ /dev/null
diff --git a/node_modules/readdirp/test/bed/root_file1.ext1 b/node_modules/readdirp/test/bed/root_file1.ext1
deleted file mode 100644
index e69de29bb..000000000
--- a/node_modules/readdirp/test/bed/root_file1.ext1
+++ /dev/null
diff --git a/node_modules/readdirp/test/bed/root_file2.ext2 b/node_modules/readdirp/test/bed/root_file2.ext2
deleted file mode 100644
index e69de29bb..000000000
--- a/node_modules/readdirp/test/bed/root_file2.ext2
+++ /dev/null
diff --git a/node_modules/readdirp/test/bed/root_file3.ext3 b/node_modules/readdirp/test/bed/root_file3.ext3
deleted file mode 100644
index e69de29bb..000000000
--- a/node_modules/readdirp/test/bed/root_file3.ext3
+++ /dev/null
diff --git a/node_modules/readdirp/test/readdirp-stream.js b/node_modules/readdirp/test/readdirp-stream.js
deleted file mode 100644
index c43d132d3..000000000
--- a/node_modules/readdirp/test/readdirp-stream.js
+++ /dev/null
@@ -1,338 +0,0 @@
-/*jshint asi:true */
-
-var debug //= true;
-var test = debug ? function () {} : require('tap').test
-var test_ = !debug ? function () {} : require('tap').test
- , path = require('path')
- , fs = require('fs')
- , util = require('util')
- , TransformStream = require('readable-stream').Transform
- , through = require('through2')
- , proxyquire = require('proxyquire')
- , streamapi = require('../stream-api')
- , readdirp = require('..')
- , root = path.join(__dirname, 'bed')
- , totalDirs = 6
- , totalFiles = 12
- , ext1Files = 4
- , ext2Files = 3
- , ext3Files = 2
- ;
-
-// see test/readdirp.js for test bed layout
-
-function opts (extend) {
- var o = { root: root };
-
- if (extend) {
- for (var prop in extend) {
- o[prop] = extend[prop];
- }
- }
- return o;
-}
-
-function capture () {
- var result = { entries: [], errors: [], ended: false }
- , dst = new TransformStream({ objectMode: true });
-
- dst._transform = function (entry, _, cb) {
- result.entries.push(entry);
- cb();
- }
-
- dst._flush = function (cb) {
- result.ended = true;
- this.push(result);
- cb();
- }
-
- return dst;
-}
-
-test('\nintegrated', function (t) {
- t.test('\n# reading root without filter', function (t) {
- t.plan(2);
-
- readdirp(opts())
- .on('error', function (err) {
- t.fail('should not throw error', err);
- })
- .pipe(capture())
- .pipe(through.obj(
- function (result, _ , cb) {
- t.equals(result.entries.length, totalFiles, 'emits all files');
- t.ok(result.ended, 'ends stream');
- t.end();
- cb();
- }
- ));
- })
-
- t.test('\n# normal: ["*.ext1", "*.ext3"]', function (t) {
- t.plan(2);
-
- readdirp(opts( { fileFilter: [ '*.ext1', '*.ext3' ] } ))
- .on('error', function (err) {
- t.fail('should not throw error', err);
- })
- .pipe(capture())
- .pipe(through.obj(
- function (result, _ , cb) {
- t.equals(result.entries.length, ext1Files + ext3Files, 'all ext1 and ext3 files');
- t.ok(result.ended, 'ends stream');
- t.end();
- cb();
- }
- ))
- })
-
- t.test('\n# files only', function (t) {
- t.plan(2);
-
- readdirp(opts( { entryType: 'files' } ))
- .on('error', function (err) {
- t.fail('should not throw error', err);
- })
- .pipe(capture())
- .pipe(through.obj(
- function (result, _ , cb) {
- t.equals(result.entries.length, totalFiles, 'returned files');
- t.ok(result.ended, 'ends stream');
- t.end();
- cb();
- }
- ))
- })
-
- t.test('\n# directories only', function (t) {
- t.plan(2);
-
- readdirp(opts( { entryType: 'directories' } ))
- .on('error', function (err) {
- t.fail('should not throw error', err);
- })
- .pipe(capture())
- .pipe(through.obj(
- function (result, _ , cb) {
- t.equals(result.entries.length, totalDirs, 'returned directories');
- t.ok(result.ended, 'ends stream');
- t.end();
- cb();
- }
- ))
- })
-
- t.test('\n# both directories + files', function (t) {
- t.plan(2);
-
- readdirp(opts( { entryType: 'both' } ))
- .on('error', function (err) {
- t.fail('should not throw error', err);
- })
- .pipe(capture())
- .pipe(through.obj(
- function (result, _ , cb) {
- t.equals(result.entries.length, totalDirs + totalFiles, 'returned everything');
- t.ok(result.ended, 'ends stream');
- t.end();
- cb();
- }
- ))
- })
-
- t.test('\n# directory filter with directories only', function (t) {
- t.plan(2);
-
- readdirp(opts( { entryType: 'directories', directoryFilter: [ 'root_dir1', '*dir1_subdir1' ] } ))
- .on('error', function (err) {
- t.fail('should not throw error', err);
- })
- .pipe(capture())
- .pipe(through.obj(
- function (result, _ , cb) {
- t.equals(result.entries.length, 2, 'two directories');
- t.ok(result.ended, 'ends stream');
- t.end();
- cb();
- }
- ))
- })
-
- t.test('\n# directory and file filters with both entries', function (t) {
- t.plan(2);
-
- readdirp(opts( { entryType: 'both', directoryFilter: [ 'root_dir1', '*dir1_subdir1' ], fileFilter: [ '!*.ext1' ] } ))
- .on('error', function (err) {
- t.fail('should not throw error', err);
- })
- .pipe(capture())
- .pipe(through.obj(
- function (result, _ , cb) {
- t.equals(result.entries.length, 6, '2 directories and 4 files');
- t.ok(result.ended, 'ends stream');
- t.end();
- cb();
- }
- ))
- })
-
- t.test('\n# negated: ["!*.ext1", "!*.ext3"]', function (t) {
- t.plan(2);
-
- readdirp(opts( { fileFilter: [ '!*.ext1', '!*.ext3' ] } ))
- .on('error', function (err) {
- t.fail('should not throw error', err);
- })
- .pipe(capture())
- .pipe(through.obj(
- function (result, _ , cb) {
- t.equals(result.entries.length, totalFiles - ext1Files - ext3Files, 'all but ext1 and ext3 files');
- t.ok(result.ended, 'ends stream');
- t.end();
- }
- ))
- })
-
- t.test('\n# no options given', function (t) {
- t.plan(1);
- readdirp()
- .on('error', function (err) {
- t.similar(err.toString() , /Need to pass at least one argument/ , 'emits meaningful error');
- t.end();
- })
- })
-
- t.test('\n# mixed: ["*.ext1", "!*.ext3"]', function (t) {
- t.plan(1);
-
- readdirp(opts( { fileFilter: [ '*.ext1', '!*.ext3' ] } ))
- .on('error', function (err) {
- t.similar(err.toString() , /Cannot mix negated with non negated glob filters/ , 'emits meaningful error');
- t.end();
- })
- })
-})
-
-
-test('\napi separately', function (t) {
-
- t.test('\n# handleError', function (t) {
- t.plan(1);
-
- var api = streamapi()
- , warning = new Error('some file caused problems');
-
- api.stream
- .on('warn', function (err) {
- t.equals(err, warning, 'warns with the handled error');
- })
- api.handleError(warning);
- })
-
- t.test('\n# when stream is paused and then resumed', function (t) {
- t.plan(6);
- var api = streamapi()
- , resumed = false
- , fatalError = new Error('fatal!')
- , nonfatalError = new Error('nonfatal!')
- , processedData = 'some data'
- ;
-
- api.stream
- .on('warn', function (err) {
- t.equals(err, nonfatalError, 'emits the buffered warning');
- t.ok(resumed, 'emits warning only after it was resumed');
- })
- .on('error', function (err) {
- t.equals(err, fatalError, 'emits the buffered fatal error');
- t.ok(resumed, 'emits errors only after it was resumed');
- })
- .on('data', function (data) {
- t.equals(data, processedData, 'emits the buffered data');
- t.ok(resumed, 'emits data only after it was resumed');
- })
- .pause()
-
- api.processEntry(processedData);
- api.handleError(nonfatalError);
- api.handleFatalError(fatalError);
-
- setTimeout(function () {
- resumed = true;
- api.stream.resume();
- }, 1)
- })
-
- t.test('\n# when a stream is paused it stops walking the fs', function (t) {
- var resumed = false,
- mockedAPI = streamapi();
-
- mockedAPI.processEntry = function (entry) {
- if (!resumed) t.notOk(true, 'should not emit while paused')
- t.ok(entry, 'emitted while resumed')
- }.bind(mockedAPI.stream)
-
- function wrapper () {
- return mockedAPI
- }
-
- var readdirp = proxyquire('../readdirp', {'./stream-api': wrapper})
- , stream = readdirp(opts())
- .on('error', function (err) {
- t.fail('should not throw error', err);
- })
- .on('end', function () {
- t.end()
- })
- .pause();
-
- setTimeout(function () {
- resumed = true;
- stream.resume();
- }, 5)
- })
-
- t.test('\n# when a stream is destroyed, it emits "closed", but no longer emits "data", "warn" and "error"', function (t) {
- var api = streamapi()
- , fatalError = new Error('fatal!')
- , nonfatalError = new Error('nonfatal!')
- , processedData = 'some data'
- , plan = 0;
-
- t.plan(6)
- var stream = api.stream
- .on('warn', function (err) {
- t.ok(!stream._destroyed, 'emits warning until destroyed');
- })
- .on('error', function (err) {
- t.ok(!stream._destroyed, 'emits errors until destroyed');
- })
- .on('data', function (data) {
- t.ok(!stream._destroyed, 'emits data until destroyed');
- })
- .on('close', function () {
- t.ok(stream._destroyed, 'emits close when stream is destroyed');
- })
-
-
- api.processEntry(processedData);
- api.handleError(nonfatalError);
- api.handleFatalError(fatalError);
-
- setTimeout(function () {
- stream.destroy()
-
- t.notOk(stream.readable, 'stream is no longer readable after it is destroyed')
-
- api.processEntry(processedData);
- api.handleError(nonfatalError);
- api.handleFatalError(fatalError);
-
- process.nextTick(function () {
- t.pass('emits no more data, warn or error events after it was destroyed')
- t.end();
- })
- }, 10)
- })
-})
diff --git a/node_modules/readdirp/test/readdirp.js b/node_modules/readdirp/test/readdirp.js
deleted file mode 100644
index 812afbbb9..000000000
--- a/node_modules/readdirp/test/readdirp.js
+++ /dev/null
@@ -1,289 +0,0 @@
-/*jshint asi:true */
-
-var test = require('tap').test
- , path = require('path')
- , fs = require('fs')
- , util = require('util')
- , net = require('net')
- , readdirp = require('../readdirp.js')
- , root = path.join(__dirname, '../test/bed')
- , totalDirs = 6
- , totalFiles = 12
- , ext1Files = 4
- , ext2Files = 3
- , ext3Files = 2
- , rootDir2Files = 2
- , nameHasLength9Dirs = 2
- , depth1Files = 8
- , depth0Files = 3
- ;
-
-/*
-Structure of test bed:
- .
- ├── root_dir1
- │   ├── root_dir1_file1.ext1
- │   ├── root_dir1_file2.ext2
- │   ├── root_dir1_file3.ext3
- │   ├── root_dir1_subdir1
- │   │   └── root1_dir1_subdir1_file1.ext1
- │   └── root_dir1_subdir2
- │   └── .gitignore
- ├── root_dir2
- │   ├── root_dir2_file1.ext1
- │   ├── root_dir2_file2.ext2
- │   ├── root_dir2_subdir1
- │   │   └── .gitignore
- │   └── root_dir2_subdir2
- │   └── .gitignore
- ├── root_file1.ext1
- ├── root_file2.ext2
- └── root_file3.ext3
-
- 6 directories, 13 files
-*/
-
-// console.log('\033[2J'); // clear console
-
-function opts (extend) {
- var o = { root: root };
-
- if (extend) {
- for (var prop in extend) {
- o[prop] = extend[prop];
- }
- }
- return o;
-}
-
-test('\nreading root without filter', function (t) {
- t.plan(2);
- readdirp(opts(), function (err, res) {
- t.equals(res.directories.length, totalDirs, 'all directories');
- t.equals(res.files.length, totalFiles, 'all files');
- t.end();
- })
-})
-
-test('\nreading root without filter using lstat', function (t) {
- t.plan(2);
- readdirp(opts({ lstat: true }), function (err, res) {
- t.equals(res.directories.length, totalDirs, 'all directories');
- t.equals(res.files.length, totalFiles, 'all files');
- t.end();
- })
-})
-
-test('\nreading root with symlinks using lstat', function (t) {
- t.plan(2);
- fs.symlinkSync(path.join(root, 'root_dir1'), path.join(root, 'dirlink'));
- fs.symlinkSync(path.join(root, 'root_file1.ext1'), path.join(root, 'link.ext1'));
- readdirp(opts({ lstat: true }), function (err, res) {
- t.equals(res.directories.length, totalDirs, 'all directories');
- t.equals(res.files.length, totalFiles + 2, 'all files + symlinks');
- fs.unlinkSync(path.join(root, 'dirlink'));
- fs.unlinkSync(path.join(root, 'link.ext1'));
- t.end();
- })
-})
-
-test('\nreading non-standard fds', function (t) {
- t.plan(2);
- var server = net.createServer().listen(path.join(root, 'test.sock'), function(){
- readdirp(opts({ entryType: 'all' }), function (err, res) {
- t.equals(res.files.length, totalFiles + 1, 'all files + socket');
- readdirp(opts({ entryType: 'both' }), function (err, res) {
- t.equals(res.files.length, totalFiles, 'all regular files only');
- server.close();
- t.end();
- })
- })
- });
-})
-
-test('\nreading root using glob filter', function (t) {
- // normal
- t.test('\n# "*.ext1"', function (t) {
- t.plan(1);
- readdirp(opts( { fileFilter: '*.ext1' } ), function (err, res) {
- t.equals(res.files.length, ext1Files, 'all ext1 files');
- t.end();
- })
- })
- t.test('\n# ["*.ext1", "*.ext3"]', function (t) {
- t.plan(1);
- readdirp(opts( { fileFilter: [ '*.ext1', '*.ext3' ] } ), function (err, res) {
- t.equals(res.files.length, ext1Files + ext3Files, 'all ext1 and ext3 files');
- t.end();
- })
- })
- t.test('\n# "root_dir1"', function (t) {
- t.plan(1);
- readdirp(opts( { directoryFilter: 'root_dir1' }), function (err, res) {
- t.equals(res.directories.length, 1, 'one directory');
- t.end();
- })
- })
- t.test('\n# ["root_dir1", "*dir1_subdir1"]', function (t) {
- t.plan(1);
- readdirp(opts( { directoryFilter: [ 'root_dir1', '*dir1_subdir1' ]}), function (err, res) {
- t.equals(res.directories.length, 2, 'two directories');
- t.end();
- })
- })
-
- t.test('\n# negated: "!*.ext1"', function (t) {
- t.plan(1);
- readdirp(opts( { fileFilter: '!*.ext1' } ), function (err, res) {
- t.equals(res.files.length, totalFiles - ext1Files, 'all but ext1 files');
- t.end();
- })
- })
- t.test('\n# negated: ["!*.ext1", "!*.ext3"]', function (t) {
- t.plan(1);
- readdirp(opts( { fileFilter: [ '!*.ext1', '!*.ext3' ] } ), function (err, res) {
- t.equals(res.files.length, totalFiles - ext1Files - ext3Files, 'all but ext1 and ext3 files');
- t.end();
- })
- })
-
- t.test('\n# mixed: ["*.ext1", "!*.ext3"]', function (t) {
- t.plan(1);
- readdirp(opts( { fileFilter: [ '*.ext1', '!*.ext3' ] } ), function (err, res) {
- t.similar(err[0].toString(), /Cannot mix negated with non negated glob filters/, 'returns meaningfull error');
- t.end();
- })
- })
-
- t.test('\n# leading and trailing spaces: [" *.ext1", "*.ext3 "]', function (t) {
- t.plan(1);
- readdirp(opts( { fileFilter: [ ' *.ext1', '*.ext3 ' ] } ), function (err, res) {
- t.equals(res.files.length, ext1Files + ext3Files, 'all ext1 and ext3 files');
- t.end();
- })
- })
- t.test('\n# leading and trailing spaces: [" !*.ext1", " !*.ext3 "]', function (t) {
- t.plan(1);
- readdirp(opts( { fileFilter: [ ' !*.ext1', ' !*.ext3' ] } ), function (err, res) {
- t.equals(res.files.length, totalFiles - ext1Files - ext3Files, 'all but ext1 and ext3 files');
- t.end();
- })
- })
-
- t.test('\n# ** glob pattern', function (t) {
- t.plan(1);
- readdirp(opts( { fileFilter: '**/*.ext1' } ), function (err, res) {
- t.equals(res.files.length, ext1Files, 'ignores ** in **/*.ext1 -> only *.ext1 files');
- t.end();
- })
- })
-})
-
-test('\n\nreading root using function filter', function (t) {
- t.test('\n# file filter -> "contains root_dir2"', function (t) {
- t.plan(1);
- readdirp(
- opts( { fileFilter: function (fi) { return fi.name.indexOf('root_dir2') >= 0; } })
- , function (err, res) {
- t.equals(res.files.length, rootDir2Files, 'all rootDir2Files');
- t.end();
- }
- )
- })
-
- t.test('\n# directory filter -> "name has length 9"', function (t) {
- t.plan(1);
- readdirp(
- opts( { directoryFilter: function (di) { return di.name.length === 9; } })
- , function (err, res) {
- t.equals(res.directories.length, nameHasLength9Dirs, 'all all dirs with name length 9');
- t.end();
- }
- )
- })
-})
-
-test('\nreading root specifying maximum depth', function (t) {
- t.test('\n# depth 1', function (t) {
- t.plan(1);
- readdirp(opts( { depth: 1 } ), function (err, res) {
- t.equals(res.files.length, depth1Files, 'does not return files at depth 2');
- })
- })
-})
-
-test('\nreading root with no recursion', function (t) {
- t.test('\n# depth 0', function (t) {
- t.plan(1);
- readdirp(opts( { depth: 0 } ), function (err, res) {
- t.equals(res.files.length, depth0Files, 'does not return files at depth 0');
- })
- })
-})
-
-test('\nprogress callbacks', function (t) {
- t.plan(2);
-
- var pluckName = function(fi) { return fi.name; }
- , processedFiles = [];
-
- readdirp(
- opts()
- , function(fi) {
- processedFiles.push(fi);
- }
- , function (err, res) {
- t.equals(processedFiles.length, res.files.length, 'calls back for each file processed');
- t.deepEquals(processedFiles.map(pluckName).sort(),res.files.map(pluckName).sort(), 'same file names');
- t.end();
- }
- )
-})
-
-test('resolving of name, full and relative paths', function (t) {
- var expected = {
- name : 'root_dir1_file1.ext1'
- , parentDirName : 'root_dir1'
- , path : 'root_dir1/root_dir1_file1.ext1'
- , fullPath : 'test/bed/root_dir1/root_dir1_file1.ext1'
- }
- , opts = [
- { root: './bed' , prefix: '' }
- , { root: './bed/' , prefix: '' }
- , { root: 'bed' , prefix: '' }
- , { root: 'bed/' , prefix: '' }
- , { root: '../test/bed/' , prefix: '' }
- , { root: '.' , prefix: 'bed' }
- ]
- t.plan(opts.length);
-
- opts.forEach(function (op) {
- op.fileFilter = 'root_dir1_file1.ext1';
-
- t.test('\n' + util.inspect(op), function (t) {
- t.plan(4);
-
- readdirp (op, function(err, res) {
- t.equals(res.files[0].name, expected.name, 'correct name');
- t.equals(res.files[0].path, path.join(op.prefix, expected.path), 'correct path');
- })
-
- fs.realpath(op.root, function(err, fullRoot) {
- readdirp (op, function(err, res) {
- t.equals(
- res.files[0].fullParentDir
- , path.join(fullRoot, op.prefix, expected.parentDirName)
- , 'correct parentDir'
- );
- t.equals(
- res.files[0].fullPath
- , path.join(fullRoot, op.prefix, expected.parentDirName, expected.name)
- , 'correct fullPath'
- );
- })
- })
- })
- })
-})
-
-