From 74767c6c13665f422a14ecacdef4ab1030bc32b0 Mon Sep 17 00:00:00 2001 From: James Messinger Date: Thu, 13 Dec 2018 05:40:59 -0600 Subject: [PATCH] ESLint auto-fixes (replaced single quotes with double quotes) --- .editorconfig | 3 +- lib/async/for-each.js | 2 +- lib/async/index.js | 18 +- lib/call.js | 2 +- lib/directory-reader.js | 46 +-- lib/index.js | 8 +- lib/normalize-options.js | 50 +-- lib/stat.js | 4 +- lib/stream/index.js | 8 +- lib/sync/for-each.js | 2 +- lib/sync/fs.js | 6 +- lib/sync/index.js | 8 +- test/fixtures/dir.js | 626 +++++++++++++++++----------------- test/fixtures/for-each-api.js | 44 +-- test/fixtures/init.js | 42 +-- test/specs/basePath.spec.js | 46 +-- test/specs/deep.spec.js | 102 +++--- test/specs/default.spec.js | 46 +-- test/specs/errors.spec.js | 84 ++--- test/specs/exports.spec.js | 102 +++--- test/specs/filter.spec.js | 94 ++--- test/specs/fs.spec.js | 152 ++++----- test/specs/sep.spec.js | 70 ++-- test/specs/stat.spec.js | 56 +-- test/specs/stream.spec.js | 92 ++--- 25 files changed, 857 insertions(+), 856 deletions(-) diff --git a/.editorconfig b/.editorconfig index 4c79a34..b4a75c5 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,6 +11,7 @@ root = true charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true +end_of_line = lf # 2 space indentation indent_style = space @@ -18,7 +19,7 @@ indent_size = 2 # JavaScript-specific settings [*.js] -quote_type = single +quote_type = double continuation_indent_size = 2 curly_bracket_next_line = false indent_brace_style = BSD diff --git a/lib/async/for-each.js b/lib/async/for-each.js index 1ac9b2f..480ca13 100644 --- a/lib/async/for-each.js +++ b/lib/async/for-each.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; module.exports = asyncForEach; diff --git a/lib/async/index.js b/lib/async/index.js index b62c2e6..6bcf2fa 100644 --- a/lib/async/index.js +++ b/lib/async/index.js @@ -1,13 +1,13 @@ -'use strict'; +"use strict"; module.exports = readdirAsync; -const maybe = require('call-me-maybe'); -const DirectoryReader = require('../directory-reader'); +const maybe = require("call-me-maybe"); +const DirectoryReader = require("../directory-reader"); let asyncFacade = { - fs: require('fs'), - forEach: require('./for-each'), + fs: require("fs"), + forEach: require("./for-each"), }; /** @@ -20,7 +20,7 @@ let asyncFacade = { * @param {object} internalOptions */ function readdirAsync (dir, options, callback, internalOptions) { - if (typeof options === 'function') { + if (typeof options === "function") { callback = options; options = undefined; } @@ -33,14 +33,14 @@ function readdirAsync (dir, options, callback, internalOptions) { let reader = new DirectoryReader(dir, options, internalOptions); let stream = reader.stream; - stream.on('error', err => { + stream.on("error", err => { reject(err); stream.pause(); }); - stream.on('data', result => { + stream.on("data", result => { results.push(result); }); - stream.on('end', () => { + stream.on("end", () => { resolve(results); }); }))); diff --git a/lib/call.js b/lib/call.js index 07e3d84..08ab1ed 100644 --- a/lib/call.js +++ b/lib/call.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; let call = module.exports = { safe: safeCall, diff --git a/lib/directory-reader.js b/lib/directory-reader.js index 37b19d5..d1a51bd 100644 --- a/lib/directory-reader.js +++ b/lib/directory-reader.js @@ -1,11 +1,11 @@ -'use strict'; +"use strict"; -const Readable = require('stream').Readable; -const EventEmitter = require('events').EventEmitter; -const path = require('path'); -const normalizeOptions = require('./normalize-options'); -const stat = require('./stat'); -const call = require('./call'); +const Readable = require("stream").Readable; +const EventEmitter = require("events").EventEmitter; +const path = require("path"); +const normalizeOptions = require("./normalize-options"); +const stat = require("./stat"); +const call = require("./call"); /** * Asynchronously reads the contents of a directory and streams the results @@ -71,7 +71,7 @@ class DirectoryReader { call.safe(facade.fs.readdir, dir.path, (err, items) => { if (err) { // fs.readdir threw an error - this.emit('error', err); + this.emit("error", err); return this.finishedReadingDirectory(); } @@ -86,7 +86,7 @@ class DirectoryReader { catch (err2) { // facade.forEach threw an error // (probably because fs.readdir returned an invalid result) - this.emit('error', err2); + this.emit("error", err2); this.finishedReadingDirectory(); } }); @@ -155,9 +155,9 @@ class DirectoryReader { options.stats || // the user wants fs.Stats objects returned options.recurseFn || // we need fs.Stats for the recurse function options.filterFn || // we need fs.Stats for the filter function - EventEmitter.listenerCount(stream, 'file') || // we need the fs.Stats to know if it's a file - EventEmitter.listenerCount(stream, 'directory') || // we need the fs.Stats to know if it's a directory - EventEmitter.listenerCount(stream, 'symlink'); // we need the fs.Stats to know if it's a symlink + EventEmitter.listenerCount(stream, "file") || // we need the fs.Stats to know if it's a file + EventEmitter.listenerCount(stream, "directory") || // we need the fs.Stats to know if it's a directory + EventEmitter.listenerCount(stream, "symlink"); // we need the fs.Stats to know if it's a symlink // If we don't need stats, then exit early if (!needStats) { @@ -171,7 +171,7 @@ class DirectoryReader { stat(options.facade.fs, fullPath, (err, stats) => { if (err) { // fs.stat threw an error - this.emit('error', err); + this.emit("error", err); return done(); } @@ -189,7 +189,7 @@ class DirectoryReader { this.queue.push({ path: fullPath, basePath: itemPath + options.sep, - posixBasePath: posixPath + '/', + posixBasePath: posixPath + "/", depth: dir.depth + 1, }); } @@ -209,7 +209,7 @@ class DirectoryReader { catch (err2) { // An error occurred while processing the item // (probably during a user-specified function, such as options.deep, options.filter, etc.) - this.emit('error', err2); + this.emit("error", err2); done(); } }); @@ -247,13 +247,13 @@ class DirectoryReader { this.shouldRead = stream.push(chunk.data); } catch (err) { - this.emit('error', err); + this.emit("error", err); } // Also emit specific events, based on the type of chunk - chunk.file && this.emit('file', chunk.data); - chunk.symlink && this.emit('symlink', chunk.data); - chunk.directory && this.emit('directory', chunk.data); + chunk.file && this.emit("file", chunk.data); + chunk.symlink && this.emit("symlink", chunk.data); + chunk.directory && this.emit("directory", chunk.data); } /** @@ -295,7 +295,7 @@ class DirectoryReader { // An error occurred in the user's code. // In Sync and Async modes, this will return an error. // In Streaming mode, we emit an "error" event, but continue processing - this.emit('error', err); + this.emit("error", err); } } else { @@ -335,7 +335,7 @@ class DirectoryReader { // An error occurred in the user's code. // In Sync and Async modes, this will return an error. // In Streaming mode, we emit an "error" event, but continue processing - this.emit('error', err); + this.emit("error", err); } } else { @@ -358,13 +358,13 @@ class DirectoryReader { stream.emit(eventName, data); } catch (err) { - if (eventName === 'error') { + if (eventName === "error") { // Don't recursively emit "error" events. // If the first one fails, then just throw throw err; } else { - stream.emit('error', err); + stream.emit("error", err); } } } diff --git a/lib/index.js b/lib/index.js index f77d2c6..49a69a4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,8 +1,8 @@ -'use strict'; +"use strict"; -const readdirSync = require('./sync'); -const readdirAsync = require('./async'); -const readdirStream = require('./stream'); +const readdirSync = require("./sync"); +const readdirAsync = require("./async"); +const readdirStream = require("./stream"); module.exports = exports = readdirAsyncPath; exports.readdir = exports.readdirAsync = exports.async = readdirAsyncPath; diff --git a/lib/normalize-options.js b/lib/normalize-options.js index 66f1158..f4d4b6d 100644 --- a/lib/normalize-options.js +++ b/lib/normalize-options.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; -const path = require('path'); -const globToRegExp = require('glob-to-regexp'); +const path = require("path"); +const globToRegExp = require("glob-to-regexp"); module.exports = normalizeOptions; @@ -55,29 +55,29 @@ function normalizeOptions (options, internalOptions) { if (options === null || options === undefined) { options = {}; } - else if (typeof options !== 'object') { - throw new TypeError('options must be an object'); + else if (typeof options !== "object") { + throw new TypeError("options must be an object"); } let recurseDepth, recurseFn, recurseRegExp, recurseGlob, deep = options.deep; if (deep === null || deep === undefined) { recurseDepth = 0; } - else if (typeof deep === 'boolean') { + else if (typeof deep === "boolean") { recurseDepth = deep ? Infinity : 0; } - else if (typeof deep === 'number') { + else if (typeof deep === "number") { if (deep < 0 || isNaN(deep)) { - throw new Error('options.deep must be a positive number'); + throw new Error("options.deep must be a positive number"); } else if (Math.floor(deep) !== deep) { - throw new Error('options.deep must be an integer'); + throw new Error("options.deep must be an integer"); } else { recurseDepth = deep; } } - else if (typeof deep === 'function') { + else if (typeof deep === "function") { recurseDepth = Infinity; recurseFn = deep; } @@ -85,27 +85,27 @@ function normalizeOptions (options, internalOptions) { recurseDepth = Infinity; recurseRegExp = deep; } - else if (typeof deep === 'string' && deep.length > 0) { + else if (typeof deep === "string" && deep.length > 0) { recurseDepth = Infinity; recurseGlob = globToRegExp(deep, { extended: true, globstar: true }); } else { - throw new TypeError('options.deep must be a boolean, number, function, regular expression, or glob pattern'); + throw new TypeError("options.deep must be a boolean, number, function, regular expression, or glob pattern"); } let filterFn, filterRegExp, filterGlob, filter = options.filter; if (filter !== null && filter !== undefined) { - if (typeof filter === 'function') { + if (typeof filter === "function") { filterFn = filter; } else if (filter instanceof RegExp) { filterRegExp = filter; } - else if (typeof filter === 'string' && filter.length > 0) { + else if (typeof filter === "string" && filter.length > 0) { filterGlob = globToRegExp(filter, { extended: true, globstar: true }); } else { - throw new TypeError('options.filter must be a function, regular expression, or glob pattern'); + throw new TypeError("options.filter must be a function, regular expression, or glob pattern"); } } @@ -113,34 +113,34 @@ function normalizeOptions (options, internalOptions) { if (sep === null || sep === undefined) { sep = path.sep; } - else if (typeof sep !== 'string') { - throw new TypeError('options.sep must be a string'); + else if (typeof sep !== "string") { + throw new TypeError("options.sep must be a string"); } let basePath = options.basePath; if (basePath === null || basePath === undefined) { - basePath = ''; + basePath = ""; } - else if (typeof basePath === 'string') { + else if (typeof basePath === "string") { // Append a path separator to the basePath, if necessary if (basePath && basePath.substr(-1) !== sep) { basePath += sep; } } else { - throw new TypeError('options.basePath must be a string'); + throw new TypeError("options.basePath must be a string"); } // Convert the basePath to POSIX (forward slashes) // so that glob pattern matching works consistently, even on Windows let posixBasePath = basePath; - if (posixBasePath && sep !== '/') { - posixBasePath = posixBasePath.replace(new RegExp('\\' + sep, 'g'), '/'); + if (posixBasePath && sep !== "/") { + posixBasePath = posixBasePath.replace(new RegExp("\\" + sep, "g"), "/"); /* istanbul ignore if */ if (isWindows) { // Convert Windows root paths (C:\) and UNCs (\\) to POSIX root paths - posixBasePath = posixBasePath.replace(/^([a-zA-Z]\:\/|\/\/)/, '/'); + posixBasePath = posixBasePath.replace(/^([a-zA-Z]\:\/|\/\/)/, "/"); } } @@ -150,13 +150,13 @@ function normalizeOptions (options, internalOptions) { // The user didn't provide their own facades, so use our internal ones facade = internalOptions.facade; } - else if (typeof options.fs === 'object') { + else if (typeof options.fs === "object") { // Merge the internal facade methods with the user-provided `fs` facades facade = Object.assign({}, internalOptions.facade); facade.fs = Object.assign({}, internalOptions.facade.fs, options.fs); } else { - throw new TypeError('options.fs must be an object'); + throw new TypeError("options.fs must be an object"); } return { diff --git a/lib/stat.js b/lib/stat.js index e338693..1ccddc1 100644 --- a/lib/stat.js +++ b/lib/stat.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const call = require('./call'); +const call = require("./call"); module.exports = stat; diff --git a/lib/stream/index.js b/lib/stream/index.js index d765acf..e3170ba 100644 --- a/lib/stream/index.js +++ b/lib/stream/index.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; module.exports = readdirStream; -const DirectoryReader = require('../directory-reader'); +const DirectoryReader = require("../directory-reader"); let streamFacade = { - fs: require('fs'), - forEach: require('../async/for-each'), + fs: require("fs"), + forEach: require("../async/for-each"), }; /** diff --git a/lib/sync/for-each.js b/lib/sync/for-each.js index c5ec088..95710a8 100644 --- a/lib/sync/for-each.js +++ b/lib/sync/for-each.js @@ -1,4 +1,4 @@ -'use strict'; +"use strict"; module.exports = syncForEach; diff --git a/lib/sync/fs.js b/lib/sync/fs.js index 3aada77..5ff7d3a 100644 --- a/lib/sync/fs.js +++ b/lib/sync/fs.js @@ -1,7 +1,7 @@ -'use strict'; +"use strict"; -const fs = require('fs'); -const call = require('../call'); +const fs = require("fs"); +const call = require("../call"); /** * A facade around {@link fs.readdirSync} that allows it to be called diff --git a/lib/sync/index.js b/lib/sync/index.js index 081bc89..4d9f811 100644 --- a/lib/sync/index.js +++ b/lib/sync/index.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; module.exports = readdirSync; -const DirectoryReader = require('../directory-reader'); +const DirectoryReader = require("../directory-reader"); let syncFacade = { - fs: require('./fs'), - forEach: require('./for-each'), + fs: require("./fs"), + forEach: require("./for-each"), }; /** diff --git a/test/fixtures/dir.js b/test/fixtures/dir.js index 676e375..114c433 100644 --- a/test/fixtures/dir.js +++ b/test/fixtures/dir.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; -const path = require('path'); +const path = require("path"); let isWindows = /^win/.test(process.platform); // This fake basePath is used to make sure Windows paths are handled properly. // The drive letter ("C:") is omitted when testing on POSIX systems, // because it gets interpreted as a path segment -let windowsBasePath = (isWindows ? 'C:' : '') + '\\Windows\\Users\\Desktop'; +let windowsBasePath = (isWindows ? "C:" : "") + "\\Windows\\Users\\Desktop"; let dir = module.exports = { windowsBasePath, @@ -15,190 +15,190 @@ let dir = module.exports = { shallow: { data: [ - '.dotdir', - '.dotfile', - 'broken-dir-symlink', - 'broken-symlink.txt', - 'empty', - 'empty.txt', - 'file-symlink.txt', - 'file.json', - 'file.txt', - 'subdir', - 'subdir-symlink', - 'subsubdir-symlink', + ".dotdir", + ".dotfile", + "broken-dir-symlink", + "broken-symlink.txt", + "empty", + "empty.txt", + "file-symlink.txt", + "file.json", + "file.txt", + "subdir", + "subdir-symlink", + "subsubdir-symlink", ], dirs: [ - '.dotdir', - 'empty', - 'subdir', - 'subdir-symlink', - 'subsubdir-symlink', + ".dotdir", + "empty", + "subdir", + "subdir-symlink", + "subsubdir-symlink", ], files: [ - '.dotfile', - 'empty.txt', - 'file-symlink.txt', - 'file.json', - 'file.txt', + ".dotfile", + "empty.txt", + "file-symlink.txt", + "file.json", + "file.txt", ], symlinks: [ - 'broken-dir-symlink', - 'broken-symlink.txt', - 'file-symlink.txt', - 'subdir-symlink', - 'subsubdir-symlink', + "broken-dir-symlink", + "broken-symlink.txt", + "file-symlink.txt", + "subdir-symlink", + "subsubdir-symlink", ], }, deep: { data: [ - '.dotdir', - '.dotfile', - 'broken-dir-symlink', - 'broken-symlink.txt', - 'empty', - 'empty.txt', - 'file-symlink.txt', - 'file.json', - 'file.txt', - 'subdir', - 'subdir-symlink', - 'subdir-symlink/.dotdir', - 'subdir-symlink/.dotdir/.dotfile', - 'subdir-symlink/.dotdir/empty', - 'subdir-symlink/file.txt', - 'subdir-symlink/subsubdir', - 'subdir-symlink/subsubdir/broken-symlink.txt', - 'subdir-symlink/subsubdir/empty.txt', - 'subdir-symlink/subsubdir/file-symlink.txt', - 'subdir-symlink/subsubdir/file.json', - 'subdir-symlink/subsubdir/file.txt', - 'subdir/.dotdir', - 'subdir/.dotdir/.dotfile', - 'subdir/.dotdir/empty', - 'subdir/file.txt', - 'subdir/subsubdir', - 'subdir/subsubdir/broken-symlink.txt', - 'subdir/subsubdir/empty.txt', - 'subdir/subsubdir/file-symlink.txt', - 'subdir/subsubdir/file.json', - 'subdir/subsubdir/file.txt', - 'subsubdir-symlink', - 'subsubdir-symlink/broken-symlink.txt', - 'subsubdir-symlink/empty.txt', - 'subsubdir-symlink/file-symlink.txt', - 'subsubdir-symlink/file.json', - 'subsubdir-symlink/file.txt', + ".dotdir", + ".dotfile", + "broken-dir-symlink", + "broken-symlink.txt", + "empty", + "empty.txt", + "file-symlink.txt", + "file.json", + "file.txt", + "subdir", + "subdir-symlink", + "subdir-symlink/.dotdir", + "subdir-symlink/.dotdir/.dotfile", + "subdir-symlink/.dotdir/empty", + "subdir-symlink/file.txt", + "subdir-symlink/subsubdir", + "subdir-symlink/subsubdir/broken-symlink.txt", + "subdir-symlink/subsubdir/empty.txt", + "subdir-symlink/subsubdir/file-symlink.txt", + "subdir-symlink/subsubdir/file.json", + "subdir-symlink/subsubdir/file.txt", + "subdir/.dotdir", + "subdir/.dotdir/.dotfile", + "subdir/.dotdir/empty", + "subdir/file.txt", + "subdir/subsubdir", + "subdir/subsubdir/broken-symlink.txt", + "subdir/subsubdir/empty.txt", + "subdir/subsubdir/file-symlink.txt", + "subdir/subsubdir/file.json", + "subdir/subsubdir/file.txt", + "subsubdir-symlink", + "subsubdir-symlink/broken-symlink.txt", + "subsubdir-symlink/empty.txt", + "subsubdir-symlink/file-symlink.txt", + "subsubdir-symlink/file.json", + "subsubdir-symlink/file.txt", ], dirs: [ - '.dotdir', - 'empty', - 'subdir', - 'subdir-symlink', - 'subdir-symlink/.dotdir', - 'subdir-symlink/.dotdir/empty', - 'subdir-symlink/subsubdir', - 'subdir/.dotdir', - 'subdir/.dotdir/empty', - 'subdir/subsubdir', - 'subsubdir-symlink', + ".dotdir", + "empty", + "subdir", + "subdir-symlink", + "subdir-symlink/.dotdir", + "subdir-symlink/.dotdir/empty", + "subdir-symlink/subsubdir", + "subdir/.dotdir", + "subdir/.dotdir/empty", + "subdir/subsubdir", + "subsubdir-symlink", ], files: [ - '.dotfile', - 'empty.txt', - 'file-symlink.txt', - 'file.json', - 'file.txt', - 'subdir-symlink/.dotdir/.dotfile', - 'subdir-symlink/file.txt', - 'subdir-symlink/subsubdir/empty.txt', - 'subdir-symlink/subsubdir/file-symlink.txt', - 'subdir-symlink/subsubdir/file.json', - 'subdir-symlink/subsubdir/file.txt', - 'subdir/.dotdir/.dotfile', - 'subdir/file.txt', - 'subdir/subsubdir/empty.txt', - 'subdir/subsubdir/file-symlink.txt', - 'subdir/subsubdir/file.json', - 'subdir/subsubdir/file.txt', - 'subsubdir-symlink/empty.txt', - 'subsubdir-symlink/file-symlink.txt', - 'subsubdir-symlink/file.json', - 'subsubdir-symlink/file.txt', + ".dotfile", + "empty.txt", + "file-symlink.txt", + "file.json", + "file.txt", + "subdir-symlink/.dotdir/.dotfile", + "subdir-symlink/file.txt", + "subdir-symlink/subsubdir/empty.txt", + "subdir-symlink/subsubdir/file-symlink.txt", + "subdir-symlink/subsubdir/file.json", + "subdir-symlink/subsubdir/file.txt", + "subdir/.dotdir/.dotfile", + "subdir/file.txt", + "subdir/subsubdir/empty.txt", + "subdir/subsubdir/file-symlink.txt", + "subdir/subsubdir/file.json", + "subdir/subsubdir/file.txt", + "subsubdir-symlink/empty.txt", + "subsubdir-symlink/file-symlink.txt", + "subsubdir-symlink/file.json", + "subsubdir-symlink/file.txt", ], symlinks: [ - 'broken-dir-symlink', - 'broken-symlink.txt', - 'file-symlink.txt', - 'subdir-symlink', - 'subdir-symlink/subsubdir/broken-symlink.txt', - 'subdir-symlink/subsubdir/file-symlink.txt', - 'subdir/subsubdir/broken-symlink.txt', - 'subdir/subsubdir/file-symlink.txt', - 'subsubdir-symlink', - 'subsubdir-symlink/broken-symlink.txt', - 'subsubdir-symlink/file-symlink.txt', + "broken-dir-symlink", + "broken-symlink.txt", + "file-symlink.txt", + "subdir-symlink", + "subdir-symlink/subsubdir/broken-symlink.txt", + "subdir-symlink/subsubdir/file-symlink.txt", + "subdir/subsubdir/broken-symlink.txt", + "subdir/subsubdir/file-symlink.txt", + "subsubdir-symlink", + "subsubdir-symlink/broken-symlink.txt", + "subsubdir-symlink/file-symlink.txt", ], oneLevel: { data: [ - '.dotdir', - '.dotfile', - 'broken-dir-symlink', - 'broken-symlink.txt', - 'empty', - 'empty.txt', - 'file-symlink.txt', - 'file.json', - 'file.txt', - 'subdir', - 'subdir-symlink', - 'subdir-symlink/.dotdir', - 'subdir-symlink/file.txt', - 'subdir-symlink/subsubdir', - 'subdir/.dotdir', - 'subdir/file.txt', - 'subdir/subsubdir', - 'subsubdir-symlink', - 'subsubdir-symlink/broken-symlink.txt', - 'subsubdir-symlink/empty.txt', - 'subsubdir-symlink/file-symlink.txt', - 'subsubdir-symlink/file.json', - 'subsubdir-symlink/file.txt', + ".dotdir", + ".dotfile", + "broken-dir-symlink", + "broken-symlink.txt", + "empty", + "empty.txt", + "file-symlink.txt", + "file.json", + "file.txt", + "subdir", + "subdir-symlink", + "subdir-symlink/.dotdir", + "subdir-symlink/file.txt", + "subdir-symlink/subsubdir", + "subdir/.dotdir", + "subdir/file.txt", + "subdir/subsubdir", + "subsubdir-symlink", + "subsubdir-symlink/broken-symlink.txt", + "subsubdir-symlink/empty.txt", + "subsubdir-symlink/file-symlink.txt", + "subsubdir-symlink/file.json", + "subsubdir-symlink/file.txt", ], dirs: [ - '.dotdir', - 'empty', - 'subdir', - 'subdir-symlink', - 'subdir-symlink/.dotdir', - 'subdir-symlink/subsubdir', - 'subdir/.dotdir', - 'subdir/subsubdir', - 'subsubdir-symlink', + ".dotdir", + "empty", + "subdir", + "subdir-symlink", + "subdir-symlink/.dotdir", + "subdir-symlink/subsubdir", + "subdir/.dotdir", + "subdir/subsubdir", + "subsubdir-symlink", ], files: [ - '.dotfile', - 'empty.txt', - 'file-symlink.txt', - 'file.json', - 'file.txt', - 'subdir-symlink/file.txt', - 'subdir/file.txt', - 'subsubdir-symlink/empty.txt', - 'subsubdir-symlink/file-symlink.txt', - 'subsubdir-symlink/file.json', - 'subsubdir-symlink/file.txt', + ".dotfile", + "empty.txt", + "file-symlink.txt", + "file.json", + "file.txt", + "subdir-symlink/file.txt", + "subdir/file.txt", + "subsubdir-symlink/empty.txt", + "subsubdir-symlink/file-symlink.txt", + "subsubdir-symlink/file.json", + "subsubdir-symlink/file.txt", ], symlinks: [ - 'broken-dir-symlink', - 'broken-symlink.txt', - 'file-symlink.txt', - 'subdir-symlink', - 'subsubdir-symlink', - 'subsubdir-symlink/broken-symlink.txt', - 'subsubdir-symlink/file-symlink.txt', + "broken-dir-symlink", + "broken-symlink.txt", + "file-symlink.txt", + "subdir-symlink", + "subsubdir-symlink", + "subsubdir-symlink/broken-symlink.txt", + "subsubdir-symlink/file-symlink.txt", ], }, }, @@ -206,160 +206,160 @@ let dir = module.exports = { subdir: { shallow: { data: [ - '.dotdir', - 'file.txt', - 'subsubdir', + ".dotdir", + "file.txt", + "subsubdir", ], dirs: [ - '.dotdir', - 'subsubdir', + ".dotdir", + "subsubdir", ], files: [ - 'file.txt', + "file.txt", ], symlinks: [], }, deep: { data: [ - '.dotdir', - '.dotdir/.dotfile', - '.dotdir/empty', - 'file.txt', - 'subsubdir', - 'subsubdir/broken-symlink.txt', - 'subsubdir/empty.txt', - 'subsubdir/file-symlink.txt', - 'subsubdir/file.json', - 'subsubdir/file.txt', + ".dotdir", + ".dotdir/.dotfile", + ".dotdir/empty", + "file.txt", + "subsubdir", + "subsubdir/broken-symlink.txt", + "subsubdir/empty.txt", + "subsubdir/file-symlink.txt", + "subsubdir/file.json", + "subsubdir/file.txt", ], dirs: [ - '.dotdir', - '.dotdir/empty', - 'subsubdir', + ".dotdir", + ".dotdir/empty", + "subsubdir", ], files: [ - '.dotdir/.dotfile', - 'file.txt', - 'subsubdir/empty.txt', - 'subsubdir/file-symlink.txt', - 'subsubdir/file.json', - 'subsubdir/file.txt', + ".dotdir/.dotfile", + "file.txt", + "subsubdir/empty.txt", + "subsubdir/file-symlink.txt", + "subsubdir/file.json", + "subsubdir/file.txt", ], symlinks: [ - 'subsubdir/broken-symlink.txt', - 'subsubdir/file-symlink.txt', + "subsubdir/broken-symlink.txt", + "subsubdir/file-symlink.txt", ], }, txt: { shallow: { data: [ - 'file.txt', + "file.txt", ], dirs: [], files: [ - 'file.txt', + "file.txt", ], symlinks: [], }, deep: { data: [ - 'file.txt', - 'subsubdir/broken-symlink.txt', - 'subsubdir/empty.txt', - 'subsubdir/file-symlink.txt', - 'subsubdir/file.txt', + "file.txt", + "subsubdir/broken-symlink.txt", + "subsubdir/empty.txt", + "subsubdir/file-symlink.txt", + "subsubdir/file.txt", ], dirs: [], files: [ - 'file.txt', - 'subsubdir/empty.txt', - 'subsubdir/file-symlink.txt', - 'subsubdir/file.txt', + "file.txt", + "subsubdir/empty.txt", + "subsubdir/file-symlink.txt", + "subsubdir/file.txt", ], symlinks: [ - 'subsubdir/broken-symlink.txt', - 'subsubdir/file-symlink.txt', + "subsubdir/broken-symlink.txt", + "subsubdir/file-symlink.txt", ], }, }, subsubdir: { data: [ - 'broken-symlink.txt', - 'empty.txt', - 'file-symlink.txt', - 'file.json', - 'file.txt', + "broken-symlink.txt", + "empty.txt", + "file-symlink.txt", + "file.json", + "file.txt", ], dirs: [], files: [ - 'empty.txt', - 'file-symlink.txt', - 'file.json', - 'file.txt', + "empty.txt", + "file-symlink.txt", + "file.json", + "file.txt", ], symlinks: [ - 'broken-symlink.txt', - 'file-symlink.txt', + "broken-symlink.txt", + "file-symlink.txt", ], txt: { data: [ - 'broken-symlink.txt', - 'empty.txt', - 'file-symlink.txt', - 'file.txt', + "broken-symlink.txt", + "empty.txt", + "file-symlink.txt", + "file.txt", ], dirs: [], files: [ - 'empty.txt', - 'file-symlink.txt', - 'file.txt', + "empty.txt", + "file-symlink.txt", + "file.txt", ], symlinks: [ - 'broken-symlink.txt', - 'file-symlink.txt', + "broken-symlink.txt", + "file-symlink.txt", ], windowsStyle: { fromDir: { data: [ - 'subdir\\subsubdir\\broken-symlink.txt', - 'subdir\\subsubdir\\empty.txt', - 'subdir\\subsubdir\\file-symlink.txt', - 'subdir\\subsubdir\\file.txt', + "subdir\\subsubdir\\broken-symlink.txt", + "subdir\\subsubdir\\empty.txt", + "subdir\\subsubdir\\file-symlink.txt", + "subdir\\subsubdir\\file.txt", ], dirs: [], files: [ - 'subdir\\subsubdir\\empty.txt', - 'subdir\\subsubdir\\file-symlink.txt', - 'subdir\\subsubdir\\file.txt', + "subdir\\subsubdir\\empty.txt", + "subdir\\subsubdir\\file-symlink.txt", + "subdir\\subsubdir\\file.txt", ], symlinks: [ - 'subdir\\subsubdir\\broken-symlink.txt', - 'subdir\\subsubdir\\file-symlink.txt', + "subdir\\subsubdir\\broken-symlink.txt", + "subdir\\subsubdir\\file-symlink.txt", ], }, fromRoot: { data: [ - windowsBasePath + '\\subdir\\subsubdir\\broken-symlink.txt', - windowsBasePath + '\\subdir\\subsubdir\\empty.txt', - windowsBasePath + '\\subdir\\subsubdir\\file-symlink.txt', - windowsBasePath + '\\subdir\\subsubdir\\file.txt', + windowsBasePath + "\\subdir\\subsubdir\\broken-symlink.txt", + windowsBasePath + "\\subdir\\subsubdir\\empty.txt", + windowsBasePath + "\\subdir\\subsubdir\\file-symlink.txt", + windowsBasePath + "\\subdir\\subsubdir\\file.txt", ], dirs: [], files: [ - windowsBasePath + '\\subdir\\subsubdir\\empty.txt', - windowsBasePath + '\\subdir\\subsubdir\\file-symlink.txt', - windowsBasePath + '\\subdir\\subsubdir\\file.txt', + windowsBasePath + "\\subdir\\subsubdir\\empty.txt", + windowsBasePath + "\\subdir\\subsubdir\\file-symlink.txt", + windowsBasePath + "\\subdir\\subsubdir\\file.txt", ], symlinks: [ - windowsBasePath + '\\subdir\\subsubdir\\broken-symlink.txt', - windowsBasePath + '\\subdir\\subsubdir\\file-symlink.txt', + windowsBasePath + "\\subdir\\subsubdir\\broken-symlink.txt", + windowsBasePath + "\\subdir\\subsubdir\\file-symlink.txt", ], }, } @@ -370,70 +370,70 @@ let dir = module.exports = { txt: { shallow: { data: [ - 'broken-symlink.txt', - 'empty.txt', - 'file.txt', - 'file-symlink.txt', + "broken-symlink.txt", + "empty.txt", + "file.txt", + "file-symlink.txt", ], dirs: [], files: [ - 'empty.txt', - 'file.txt', - 'file-symlink.txt', + "empty.txt", + "file.txt", + "file-symlink.txt", ], symlinks: [ - 'broken-symlink.txt', - 'file-symlink.txt', + "broken-symlink.txt", + "file-symlink.txt", ], }, deep: { data: [ - 'broken-symlink.txt', - 'empty.txt', - 'file-symlink.txt', - 'file.txt', - 'subdir/file.txt', - 'subdir/subsubdir/broken-symlink.txt', - 'subdir/subsubdir/empty.txt', - 'subdir/subsubdir/file-symlink.txt', - 'subdir/subsubdir/file.txt', - 'subdir-symlink/file.txt', - 'subdir-symlink/subsubdir/broken-symlink.txt', - 'subdir-symlink/subsubdir/empty.txt', - 'subdir-symlink/subsubdir/file-symlink.txt', - 'subdir-symlink/subsubdir/file.txt', - 'subsubdir-symlink/broken-symlink.txt', - 'subsubdir-symlink/empty.txt', - 'subsubdir-symlink/file-symlink.txt', - 'subsubdir-symlink/file.txt', + "broken-symlink.txt", + "empty.txt", + "file-symlink.txt", + "file.txt", + "subdir/file.txt", + "subdir/subsubdir/broken-symlink.txt", + "subdir/subsubdir/empty.txt", + "subdir/subsubdir/file-symlink.txt", + "subdir/subsubdir/file.txt", + "subdir-symlink/file.txt", + "subdir-symlink/subsubdir/broken-symlink.txt", + "subdir-symlink/subsubdir/empty.txt", + "subdir-symlink/subsubdir/file-symlink.txt", + "subdir-symlink/subsubdir/file.txt", + "subsubdir-symlink/broken-symlink.txt", + "subsubdir-symlink/empty.txt", + "subsubdir-symlink/file-symlink.txt", + "subsubdir-symlink/file.txt", ], dirs: [], files: [ - 'empty.txt', - 'file.txt', - 'file-symlink.txt', - 'subdir/file.txt', - 'subdir/subsubdir/empty.txt', - 'subdir/subsubdir/file.txt', - 'subdir/subsubdir/file-symlink.txt', - 'subdir-symlink/file.txt', - 'subdir-symlink/subsubdir/empty.txt', - 'subdir-symlink/subsubdir/file.txt', - 'subdir-symlink/subsubdir/file-symlink.txt', - 'subsubdir-symlink/empty.txt', - 'subsubdir-symlink/file.txt', - 'subsubdir-symlink/file-symlink.txt', + "empty.txt", + "file.txt", + "file-symlink.txt", + "subdir/file.txt", + "subdir/subsubdir/empty.txt", + "subdir/subsubdir/file.txt", + "subdir/subsubdir/file-symlink.txt", + "subdir-symlink/file.txt", + "subdir-symlink/subsubdir/empty.txt", + "subdir-symlink/subsubdir/file.txt", + "subdir-symlink/subsubdir/file-symlink.txt", + "subsubdir-symlink/empty.txt", + "subsubdir-symlink/file.txt", + "subsubdir-symlink/file-symlink.txt", ], symlinks: [ - 'broken-symlink.txt', - 'file-symlink.txt', - 'subdir/subsubdir/broken-symlink.txt', - 'subdir/subsubdir/file-symlink.txt', - 'subdir-symlink/subsubdir/broken-symlink.txt', - 'subdir-symlink/subsubdir/file-symlink.txt', - 'subsubdir-symlink/broken-symlink.txt', - 'subsubdir-symlink/file-symlink.txt', + "broken-symlink.txt", + "file-symlink.txt", + "subdir/subsubdir/broken-symlink.txt", + "subdir/subsubdir/file-symlink.txt", + "subdir-symlink/subsubdir/broken-symlink.txt", + "subdir-symlink/subsubdir/file-symlink.txt", + "subsubdir-symlink/broken-symlink.txt", + "subsubdir-symlink/file-symlink.txt", ], }, }, @@ -441,38 +441,38 @@ let dir = module.exports = { empties: { shallow: { data: [ - 'empty', - 'empty.txt', + "empty", + "empty.txt", ], dirs: [ - 'empty', + "empty", ], files: [ - 'empty.txt', + "empty.txt", ], symlinks: [], }, deep: { data: [ - 'empty', - 'empty.txt', - 'subdir/.dotdir/empty', - 'subdir/subsubdir/empty.txt', - 'subdir-symlink/.dotdir/empty', - 'subdir-symlink/subsubdir/empty.txt', - 'subsubdir-symlink/empty.txt', + "empty", + "empty.txt", + "subdir/.dotdir/empty", + "subdir/subsubdir/empty.txt", + "subdir-symlink/.dotdir/empty", + "subdir-symlink/subsubdir/empty.txt", + "subsubdir-symlink/empty.txt", ], dirs: [ - 'empty', - 'subdir/.dotdir/empty', - 'subdir-symlink/.dotdir/empty', + "empty", + "subdir/.dotdir/empty", + "subdir-symlink/.dotdir/empty", ], files: [ - 'empty.txt', - 'subdir/subsubdir/empty.txt', - 'subdir-symlink/subsubdir/empty.txt', - 'subsubdir-symlink/empty.txt', + "empty.txt", + "subdir/subsubdir/empty.txt", + "subdir-symlink/subsubdir/empty.txt", + "subsubdir-symlink/empty.txt", ], symlinks: [], }, @@ -481,21 +481,21 @@ let dir = module.exports = { symlinks: { deep: { files: [ - 'file-symlink.txt', - 'subdir/subsubdir/file-symlink.txt', - 'subdir-symlink/subsubdir/file-symlink.txt', - 'subsubdir-symlink/file-symlink.txt', + "file-symlink.txt", + "subdir/subsubdir/file-symlink.txt", + "subdir-symlink/subsubdir/file-symlink.txt", + "subsubdir-symlink/file-symlink.txt", ], dirs: [ - 'subdir-symlink', - 'subsubdir-symlink', + "subdir-symlink", + "subsubdir-symlink", ], }, }, }; // Change all the path separators to "\" on Windows -if (path.sep !== '/') { +if (path.sep !== "/") { changePathSeparatorsRecursive(dir); } @@ -505,7 +505,7 @@ function changePathSeparatorsRecursive (obj) { if (Array.isArray(value)) { obj[key] = value.map(changePathSeparators); } - else if (typeof value === 'object') { + else if (typeof value === "object") { changePathSeparatorsRecursive(value); } }); diff --git a/test/fixtures/for-each-api.js b/test/fixtures/for-each-api.js index 60a7ae2..45c065e 100644 --- a/test/fixtures/for-each-api.js +++ b/test/fixtures/for-each-api.js @@ -1,6 +1,6 @@ -'use strict'; +"use strict"; -const readdir = require('../../'); +const readdir = require("../../"); module.exports = forEachApi; @@ -8,9 +8,9 @@ module.exports = forEachApi; * Runs an array of tests tests against each of the readdir-enhanced APIs */ function forEachApi (tests) { - describe('Synchronous API', () => { + describe("Synchronous API", () => { tests.forEach(test => { - testApi(test, 'sync', done => { + testApi(test, "sync", done => { try { let data = readdir.sync.apply(null, test.args); done(null, data); @@ -22,9 +22,9 @@ function forEachApi (tests) { }); }); - describe('Asynchronous API (callback/Promise)', () => { + describe("Asynchronous API (callback/Promise)", () => { tests.forEach(test => { - testApi(test, 'async', done => { + testApi(test, "async", done => { readdir.async.apply(null, test.args) .then( data => { @@ -38,9 +38,9 @@ function forEachApi (tests) { }); }); - describe('Asynchronous API (Stream/EventEmitter)', () => { + describe("Asynchronous API (Stream/EventEmitter)", () => { tests.forEach(test => { - testApi(test, 'stream', done => { + testApi(test, "stream", done => { let stream, errors = [], data = [], files = [], dirs = [], symlinks = []; try { @@ -50,22 +50,22 @@ function forEachApi (tests) { return done([error], data, files, dirs, symlinks); } - stream.on('error', error => { + stream.on("error", error => { errors.push(error); }); - stream.on('file', file => { + stream.on("file", file => { files.push(file); }); - stream.on('directory', dir => { + stream.on("directory", dir => { dirs.push(dir); }); - stream.on('symlink', symlink => { + stream.on("symlink", symlink => { symlinks.push(symlink); }); - stream.on('data', datum => { + stream.on("data", datum => { data.push(datum); }); - stream.on('end', () => { + stream.on("end", () => { done(errors, data, files, dirs, symlinks); }); }); @@ -103,7 +103,7 @@ function testApi (test, apiName, api) { dirs && dirs.sort(); symlinks && symlinks.sort(); - if (apiName === 'stream') { + if (apiName === "stream") { // Perform assertions that are specific to the streaming API if (test.streamAssert) { test.streamAssert(errors, data, files, dirs, symlinks); @@ -129,13 +129,13 @@ function testApi (test, apiName, api) { done(e); console.error( - '==================== ACTUAL RESULTS ====================\n' + - 'errors: ' + JSON.stringify(errors) + '\n\n' + - 'data: ' + JSON.stringify(data) + '\n\n' + - 'files: ' + JSON.stringify(files) + '\n\n' + - 'dirs: ' + JSON.stringify(dirs) + '\n\n' + - 'symlinks: ' + JSON.stringify(symlinks) + '\n' + - '========================================================' + "==================== ACTUAL RESULTS ====================\n" + + "errors: " + JSON.stringify(errors) + "\n\n" + + "data: " + JSON.stringify(data) + "\n\n" + + "files: " + JSON.stringify(files) + "\n\n" + + "dirs: " + JSON.stringify(dirs) + "\n\n" + + "symlinks: " + JSON.stringify(symlinks) + "\n" + + "========================================================" ); } }); diff --git a/test/fixtures/init.js b/test/fixtures/init.js index 0bd35a4..335ee0e 100644 --- a/test/fixtures/init.js +++ b/test/fixtures/init.js @@ -1,32 +1,32 @@ -'use strict'; +"use strict"; -const mkdirp = require('mkdirp'); -const del = require('del'); -const path = require('path'); -const fs = require('fs'); +const mkdirp = require("mkdirp"); +const del = require("del"); +const path = require("path"); +const fs = require("fs"); before(() => { - console.log('Initializing test directory'); + console.log("Initializing test directory"); // create some empty dirs (cannot check-in empty dirs to git) - mkdirp.sync('test/dir/.dotdir'); - mkdirp.sync('test/dir/empty'); - mkdirp.sync('test/dir/subdir/.dotdir/empty'); + mkdirp.sync("test/dir/.dotdir"); + mkdirp.sync("test/dir/empty"); + mkdirp.sync("test/dir/subdir/.dotdir/empty"); // create symlinks (checking symlinks into git is problematic cross-platform) - symlink('test/dir/file.txt', 'test/dir/file-symlink.txt', 'file'); - symlink('test/dir/subdir/subsubdir/file.txt', 'test/dir/subdir/subsubdir/file-symlink.txt', 'file'); - symlink('test/dir/subdir', 'test/dir/subdir-symlink', 'dir'); - symlink('test/dir/subdir/subsubdir', 'test/dir/subsubdir-symlink', 'dir'); + symlink("test/dir/file.txt", "test/dir/file-symlink.txt", "file"); + symlink("test/dir/subdir/subsubdir/file.txt", "test/dir/subdir/subsubdir/file-symlink.txt", "file"); + symlink("test/dir/subdir", "test/dir/subdir-symlink", "dir"); + symlink("test/dir/subdir/subsubdir", "test/dir/subsubdir-symlink", "dir"); // create broken symlinks (checking broken symlinks into git is problematic) - brokenSymlink('test/dir/broken-symlink.txt', 'file'); - brokenSymlink('test/dir/subdir/subsubdir/broken-symlink.txt', 'file'); - brokenSymlink('test/dir/broken-dir-symlink', 'dir'); + brokenSymlink("test/dir/broken-symlink.txt", "file"); + brokenSymlink("test/dir/subdir/subsubdir/broken-symlink.txt", "file"); + brokenSymlink("test/dir/broken-dir-symlink", "dir"); // delete files that get created automatically by the OS - del.sync('test/dir/**/.DS_Store', { dot: true }); - del.sync('test/dir/**/Thumbs.db', { dot: true }); + del.sync("test/dir/**/.DS_Store", { dot: true }); + del.sync("test/dir/**/Thumbs.db", { dot: true }); }); /** @@ -38,7 +38,7 @@ function symlink (targetPath, linkPath, type) { fs.unlinkSync(linkPath); } catch (e) { - if (e.code !== 'ENOENT') { + if (e.code !== "ENOENT") { throw e; } } @@ -53,8 +53,8 @@ function symlink (targetPath, linkPath, type) { function brokenSymlink (linkPath, type) { let tmp = path.join(path.dirname(linkPath), Date.now() + type); - if (type === 'file') { - fs.writeFileSync(tmp, ''); + if (type === "file") { + fs.writeFileSync(tmp, ""); symlink(tmp, linkPath, type); fs.unlinkSync(tmp); } diff --git a/test/specs/basePath.spec.js b/test/specs/basePath.spec.js index 5c73c28..7646d67 100644 --- a/test/specs/basePath.spec.js +++ b/test/specs/basePath.spec.js @@ -1,17 +1,17 @@ -'use strict'; +"use strict"; -const forEachApi = require('../fixtures/for-each-api'); -const dir = require('../fixtures/dir'); -const expect = require('chai').expect; -const path = require('path'); +const forEachApi = require("../fixtures/for-each-api"); +const dir = require("../fixtures/dir"); +const expect = require("chai").expect; +const path = require("path"); -let testDirAbsPath = path.resolve('test/dir'); +let testDirAbsPath = path.resolve("test/dir"); -describe('options.basePath', () => { +describe("options.basePath", () => { forEachApi([ { it: 'should return relative paths if basePath === "" (empty string)', - args: ['test/dir', { basePath: '' }], + args: ["test/dir", { basePath: "" }], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.shallow.data); @@ -26,22 +26,22 @@ describe('options.basePath', () => { }, { it: 'should return relative paths if basePath === "."', - args: ['test/dir', { basePath: '.' }], + args: ["test/dir", { basePath: "." }], assert (error, data) { expect(error).to.be.null; - assertPathsMatch(data, dir.shallow.data, '.'); + assertPathsMatch(data, dir.shallow.data, "."); }, streamAssert (errors, data, files, dirs, symlinks) { expect(errors).to.have.lengthOf(0); - assertPathsMatch(data, dir.shallow.data, '.'); - assertPathsMatch(files, dir.shallow.files, '.'); - assertPathsMatch(dirs, dir.shallow.dirs, '.'); - assertPathsMatch(symlinks, dir.shallow.symlinks, '.'); + assertPathsMatch(data, dir.shallow.data, "."); + assertPathsMatch(files, dir.shallow.files, "."); + assertPathsMatch(dirs, dir.shallow.dirs, "."); + assertPathsMatch(symlinks, dir.shallow.symlinks, "."); }, }, { - it: 'should return absolute paths if basePath === absolute path', - args: ['test/dir', { basePath: testDirAbsPath }], + it: "should return absolute paths if basePath === absolute path", + args: ["test/dir", { basePath: testDirAbsPath }], assert (error, data) { expect(error).to.be.null; assertPathsMatch(data, dir.shallow.data, testDirAbsPath); @@ -55,18 +55,18 @@ describe('options.basePath', () => { }, }, { - it: 'should return relative paths to process.cwd() if basePath === path', - args: ['test/dir', { basePath: 'test/dir' }], + it: "should return relative paths to process.cwd() if basePath === path", + args: ["test/dir", { basePath: "test/dir" }], assert (error, data) { expect(error).to.be.null; - assertPathsMatch(data, dir.shallow.data, 'test/dir'); + assertPathsMatch(data, dir.shallow.data, "test/dir"); }, streamAssert (errors, data, files, dirs, symlinks) { expect(errors).to.have.lengthOf(0); - assertPathsMatch(data, dir.shallow.data, 'test/dir'); - assertPathsMatch(files, dir.shallow.files, 'test/dir'); - assertPathsMatch(dirs, dir.shallow.dirs, 'test/dir'); - assertPathsMatch(symlinks, dir.shallow.symlinks, 'test/dir'); + assertPathsMatch(data, dir.shallow.data, "test/dir"); + assertPathsMatch(files, dir.shallow.files, "test/dir"); + assertPathsMatch(dirs, dir.shallow.dirs, "test/dir"); + assertPathsMatch(symlinks, dir.shallow.symlinks, "test/dir"); }, }, ]); diff --git a/test/specs/deep.spec.js b/test/specs/deep.spec.js index 516210e..bbd2b65 100644 --- a/test/specs/deep.spec.js +++ b/test/specs/deep.spec.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -const forEachApi = require('../fixtures/for-each-api'); -const dir = require('../fixtures/dir'); -const expect = require('chai').expect; -const path = require('path'); +const forEachApi = require("../fixtures/for-each-api"); +const dir = require("../fixtures/dir"); +const expect = require("chai").expect; +const path = require("path"); -describe('options.deep', () => { +describe("options.deep", () => { forEachApi([ { - it: 'should return all deep contents', - args: ['test/dir', { deep: true }], + it: "should return all deep contents", + args: ["test/dir", { deep: true }], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.deep.data); @@ -23,8 +23,8 @@ describe('options.deep', () => { }, }, { - it: 'should only return top-level contents if deep === false', - args: ['test/dir', { deep: false }], + it: "should only return top-level contents if deep === false", + args: ["test/dir", { deep: false }], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.shallow.data); @@ -38,8 +38,8 @@ describe('options.deep', () => { }, }, { - it: 'should only return top-level contents if deep === 0', - args: ['test/dir', { deep: 0 }], + it: "should only return top-level contents if deep === 0", + args: ["test/dir", { deep: 0 }], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.shallow.data); @@ -53,8 +53,8 @@ describe('options.deep', () => { }, }, { - it: 'should return 1-level deep contents', - args: ['test/dir', { deep: 1 }], + it: "should return 1-level deep contents", + args: ["test/dir", { deep: 1 }], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.deep.oneLevel.data); @@ -68,8 +68,8 @@ describe('options.deep', () => { }, }, { - it: 'should return all deep contents if deep is a number greater than the number of dirs', - args: ['test/dir', { deep: 25 }], + it: "should return all deep contents if deep is a number greater than the number of dirs", + args: ["test/dir", { deep: 25 }], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.deep.data); @@ -83,8 +83,8 @@ describe('options.deep', () => { }, }, { - it: 'should return all deep contents if deep === Infinity', - args: ['test/dir', { deep: Infinity }], + it: "should return all deep contents if deep === Infinity", + args: ["test/dir", { deep: Infinity }], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.deep.data); @@ -98,8 +98,8 @@ describe('options.deep', () => { }, }, { - it: 'should recurse based on a regular expression', - args: ['test/dir', { + it: "should recurse based on a regular expression", + args: ["test/dir", { deep: /^((?!\-symlink).)*$/, }], assert (error, data) { @@ -117,41 +117,41 @@ describe('options.deep', () => { // Omits the contents of the "-symlink" directories omitSymlinkDirs (paths) { return paths.filter(p => { - return p.indexOf('-symlink' + path.sep) === -1; + return p.indexOf("-symlink" + path.sep) === -1; }); } }, { - it: 'should recurse based on a glob pattern', - args: ['test/dir', { - deep: 'subdir', + it: "should recurse based on a glob pattern", + args: ["test/dir", { + deep: "subdir", }], assert (error, data) { expect(error).to.be.null; - expect(data).to.have.same.members(this.shallowPlusSubdir('data')); + expect(data).to.have.same.members(this.shallowPlusSubdir("data")); }, streamAssert (errors, data, files, dirs, symlinks) { expect(errors).to.have.lengthOf(0); - expect(data).to.have.same.members(this.shallowPlusSubdir('data')); - expect(files).to.have.same.members(this.shallowPlusSubdir('files')); - expect(dirs).to.have.same.members(this.shallowPlusSubdir('dirs')); - expect(symlinks).to.have.same.members(this.shallowPlusSubdir('symlinks')); + expect(data).to.have.same.members(this.shallowPlusSubdir("data")); + expect(files).to.have.same.members(this.shallowPlusSubdir("files")); + expect(dirs).to.have.same.members(this.shallowPlusSubdir("dirs")); + expect(symlinks).to.have.same.members(this.shallowPlusSubdir("symlinks")); }, // Returns the shallow contents of the root directory and the "subdir" directory shallowPlusSubdir (type) { return dir.shallow[type].concat( dir.subdir.shallow[type].map(file => { - return path.join('subdir', file); + return path.join("subdir", file); }) ); } }, { - it: 'should recurse based on a custom function', - args: ['test/dir', { + it: "should recurse based on a custom function", + args: ["test/dir", { deep (stats) { - return stats.path !== 'subdir'; + return stats.path !== "subdir"; }, }], assert (error, data) { @@ -169,13 +169,13 @@ describe('options.deep', () => { // Omits the contents of the "subdir" directory omitSubdir (paths) { return paths.filter(p => { - return p.substr(0, 7) !== 'subdir' + path.sep; + return p.substr(0, 7) !== "subdir" + path.sep; }); } }, { - it: 'should recurse based on a custom function with depth property', - args: ['test/dir', { + it: "should recurse based on a custom function with depth property", + args: ["test/dir", { deep (stats) { return stats.depth !== 1; }, @@ -200,8 +200,8 @@ describe('options.deep', () => { } }, { - it: 'should return all deep contents if custom deep function always returns true', - args: ['test/dir', { + it: "should return all deep contents if custom deep function always returns true", + args: ["test/dir", { deep () { return true; }, @@ -219,8 +219,8 @@ describe('options.deep', () => { }, }, { - it: 'should return shallow contents if custom deep function always returns false', - args: ['test/dir', { + it: "should return shallow contents if custom deep function always returns false", + args: ["test/dir", { deep () { return false; }, @@ -238,11 +238,11 @@ describe('options.deep', () => { }, }, { - it: 'should handle errors that occur in the deep function', - args: ['test/dir', { + it: "should handle errors that occur in the deep function", + args: ["test/dir", { deep (stats) { if (stats.isSymbolicLink()) { - throw new Error('Boooooom!'); + throw new Error("Boooooom!"); } return false; } @@ -250,26 +250,26 @@ describe('options.deep', () => { assert (error, data) { // The sync & async APIs abort after the first error and don't return any data expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal('Boooooom!'); + expect(error.message).to.equal("Boooooom!"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { // The streaming API emits errors and data separately expect(errors).to.have.lengthOf(2); expect(data).to.have.same.members([ - '.dotdir', 'empty', 'subdir', '.dotfile', 'empty.txt', 'file.txt', 'file.json', - 'broken-dir-symlink', 'broken-symlink.txt', 'file-symlink.txt', 'subdir-symlink', - 'subsubdir-symlink' + ".dotdir", "empty", "subdir", ".dotfile", "empty.txt", "file.txt", "file.json", + "broken-dir-symlink", "broken-symlink.txt", "file-symlink.txt", "subdir-symlink", + "subsubdir-symlink" ]); expect(files).to.have.same.members([ - '.dotfile', 'empty.txt', 'file.txt', 'file.json', 'file-symlink.txt' + ".dotfile", "empty.txt", "file.txt", "file.json", "file-symlink.txt" ]); expect(dirs).to.have.same.members([ - '.dotdir', 'empty', 'subdir', 'subdir-symlink', 'subsubdir-symlink' + ".dotdir", "empty", "subdir", "subdir-symlink", "subsubdir-symlink" ]); expect(symlinks).to.have.same.members([ - 'broken-dir-symlink', 'broken-symlink.txt', 'file-symlink.txt', 'subdir-symlink', - 'subsubdir-symlink' + "broken-dir-symlink", "broken-symlink.txt", "file-symlink.txt", "subdir-symlink", + "subsubdir-symlink" ]); }, }, diff --git a/test/specs/default.spec.js b/test/specs/default.spec.js index 3d18149..66ad9fd 100644 --- a/test/specs/default.spec.js +++ b/test/specs/default.spec.js @@ -1,28 +1,28 @@ -'use strict'; +"use strict"; -const forEachApi = require('../fixtures/for-each-api'); -const dir = require('../fixtures/dir'); -const expect = require('chai').expect; -const fs = require('fs'); -const path = require('path'); +const forEachApi = require("../fixtures/for-each-api"); +const dir = require("../fixtures/dir"); +const expect = require("chai").expect; +const fs = require("fs"); +const path = require("path"); -describe('default behavior', () => { +describe("default behavior", () => { forEachApi([ { - it: 'should return the same results as `fs.readdir`', - args: ['test/dir'], + it: "should return the same results as `fs.readdir`", + args: ["test/dir"], assert (error, data) { - let fsResults = fs.readdirSync('test/dir'); + let fsResults = fs.readdirSync("test/dir"); expect(error).to.be.null; expect(data).to.have.same.members(fsResults); }, }, { - it: 'should return an empty array for an empty dir', - args: ['test/dir/empty'], + it: "should return an empty array for an empty dir", + args: ["test/dir/empty"], assert (error, data) { expect(error).to.be.null; - expect(data).to.be.an('array').with.lengthOf(0); + expect(data).to.be.an("array").with.lengthOf(0); }, streamAssert (errors, data, files, dirs, symlinks) { expect(errors).to.have.lengthOf(0); @@ -33,8 +33,8 @@ describe('default behavior', () => { }, }, { - it: 'should return all top-level contents', - args: ['test/dir'], + it: "should return all top-level contents", + args: ["test/dir"], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.shallow.data); @@ -48,8 +48,8 @@ describe('default behavior', () => { }, }, { - it: 'should return the same results if the path is absolute', - args: [path.resolve('test/dir')], + it: "should return the same results if the path is absolute", + args: [path.resolve("test/dir")], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.shallow.data); @@ -63,8 +63,8 @@ describe('default behavior', () => { }, }, { - it: 'should return all top-level contents of a directory symlink', - args: ['test/dir/subdir-symlink'], + it: "should return all top-level contents of a directory symlink", + args: ["test/dir/subdir-symlink"], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.subdir.shallow.data); @@ -78,13 +78,13 @@ describe('default behavior', () => { }, }, { - it: 'should return relative paths', - args: ['test/dir'], + it: "should return relative paths", + args: ["test/dir"], assert (error, data) { expect(error).to.be.null; data.forEach(item => { - expect(item).not.to.contain('/'); - expect(item).not.to.contain('\\'); + expect(item).not.to.contain("/"); + expect(item).not.to.contain("\\"); }); }, streamAssert (errors, data, files, dirs, symlinks) { diff --git a/test/specs/errors.spec.js b/test/specs/errors.spec.js index 695bff7..a80ee66 100644 --- a/test/specs/errors.spec.js +++ b/test/specs/errors.spec.js @@ -1,12 +1,12 @@ -'use strict'; +"use strict"; -const forEachApi = require('../fixtures/for-each-api'); -const expect = require('chai').expect; +const forEachApi = require("../fixtures/for-each-api"); +const expect = require("chai").expect; -describe('error handling', () => { +describe("error handling", () => { forEachApi([ { - it: 'should throw an error if no arguments are passed', + it: "should throw an error if no arguments are passed", args: [], assert (error, data) { expect(error).to.be.an.instanceOf(TypeError); @@ -22,7 +22,7 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if the path is not a string', + it: "should throw an error if the path is not a string", args: [55555], assert (error, data) { expect(error).to.be.an.instanceOf(TypeError); @@ -38,11 +38,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if options are invalid', - args: ['test/dir', 'invalid options'], + it: "should throw an error if options are invalid", + args: ["test/dir", "invalid options"], assert (error, data) { expect(error).to.be.an.instanceOf(TypeError); - expect(error.message).to.equal('options must be an object'); + expect(error.message).to.equal("options must be an object"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -54,11 +54,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if options.deep is invalid', - args: ['test/dir', { deep: { foo: 'bar' }}], + it: "should throw an error if options.deep is invalid", + args: ["test/dir", { deep: { foo: "bar" }}], assert (error, data) { expect(error).to.be.an.instanceOf(TypeError); - expect(error.message).to.equal('options.deep must be a boolean, number, function, regular expression, or glob pattern'); + expect(error.message).to.equal("options.deep must be a boolean, number, function, regular expression, or glob pattern"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -70,11 +70,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if options.deep is negative', - args: ['test/dir', { deep: -5 }], + it: "should throw an error if options.deep is negative", + args: ["test/dir", { deep: -5 }], assert (error, data) { expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal('options.deep must be a positive number'); + expect(error.message).to.equal("options.deep must be a positive number"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -86,11 +86,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if options.deep is NaN', - args: ['test/dir', { deep: NaN }], + it: "should throw an error if options.deep is NaN", + args: ["test/dir", { deep: NaN }], assert (error, data) { expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal('options.deep must be a positive number'); + expect(error.message).to.equal("options.deep must be a positive number"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -102,11 +102,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if options.deep is not an integer', - args: ['test/dir', { deep: 5.4 }], + it: "should throw an error if options.deep is not an integer", + args: ["test/dir", { deep: 5.4 }], assert (error, data) { expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal('options.deep must be an integer'); + expect(error.message).to.equal("options.deep must be an integer"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -118,12 +118,12 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if options.filter is invalid', - args: ['test/dir', { filter: 12345 }], + it: "should throw an error if options.filter is invalid", + args: ["test/dir", { filter: 12345 }], assert (error, data) { expect(error).to.be.an.instanceOf(TypeError); expect(error.message).to.equal( - 'options.filter must be a function, regular expression, or glob pattern'); + "options.filter must be a function, regular expression, or glob pattern"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -135,11 +135,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if options.sep is invalid', - args: ['test/dir', { sep: 57 }], + it: "should throw an error if options.sep is invalid", + args: ["test/dir", { sep: 57 }], assert (error, data) { expect(error).to.be.an.instanceOf(TypeError); - expect(error.message).to.equal('options.sep must be a string'); + expect(error.message).to.equal("options.sep must be a string"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -151,11 +151,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if options.basePath is invalid', - args: ['test/dir', { basePath: 57 }], + it: "should throw an error if options.basePath is invalid", + args: ["test/dir", { basePath: 57 }], assert (error, data) { expect(error).to.be.an.instanceOf(TypeError); - expect(error.message).to.equal('options.basePath must be a string'); + expect(error.message).to.equal("options.basePath must be a string"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -167,11 +167,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if the directory does not exist', - args: ['test/dir/does-not-exist'], + it: "should throw an error if the directory does not exist", + args: ["test/dir/does-not-exist"], assert (error, data) { expect(error).to.be.an.instanceOf(Error); - expect(error.code).to.equal('ENOENT'); + expect(error.code).to.equal("ENOENT"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -183,11 +183,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if the path is not a directory', - args: ['test/dir/file.txt'], + it: "should throw an error if the path is not a directory", + args: ["test/dir/file.txt"], assert (error, data) { expect(error).to.be.an.instanceOf(Error); - expect(error.code).to.equal('ENOTDIR'); + expect(error.code).to.equal("ENOTDIR"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -199,11 +199,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if the path is a broken symlink', - args: ['test/dir/broken-dir-symlink'], + it: "should throw an error if the path is a broken symlink", + args: ["test/dir/broken-dir-symlink"], assert (error, data) { expect(error).to.be.an.instanceOf(Error); - expect(error.code).to.equal('ENOENT'); + expect(error.code).to.equal("ENOENT"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -215,11 +215,11 @@ describe('error handling', () => { }, }, { - it: 'should throw an error if `options.fs` is invalid', - args: ['test/dir', { fs: 'Hello, World' }], + it: "should throw an error if `options.fs` is invalid", + args: ["test/dir", { fs: "Hello, World" }], assert (error, data) { expect(error).to.be.an.instanceOf(TypeError); - expect(error.message).to.equal('options.fs must be an object'); + expect(error.message).to.equal("options.fs must be an object"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { diff --git a/test/specs/exports.spec.js b/test/specs/exports.spec.js index cbaf5d2..b92933f 100644 --- a/test/specs/exports.spec.js +++ b/test/specs/exports.spec.js @@ -1,100 +1,100 @@ -'use strict'; +"use strict"; -const expect = require('chai').expect; +const expect = require("chai").expect; -describe('exports', () => { - describe('Synchronous API', () => { - it('should export the `readdirSyncPath` function as `readdirSync`', done => { - const readdir = require('../../'); - expect(readdir.readdirSync).to.be.a('function'); - expect(readdir.readdirSync.name).to.equal('readdirSyncPath'); +describe("exports", () => { + describe("Synchronous API", () => { + it("should export the `readdirSyncPath` function as `readdirSync`", done => { + const readdir = require("../../"); + expect(readdir.readdirSync).to.be.a("function"); + expect(readdir.readdirSync.name).to.equal("readdirSyncPath"); done(); }); - it('should alias `readdirSyncPath` as `readdir.sync`', done => { - const readdir = require('../../'); - expect(readdir.sync).to.be.a('function'); + it("should alias `readdirSyncPath` as `readdir.sync`", done => { + const readdir = require("../../"); + expect(readdir.sync).to.be.a("function"); expect(readdir.sync).to.equal(readdir.readdirSync); done(); }); - it('should export the `readdirSyncStat` function', done => { - const readdir = require('../../'); - expect(readdir.readdirSyncStat).to.be.a('function'); - expect(readdir.readdirSyncStat.name).to.equal('readdirSyncStat'); + it("should export the `readdirSyncStat` function", done => { + const readdir = require("../../"); + expect(readdir.readdirSyncStat).to.be.a("function"); + expect(readdir.readdirSyncStat.name).to.equal("readdirSyncStat"); done(); }); - it('should alias `readdirSyncStat` as `readdir.sync.stat`', done => { - const readdir = require('../../'); - expect(readdir.sync.stat).to.be.a('function'); + it("should alias `readdirSyncStat` as `readdir.sync.stat`", done => { + const readdir = require("../../"); + expect(readdir.sync.stat).to.be.a("function"); expect(readdir.sync.stat).to.equal(readdir.readdirSyncStat); done(); }); }); - describe('Asynchronous API (callback/Promise)', () => { - it('should export the `readdirAsyncPath` function by default', done => { - const readdir = require('../../'); - expect(readdir).to.be.a('function'); - expect(readdir.name).to.equal('readdirAsyncPath'); + describe("Asynchronous API (callback/Promise)", () => { + it("should export the `readdirAsyncPath` function by default", done => { + const readdir = require("../../"); + expect(readdir).to.be.a("function"); + expect(readdir.name).to.equal("readdirAsyncPath"); done(); }); - it('should alias `readdirAsyncPath` as `readdir.readdirAync`', done => { - const readdir = require('../../'); - expect(readdir.readdirAsync).to.be.a('function'); + it("should alias `readdirAsyncPath` as `readdir.readdirAync`", done => { + const readdir = require("../../"); + expect(readdir.readdirAsync).to.be.a("function"); expect(readdir.readdirAsync).to.equal(readdir); done(); }); - it('should alias `readdirAsyncPath` as `readdir.async`', done => { - const readdir = require('../../'); - expect(readdir.async).to.be.a('function'); + it("should alias `readdirAsyncPath` as `readdir.async`", done => { + const readdir = require("../../"); + expect(readdir.async).to.be.a("function"); expect(readdir.async).to.equal(readdir); done(); }); - it('should export the `readdirAsyncStat` function', done => { - const readdir = require('../../'); - expect(readdir.readdirAsyncStat).to.be.a('function'); - expect(readdir.readdirAsyncStat.name).to.equal('readdirAsyncStat'); + it("should export the `readdirAsyncStat` function", done => { + const readdir = require("../../"); + expect(readdir.readdirAsyncStat).to.be.a("function"); + expect(readdir.readdirAsyncStat.name).to.equal("readdirAsyncStat"); done(); }); - it('should alias `readdirAsyncStat` as `readdir.async.stat`', done => { - const readdir = require('../../'); - expect(readdir.async.stat).to.be.a('function'); + it("should alias `readdirAsyncStat` as `readdir.async.stat`", done => { + const readdir = require("../../"); + expect(readdir.async.stat).to.be.a("function"); expect(readdir.async.stat).to.equal(readdir.readdirAsyncStat); done(); }); }); - describe('Asynchronous API (Stream/EventEmitter)', () => { - it('should export the `readdirStreamPath` function as `readdirStream`', done => { - const readdir = require('../../'); - expect(readdir.readdirStream).to.be.a('function'); - expect(readdir.readdirStream.name).to.equal('readdirStreamPath'); + describe("Asynchronous API (Stream/EventEmitter)", () => { + it("should export the `readdirStreamPath` function as `readdirStream`", done => { + const readdir = require("../../"); + expect(readdir.readdirStream).to.be.a("function"); + expect(readdir.readdirStream.name).to.equal("readdirStreamPath"); done(); }); - it('should alias `readdirStreamPath` as `readdir.stream`', done => { - const readdir = require('../../'); - expect(readdir.stream).to.be.a('function'); + it("should alias `readdirStreamPath` as `readdir.stream`", done => { + const readdir = require("../../"); + expect(readdir.stream).to.be.a("function"); expect(readdir.stream).to.equal(readdir.readdirStream); done(); }); - it('should export the `readdirStreamStat` function', done => { - const readdir = require('../../'); - expect(readdir.readdirStreamStat).to.be.a('function'); - expect(readdir.readdirStreamStat.name).to.equal('readdirStreamStat'); + it("should export the `readdirStreamStat` function", done => { + const readdir = require("../../"); + expect(readdir.readdirStreamStat).to.be.a("function"); + expect(readdir.readdirStreamStat.name).to.equal("readdirStreamStat"); done(); }); - it('should alias `readdirStreamStat` as `readdir.stream.stat`', done => { - const readdir = require('../../'); - expect(readdir.stream.stat).to.be.a('function'); + it("should alias `readdirStreamStat` as `readdir.stream.stat`", done => { + const readdir = require("../../"); + expect(readdir.stream.stat).to.be.a("function"); expect(readdir.stream.stat).to.equal(readdir.readdirStreamStat); done(); }); diff --git a/test/specs/filter.spec.js b/test/specs/filter.spec.js index 0a865a0..549dc69 100644 --- a/test/specs/filter.spec.js +++ b/test/specs/filter.spec.js @@ -1,36 +1,36 @@ -'use strict'; +"use strict"; -const forEachApi = require('../fixtures/for-each-api'); -const dir = require('../fixtures/dir'); -const expect = require('chai').expect; +const forEachApi = require("../fixtures/for-each-api"); +const dir = require("../fixtures/dir"); +const expect = require("chai").expect; -describe('options.filter', () => { +describe("options.filter", () => { forEachApi([ { - it: 'should return filtered top-level contents', - args: ['test/dir', { + it: "should return filtered top-level contents", + args: ["test/dir", { filter (stats) { - return stats.path.indexOf('empty') >= 0; + return stats.path.indexOf("empty") >= 0; } }], assert (error, data) { expect(error).to.be.null; - expect(data).to.have.same.members(['empty', 'empty.txt']); + expect(data).to.have.same.members(["empty", "empty.txt"]); }, streamAssert (errors, data, files, dirs, symlinks) { expect(errors).to.have.lengthOf(0); - expect(data).to.have.same.members(['empty', 'empty.txt']); - expect(files).to.have.same.members(['empty.txt']); - expect(dirs).to.have.same.members(['empty']); + expect(data).to.have.same.members(["empty", "empty.txt"]); + expect(files).to.have.same.members(["empty.txt"]); + expect(dirs).to.have.same.members(["empty"]); expect(symlinks).to.have.lengthOf(0); }, }, { - it: 'should return filtered deep contents', - args: ['test/dir', { + it: "should return filtered deep contents", + args: ["test/dir", { deep: true, filter (stats) { - return stats.path.indexOf('empty') >= 0; + return stats.path.indexOf("empty") >= 0; } }], assert (error, data) { @@ -46,8 +46,8 @@ describe('options.filter', () => { }, }, { - it: 'should filter by files', - args: ['test/dir', { + it: "should filter by files", + args: ["test/dir", { deep: true, filter (stats) { return stats.isFile(); @@ -66,8 +66,8 @@ describe('options.filter', () => { }, }, { - it: 'should filter by directories', - args: ['test/dir', { + it: "should filter by directories", + args: ["test/dir", { deep: true, filter (stats) { return stats.isDirectory(); @@ -86,8 +86,8 @@ describe('options.filter', () => { }, }, { - it: 'should filter by symlinks', - args: ['test/dir', { + it: "should filter by symlinks", + args: ["test/dir", { deep: true, filter (stats) { return stats.isSymbolicLink(); @@ -106,8 +106,8 @@ describe('options.filter', () => { }, }, { - it: 'should filter by a regular expression', - args: ['test/dir', { + it: "should filter by a regular expression", + args: ["test/dir", { filter: /.*empt[^aeiou]/, }], assert (error, data) { @@ -123,10 +123,10 @@ describe('options.filter', () => { }, }, { - it: 'should use appropriate path separators when filtering by a regular expression', - args: ['test/dir', { + it: "should use appropriate path separators when filtering by a regular expression", + args: ["test/dir", { deep: true, - sep: '\\', + sep: "\\", filter: /subdir\\[^\\]*\\.*\.txt/, }], assert (error, data) { @@ -142,9 +142,9 @@ describe('options.filter', () => { }, }, { - it: 'should filter by a glob pattern', - args: ['test/dir', { - filter: 'empty*' + it: "should filter by a glob pattern", + args: ["test/dir", { + filter: "empty*" }], assert (error, data) { expect(error).to.be.null; @@ -159,11 +159,11 @@ describe('options.filter', () => { }, }, { - it: 'should use POSIX paths when filtering by a glob pattern', - args: ['test/dir', { + it: "should use POSIX paths when filtering by a glob pattern", + args: ["test/dir", { deep: true, - sep: '\\', - filter: 'subdir/*/*.txt', + sep: "\\", + filter: "subdir/*/*.txt", }], assert (error, data) { expect(error).to.be.null; @@ -178,12 +178,12 @@ describe('options.filter', () => { }, }, { - it: 'should prepend a POSIX version of the basePath when filtering by a glob pattern', - args: ['test/dir', { + it: "should prepend a POSIX version of the basePath when filtering by a glob pattern", + args: ["test/dir", { deep: true, basePath: dir.windowsBasePath, - sep: '\\', - filter: '/Windows/**/subdir/*/*.txt', + sep: "\\", + filter: "/Windows/**/subdir/*/*.txt", }], assert (error, data) { expect(error).to.be.null; @@ -198,10 +198,10 @@ describe('options.filter', () => { }, }, { - it: 'should filter by a file extension pattern', - args: ['test/dir', { + it: "should filter by a file extension pattern", + args: ["test/dir", { deep: true, - filter: '**/*.txt', + filter: "**/*.txt", }], assert (error, data) { expect(error).to.be.null; @@ -216,11 +216,11 @@ describe('options.filter', () => { }, }, { - it: 'should handle errors that occur in the filter function', - args: ['test/dir', { + it: "should handle errors that occur in the filter function", + args: ["test/dir", { filter (stats) { if (stats.isSymbolicLink()) { - throw new Error('Boooooom!'); + throw new Error("Boooooom!"); } return true; } @@ -228,20 +228,20 @@ describe('options.filter', () => { assert (error, data) { // The sync & async APIs abort after the first error and don't return any data expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal('Boooooom!'); + expect(error.message).to.equal("Boooooom!"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { // The streaming API emits errors and data separately expect(errors).to.have.lengthOf(5); expect(data).to.have.same.members([ - '.dotdir', 'empty', 'subdir', '.dotfile', 'empty.txt', 'file.txt', 'file.json', + ".dotdir", "empty", "subdir", ".dotfile", "empty.txt", "file.txt", "file.json", ]); expect(files).to.have.same.members([ - '.dotfile', 'empty.txt', 'file.txt', 'file.json', + ".dotfile", "empty.txt", "file.txt", "file.json", ]); expect(dirs).to.have.same.members([ - '.dotdir', 'empty', 'subdir', + ".dotdir", "empty", "subdir", ]); expect(symlinks).to.have.lengthOf(0); }, diff --git a/test/specs/fs.spec.js b/test/specs/fs.spec.js index bca305d..7000abd 100644 --- a/test/specs/fs.spec.js +++ b/test/specs/fs.spec.js @@ -1,16 +1,16 @@ -'use strict'; +"use strict"; -const forEachApi = require('../fixtures/for-each-api'); -const dir = require('../fixtures/dir'); -const path = require('path'); -const fs = require('fs'); -const expect = require('chai').expect; +const forEachApi = require("../fixtures/for-each-api"); +const dir = require("../fixtures/dir"); +const path = require("path"); +const fs = require("fs"); +const expect = require("chai").expect; -describe('options.fs', () => { +describe("options.fs", () => { forEachApi([ { - it: 'should have no effect if `options.fs` is null', - args: ['test/dir', { fs: null }], + it: "should have no effect if `options.fs` is null", + args: ["test/dir", { fs: null }], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.shallow.data); @@ -24,8 +24,8 @@ describe('options.fs', () => { }, }, { - it: 'should have no effect if `options.fs` is empty', - args: ['test/dir', { fs: {}}], + it: "should have no effect if `options.fs` is empty", + args: ["test/dir", { fs: {}}], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.shallow.data); @@ -44,8 +44,8 @@ describe('options.fs', () => { * fs.readdir ************************************************************/ { - it: 'should use a custom `fs.readdir` method', - args: ['test/dir', { + it: "should use a custom `fs.readdir` method", + args: ["test/dir", { fs: { readdir (dirPath, callback) { callback(null, dir.txt.shallow.data); @@ -65,34 +65,34 @@ describe('options.fs', () => { }, }, { - it: 'should handle an invalid file name from a custom `fs.readdir` method', - args: ['test/dir', { + it: "should handle an invalid file name from a custom `fs.readdir` method", + args: ["test/dir", { deep: true, fs: { readdir (dirPath, callback) { - callback(null, ['empty.txt', 'invalid.txt', 'file.txt']); + callback(null, ["empty.txt", "invalid.txt", "file.txt"]); }, } }], assert (error, data) { // The sync & async APIs abort after the first error and don't return any data expect(error).to.be.an.instanceOf(Error); - expect(error.code).to.equal('ENOENT'); + expect(error.code).to.equal("ENOENT"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { // The streaming API emits errors and data separately expect(errors).to.have.lengthOf(1); - expect(errors[0].code).to.equal('ENOENT'); - expect(data).to.have.same.members(['empty.txt', 'file.txt']); - expect(files).to.have.same.members(['empty.txt', 'file.txt']); + expect(errors[0].code).to.equal("ENOENT"); + expect(data).to.have.same.members(["empty.txt", "file.txt"]); + expect(files).to.have.same.members(["empty.txt", "file.txt"]); expect(dirs).to.have.lengthOf(0); expect(symlinks).to.have.lengthOf(0); }, }, { - it: 'should handle a null result from a custom `fs.readdir` method', - args: ['test/dir', { + it: "should handle a null result from a custom `fs.readdir` method", + args: ["test/dir", { deep: true, fs: { readdir (dirPath, callback) { @@ -117,8 +117,8 @@ describe('options.fs', () => { }, }, { - it: 'should handle an invalid result from a custom `fs.readdir` method', - args: ['test/dir', { + it: "should handle an invalid result from a custom `fs.readdir` method", + args: ["test/dir", { deep: true, fs: { readdir (dirPath, callback) { @@ -129,13 +129,13 @@ describe('options.fs', () => { assert (error, data) { // The sync & async APIs abort after the first error and don't return any data expect(error).to.be.an.instanceOf(TypeError); - expect(error.message).to.equal('array.forEach is not a function'); + expect(error.message).to.equal("array.forEach is not a function"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { // The streaming API emits errors and data separately expect(errors).to.have.lengthOf(1); - expect(errors[0].message).to.equal('array.forEach is not a function'); + expect(errors[0].message).to.equal("array.forEach is not a function"); expect(data).to.have.lengthOf(0); expect(files).to.have.lengthOf(0); expect(dirs).to.have.lengthOf(0); @@ -143,14 +143,14 @@ describe('options.fs', () => { }, }, { - it: 'should handle an error from a custom `fs.readdir` method', - args: ['test/dir', { + it: "should handle an error from a custom `fs.readdir` method", + args: ["test/dir", { deep: true, fs: { readdir (dirPath, callback) { // Simulate a sporadic error - if (dirPath === dir.path('test/dir/subdir/subsubdir')) { - callback(new Error('Boooooom!')); + if (dirPath === dir.path("test/dir/subdir/subsubdir")) { + callback(new Error("Boooooom!")); } else { let files = fs.readdirSync(dirPath); @@ -162,7 +162,7 @@ describe('options.fs', () => { assert (error, data) { // The sync & async APIs abort after the first error and don't return any data expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal('Boooooom!'); + expect(error.message).to.equal("Boooooom!"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -177,19 +177,19 @@ describe('options.fs', () => { // Omits the contents of the "subsubdir" directory omitSubdir (paths) { return paths.filter(p => { - return p.substr(7, 10) !== 'subsubdir' + path.sep; + return p.substr(7, 10) !== "subsubdir" + path.sep; }); } }, { - it: 'should handle an error thrown by a custom `fs.readdir` method', - args: ['test/dir', { + it: "should handle an error thrown by a custom `fs.readdir` method", + args: ["test/dir", { deep: true, fs: { readdir (dirPath, callback) { // Simulate an error being thrown (rather than returned to the callback) - if (dirPath === dir.path('test/dir/subdir/subsubdir')) { - throw new Error('Boooooom!'); + if (dirPath === dir.path("test/dir/subdir/subsubdir")) { + throw new Error("Boooooom!"); } else { let files = fs.readdirSync(dirPath); @@ -201,7 +201,7 @@ describe('options.fs', () => { assert (error, data) { // The sync & async APIs abort after the first error and don't return any data expect(error).to.be.an.instanceOf(Error); - expect(error.message).to.equal('Boooooom!'); + expect(error.message).to.equal("Boooooom!"); expect(data).to.be.undefined; }, streamAssert (errors, data, files, dirs, symlinks) { @@ -216,7 +216,7 @@ describe('options.fs', () => { // Omits the contents of the "subsubdir" directory omitSubdir (paths) { return paths.filter(p => { - return p.substr(7, 10) !== 'subsubdir' + path.sep; + return p.substr(7, 10) !== "subsubdir" + path.sep; }); } }, @@ -226,8 +226,8 @@ describe('options.fs', () => { * fs.stat ************************************************************/ { - it: 'should use a custom `fs.stat` method', - args: ['test/dir', { + it: "should use a custom `fs.stat` method", + args: ["test/dir", { deep: true, fs: { stat (dirPath, callback) { @@ -257,17 +257,17 @@ describe('options.fs', () => { // Omits symlink directories omitSymlinks (files) { - return files.filter(file => !file.includes('symlink')); + return files.filter(file => !file.includes("symlink")); }, // Omits symlink directories omitSymlinkDirs (files) { - return files.filter(file => !file.includes('symlink' + path.sep)); + return files.filter(file => !file.includes("symlink" + path.sep)); }, }, { - it: 'should handle a null result from a custom `fs.stat` method', - args: ['test/dir', { + it: "should handle a null result from a custom `fs.stat` method", + args: ["test/dir", { deep: true, fs: { stat (dirPath, callback) { @@ -293,16 +293,16 @@ describe('options.fs', () => { // Omits symlinks omitSymlinks (files) { - return files.filter(file => !file.includes('symlink')); + return files.filter(file => !file.includes("symlink")); } }, { - it: 'should handle an invalid result from a custom `fs.stat` method', - args: ['test/dir', { + it: "should handle an invalid result from a custom `fs.stat` method", + args: ["test/dir", { deep: true, fs: { stat (dirPath, callback) { - callback(null, 'Hello, world'); + callback(null, "Hello, world"); }, } }], @@ -324,17 +324,17 @@ describe('options.fs', () => { // Omits symlinks omitSymlinks (files) { - return files.filter(file => !file.includes('symlink')); + return files.filter(file => !file.includes("symlink")); } }, { - it: 'should handle an error from a custom `fs.stat` method', - args: ['test/dir', { + it: "should handle an error from a custom `fs.stat` method", + args: ["test/dir", { fs: { stat (filePath, callback) { // Simulate a sporadic error - if (filePath === dir.path('test/dir/subsubdir-symlink')) { - callback(new Error('Boooooom!')); + if (filePath === dir.path("test/dir/subsubdir-symlink")) { + callback(new Error("Boooooom!")); } else { let stats = fs.statSync(filePath); @@ -353,19 +353,19 @@ describe('options.fs', () => { expect(data).to.have.same.members(dir.shallow.data); expect(files).to.have.same.members(dir.shallow.files); expect(dirs).to.have.same.members( - dir.shallow.dirs.filter(file => file !== 'subsubdir-symlink') + dir.shallow.dirs.filter(file => file !== "subsubdir-symlink") ); expect(symlinks).to.have.same.members(dir.shallow.symlinks); }, }, { - it: 'should handle an error thrown by a custom `fs.stat` method', - args: ['test/dir', { + it: "should handle an error thrown by a custom `fs.stat` method", + args: ["test/dir", { fs: { stat (filePath, callback) { // Simulate an error being thrown (rather than returned to the callback) - if (filePath === dir.path('test/dir/subsubdir-symlink')) { - throw new Error('Boooooom!'); + if (filePath === dir.path("test/dir/subsubdir-symlink")) { + throw new Error("Boooooom!"); } else { let stats = fs.statSync(filePath); @@ -384,7 +384,7 @@ describe('options.fs', () => { expect(data).to.have.same.members(dir.shallow.data); expect(files).to.have.same.members(dir.shallow.files); expect(dirs).to.have.same.members( - dir.shallow.dirs.filter(file => file !== 'subsubdir-symlink') + dir.shallow.dirs.filter(file => file !== "subsubdir-symlink") ); expect(symlinks).to.have.same.members(dir.shallow.symlinks); }, @@ -395,8 +395,8 @@ describe('options.fs', () => { * fs.lstat ************************************************************/ { - it: 'should use a custom `fs.lstat` method', - args: ['test/dir', { + it: "should use a custom `fs.lstat` method", + args: ["test/dir", { deep: true, fs: { lstat (dirPath, callback) { @@ -421,8 +421,8 @@ describe('options.fs', () => { }, }, { - it: 'should handle a null result from a custom `fs.lstat` method', - args: ['test/dir', { + it: "should handle a null result from a custom `fs.lstat` method", + args: ["test/dir", { deep: true, fs: { lstat (dirPath, callback) { @@ -447,12 +447,12 @@ describe('options.fs', () => { }, }, { - it: 'should handle an invalid result from a custom `fs.lstat` method', - args: ['test/dir', { + it: "should handle an invalid result from a custom `fs.lstat` method", + args: ["test/dir", { deep: true, fs: { lstat (dirPath, callback) { - callback(null, 'Hello, world'); + callback(null, "Hello, world"); }, } }], @@ -473,14 +473,14 @@ describe('options.fs', () => { }, }, { - it: 'should handle an error from a custom `fs.lstat` method', - args: ['test/dir', { + it: "should handle an error from a custom `fs.lstat` method", + args: ["test/dir", { deep: true, fs: { lstat (filePath, callback) { // Simulate a sporadic error - if (filePath === dir.path('test/dir/subsubdir-symlink')) { - callback(new Error('Boooooom!')); + if (filePath === dir.path("test/dir/subsubdir-symlink")) { + callback(new Error("Boooooom!")); } else { let lstats = fs.lstatSync(filePath); @@ -504,18 +504,18 @@ describe('options.fs', () => { // Omits the "subsubdir-symlink" directory and its children omitSubdirSymlink (files) { - return files.filter(file => !file.includes('subsubdir-symlink')); + return files.filter(file => !file.includes("subsubdir-symlink")); } }, { - it: 'should handle an error thrown by a custom `fs.lstat` method', - args: ['test/dir', { + it: "should handle an error thrown by a custom `fs.lstat` method", + args: ["test/dir", { deep: true, fs: { lstat (filePath, callback) { // Simulate an error being thrown (rather than returned to the callback) - if (filePath === dir.path('test/dir/subsubdir-symlink')) { - throw new Error('Boooooom!'); + if (filePath === dir.path("test/dir/subsubdir-symlink")) { + throw new Error("Boooooom!"); } else { let lstats = fs.lstatSync(filePath); @@ -539,7 +539,7 @@ describe('options.fs', () => { // Omits the "subsubdir-symlink" directory and its children omitSubdirSymlink (files) { - return files.filter(file => !file.includes('subsubdir-symlink')); + return files.filter(file => !file.includes("subsubdir-symlink")); } }, ]); diff --git a/test/specs/sep.spec.js b/test/specs/sep.spec.js index 9cbedfe..4e8e129 100644 --- a/test/specs/sep.spec.js +++ b/test/specs/sep.spec.js @@ -1,15 +1,15 @@ -'use strict'; +"use strict"; -const forEachApi = require('../fixtures/for-each-api'); -const dir = require('../fixtures/dir'); -const expect = require('chai').expect; -const path = require('path'); +const forEachApi = require("../fixtures/for-each-api"); +const dir = require("../fixtures/dir"); +const expect = require("chai").expect; +const path = require("path"); -describe('options.sep', () => { +describe("options.sep", () => { forEachApi([ { - it: 'should have no effect if `options.deep` is not set', - args: ['test/dir', { sep: '_' }], + it: "should have no effect if `options.deep` is not set", + args: ["test/dir", { sep: "_" }], assert (error, data) { expect(error).to.be.null; expect(data).to.have.same.members(dir.shallow.data); @@ -24,68 +24,68 @@ describe('options.sep', () => { }, { it: 'should return POSIX paths if sep === "/"', - args: ['test/dir', { deep: true, sep: '/' }], + args: ["test/dir", { deep: true, sep: "/" }], assert (error, data) { expect(error).to.be.null; - assertPathsMatch(data, dir.deep.data, '/'); + assertPathsMatch(data, dir.deep.data, "/"); }, streamAssert (errors, data, files, dirs, symlinks) { expect(errors).to.have.lengthOf(0); - assertPathsMatch(data, dir.deep.data, '/'); - assertPathsMatch(files, dir.deep.files, '/'); - assertPathsMatch(dirs, dir.deep.dirs, '/'); - assertPathsMatch(symlinks, dir.deep.symlinks, '/'); + assertPathsMatch(data, dir.deep.data, "/"); + assertPathsMatch(files, dir.deep.files, "/"); + assertPathsMatch(dirs, dir.deep.dirs, "/"); + assertPathsMatch(symlinks, dir.deep.symlinks, "/"); }, }, { it: 'should return Windows paths if sep === "\\"', - args: ['test/dir', { deep: true, sep: '\\' }], + args: ["test/dir", { deep: true, sep: "\\" }], assert (error, data) { expect(error).to.be.null; - assertPathsMatch(data, dir.deep.data, '\\'); + assertPathsMatch(data, dir.deep.data, "\\"); }, streamAssert (errors, data, files, dirs, symlinks) { expect(errors).to.have.lengthOf(0); - assertPathsMatch(data, dir.deep.data, '\\'); - assertPathsMatch(files, dir.deep.files, '\\'); - assertPathsMatch(dirs, dir.deep.dirs, '\\'); - assertPathsMatch(symlinks, dir.deep.symlinks, '\\'); + assertPathsMatch(data, dir.deep.data, "\\"); + assertPathsMatch(files, dir.deep.files, "\\"); + assertPathsMatch(dirs, dir.deep.dirs, "\\"); + assertPathsMatch(symlinks, dir.deep.symlinks, "\\"); }, }, { - it: 'should allow sep to be an empty string', - args: ['test/dir', { deep: true, sep: '' }], + it: "should allow sep to be an empty string", + args: ["test/dir", { deep: true, sep: "" }], assert (error, data) { expect(error).to.be.null; - assertPathsMatch(data, dir.deep.data, ''); + assertPathsMatch(data, dir.deep.data, ""); }, streamAssert (errors, data, files, dirs, symlinks) { expect(errors).to.have.lengthOf(0); - assertPathsMatch(data, dir.deep.data, ''); - assertPathsMatch(files, dir.deep.files, ''); - assertPathsMatch(dirs, dir.deep.dirs, ''); - assertPathsMatch(symlinks, dir.deep.symlinks, ''); + assertPathsMatch(data, dir.deep.data, ""); + assertPathsMatch(files, dir.deep.files, ""); + assertPathsMatch(dirs, dir.deep.dirs, ""); + assertPathsMatch(symlinks, dir.deep.symlinks, ""); }, }, { - it: 'should allow sep to be multiple characters', - args: ['test/dir', { deep: true, sep: '-----' }], + it: "should allow sep to be multiple characters", + args: ["test/dir", { deep: true, sep: "-----" }], assert (error, data) { expect(error).to.be.null; - assertPathsMatch(data, dir.deep.data, '-----'); + assertPathsMatch(data, dir.deep.data, "-----"); }, streamAssert (errors, data, files, dirs, symlinks) { expect(errors).to.have.lengthOf(0); - assertPathsMatch(data, dir.deep.data, '-----'); - assertPathsMatch(files, dir.deep.files, '-----'); - assertPathsMatch(dirs, dir.deep.dirs, '-----'); - assertPathsMatch(symlinks, dir.deep.symlinks, '-----'); + assertPathsMatch(data, dir.deep.data, "-----"); + assertPathsMatch(files, dir.deep.files, "-----"); + assertPathsMatch(dirs, dir.deep.dirs, "-----"); + assertPathsMatch(symlinks, dir.deep.symlinks, "-----"); }, }, ]); function assertPathsMatch (actual, expected, sep) { - let regExp = new RegExp('\\' + path.sep, 'g'); + let regExp = new RegExp("\\" + path.sep, "g"); let expectedPaths = expected.map(expectedPath => { return expectedPath.replace(regExp, sep); }); diff --git a/test/specs/stat.spec.js b/test/specs/stat.spec.js index d713400..601c235 100644 --- a/test/specs/stat.spec.js +++ b/test/specs/stat.spec.js @@ -1,46 +1,46 @@ -'use strict'; +"use strict"; -const readdir = require('../../'); -const dir = require('../fixtures/dir'); -const expect = require('chai').expect; -const fs = require('fs'); +const readdir = require("../../"); +const dir = require("../fixtures/dir"); +const expect = require("chai").expect; +const fs = require("fs"); -describe('fs.Stats', () => { - describe('Synchronous API', () => { - it('should return stats instead of paths', done => { - let data = readdir.sync.stat('test/dir'); +describe("fs.Stats", () => { + describe("Synchronous API", () => { + it("should return stats instead of paths", done => { + let data = readdir.sync.stat("test/dir"); assertStats(data, dir.shallow.data, done); }); }); - describe('Asynchronous API (callback/Promise)', () => { - it('should return stats instead of paths', done => { - readdir.async.stat('test/dir', (err, data) => { + describe("Asynchronous API (callback/Promise)", () => { + it("should return stats instead of paths", done => { + readdir.async.stat("test/dir", (err, data) => { expect(err).to.be.null; assertStats(data, dir.shallow.data, done); }); }); }); - describe('Asynchronous API (Stream/EventEmitter)', () => { - it('should return stats instead of paths', done => { + describe("Asynchronous API (Stream/EventEmitter)", () => { + it("should return stats instead of paths", done => { let error, data = [], files = [], dirs = [], symlinks = []; - let stream = readdir.stream.stat('test/dir'); + let stream = readdir.stream.stat("test/dir"); - stream.on('error', done); - stream.on('data', dataInfo => { + stream.on("error", done); + stream.on("data", dataInfo => { data.push(dataInfo); }); - stream.on('file', fileInfo => { + stream.on("file", fileInfo => { files.push(fileInfo); }); - stream.on('directory', dirInfo => { + stream.on("directory", dirInfo => { dirs.push(dirInfo); }); - stream.on('symlink', symlinkInfo => { + stream.on("symlink", symlinkInfo => { symlinks.push(symlinkInfo); }); - stream.on('end', () => { + stream.on("end", () => { assertStats(data, dir.shallow.data, errorHandler); assertStats(files, dir.shallow.files, errorHandler); assertStats(dirs, dir.shallow.dirs, errorHandler); @@ -55,7 +55,7 @@ describe('fs.Stats', () => { function assertStats (data, expected, done) { try { // Should return an array of the correct length - expect(data).to.be.an('array').with.lengthOf(expected.length); + expect(data).to.be.an("array").with.lengthOf(expected.length); // Should return the expected paths let paths = data.map(stat => { return stat.path; }); @@ -63,16 +63,16 @@ describe('fs.Stats', () => { // Each item should be a valid fs.Stats object data.forEach(stat => { - expect(stat).to.be.an('object'); + expect(stat).to.be.an("object"); expect(stat).to.be.an.instanceOf(fs.Stats); - expect(stat.mode).to.be.a('number'); - expect(stat.uid).to.be.a('number'); - expect(stat.gid).to.be.a('number'); - expect(stat.size).to.be.a('number'); + expect(stat.mode).to.be.a("number"); + expect(stat.uid).to.be.a("number"); + expect(stat.gid).to.be.a("number"); + expect(stat.size).to.be.a("number"); expect(stat.atime).to.be.an.instanceOf(Date); expect(stat.mtime).to.be.an.instanceOf(Date); expect(stat.ctime).to.be.an.instanceOf(Date); - expect(stat.path).to.be.a('string'); + expect(stat.path).to.be.a("string"); }); done(); diff --git a/test/specs/stream.spec.js b/test/specs/stream.spec.js index 9c2a403..7917454 100644 --- a/test/specs/stream.spec.js +++ b/test/specs/stream.spec.js @@ -1,18 +1,18 @@ -'use strict'; +"use strict"; -const readdir = require('../../'); -const dir = require('../fixtures/dir'); -const expect = require('chai').expect; -const through2 = require('through2'); -const fs = require('fs'); +const readdir = require("../../"); +const dir = require("../fixtures/dir"); +const expect = require("chai").expect; +const through2 = require("through2"); +const fs = require("fs"); let nodeVersion = parseFloat(process.version.substr(1)); -describe('Stream API', () => { - it('should be able to pipe to other streams as a Buffer', done => { +describe("Stream API", () => { + it("should be able to pipe to other streams as a Buffer", done => { let allData = []; - readdir.stream('test/dir') + readdir.stream("test/dir") .pipe(through2((data, enc, next) => { try { // By default, the data is streamed as a Buffer @@ -27,7 +27,7 @@ describe('Stream API', () => { next(e); } })) - .on('finish', () => { + .on("finish", () => { try { expect(allData).to.have.same.members(dir.shallow.data); done(); @@ -36,7 +36,7 @@ describe('Stream API', () => { done(e); } }) - .on('error', err => { + .on("error", err => { done(err); }); }); @@ -44,11 +44,11 @@ describe('Stream API', () => { it('should be able to pipe to other streams in "object mode"', done => { let allData = []; - readdir.stream('test/dir') + readdir.stream("test/dir") .pipe(through2({ objectMode: true }, (data, enc, next) => { try { // In "object mode", the data is a string - expect(data).to.be.a('string'); + expect(data).to.be.a("string"); allData.push(data); next(null, data); @@ -57,7 +57,7 @@ describe('Stream API', () => { next(e); } })) - .on('finish', () => { + .on("finish", () => { try { expect(allData).to.have.same.members(dir.shallow.data); done(); @@ -66,7 +66,7 @@ describe('Stream API', () => { done(e); } }) - .on('error', err => { + .on("error", err => { done(err); }); }); @@ -74,11 +74,11 @@ describe('Stream API', () => { it('should be able to pipe fs.Stats to other streams in "object mode"', done => { let allData = []; - readdir.stream.stat('test/dir') + readdir.stream.stat("test/dir") .pipe(through2({ objectMode: true }, (data, enc, next) => { try { // The data is an fs.Stats object - expect(data).to.be.an('object'); + expect(data).to.be.an("object"); expect(data).to.be.an.instanceOf(fs.Stats); allData.push(data.path); @@ -88,7 +88,7 @@ describe('Stream API', () => { next(e); } })) - .on('finish', () => { + .on("finish", () => { try { expect(allData).to.have.same.members(dir.shallow.data); done(); @@ -97,14 +97,14 @@ describe('Stream API', () => { done(e); } }) - .on('error', done); + .on("error", done); }); - it('should be able to pause & resume the stream', done => { + it("should be able to pause & resume the stream", done => { let allData = []; - let stream = readdir.stream('test/dir') - .on('data', data => { + let stream = readdir.stream("test/dir") + .on("data", data => { allData.push(data); // The stream should not be paused @@ -130,19 +130,19 @@ describe('Stream API', () => { }, 1000); } }) - .on('end', () => { + .on("end", () => { expect(allData).to.have.same.members(dir.shallow.data); done(); }) - .on('error', done); + .on("error", done); }); it('should be able to use "readable" and "read"', done => { let allData = []; let nullCount = 0; - let stream = readdir.stream('test/dir') - .on('readable', () => { + let stream = readdir.stream("test/dir") + .on("readable", () => { // Manually read the next chunk of data let data = stream.read(); @@ -154,14 +154,14 @@ describe('Stream API', () => { } else { // The data should be a string (the file name) - expect(data).to.be.a('string').and.not.empty; + expect(data).to.be.a("string").and.not.empty; allData.push(data); data = stream.read(); } } }) - .on('end', () => { + .on("end", () => { if (nodeVersion >= 10) { // In Node >= 10, the "readable" event only fires once, // and stream.read() only returns null once @@ -176,77 +176,77 @@ describe('Stream API', () => { expect(allData).to.have.same.members(dir.shallow.data); done(); }) - .on('error', done); + .on("error", done); }); it('should be able to subscribe to custom events instead of "data"', done => { let allFiles = []; let allSubdirs = []; - let stream = readdir.stream('test/dir'); + let stream = readdir.stream("test/dir"); // Calling "resume" is required, since we're not handling the "data" event stream.resume(); stream - .on('file', filename => { - expect(filename).to.be.a('string').and.not.empty; + .on("file", filename => { + expect(filename).to.be.a("string").and.not.empty; allFiles.push(filename); }) - .on('directory', subdir => { - expect(subdir).to.be.a('string').and.not.empty; + .on("directory", subdir => { + expect(subdir).to.be.a("string").and.not.empty; allSubdirs.push(subdir); }) - .on('end', () => { + .on("end", () => { expect(allFiles).to.have.same.members(dir.shallow.files); expect(allSubdirs).to.have.same.members(dir.shallow.dirs); done(); }) - .on('error', done); + .on("error", done); }); it('should handle errors that occur in the "data" event listener', done => { - testErrorHandling('data', dir.shallow.data, 7, done); + testErrorHandling("data", dir.shallow.data, 7, done); }); it('should handle errors that occur in the "file" event listener', done => { - testErrorHandling('file', dir.shallow.files, 3, done); + testErrorHandling("file", dir.shallow.files, 3, done); }); it('should handle errors that occur in the "directory" event listener', done => { - testErrorHandling('directory', dir.shallow.dirs, 2, done); + testErrorHandling("directory", dir.shallow.dirs, 2, done); }); it('should handle errors that occur in the "symlink" event listener', done => { - testErrorHandling('symlink', dir.shallow.symlinks, 5, done); + testErrorHandling("symlink", dir.shallow.symlinks, 5, done); }); function testErrorHandling (eventName, expected, expectedErrors, done) { let errors = [], data = []; - let stream = readdir.stream('test/dir'); + let stream = readdir.stream("test/dir"); // Capture all errors - stream.on('error', error => { + stream.on("error", error => { errors.push(error); }); stream.on(eventName, path => { data.push(path); - if (path.indexOf('.txt') >= 0 || path.indexOf('dir-') >= 0) { - throw new Error('Epic Fail!!!'); + if (path.indexOf(".txt") >= 0 || path.indexOf("dir-") >= 0) { + throw new Error("Epic Fail!!!"); } else { return true; } }); - stream.on('end', () => { + stream.on("end", () => { try { // Make sure the correct number of errors were thrown expect(errors).to.have.lengthOf(expectedErrors); errors.forEach(error => { - expect(error.message).to.equal('Epic Fail!!!'); + expect(error.message).to.equal("Epic Fail!!!"); }); // All of the events should have still been emitted, despite the errors