diff --git a/README.md b/README.md
index a5fd5c20..c93657b3 100644
--- a/README.md
+++ b/README.md
@@ -103,11 +103,14 @@ Configuration from the home directory (`~`) and current working directory (`cwd`
Supported configurations properties:
-| Property | Description |
-|----------------|-------------|
-| description | Top-level description of the project/gulpfile (Replaces "Tasks for ~/path/of/gulpfile.js") |
-| flags.gulpfile | Set a default gulpfile |
-| flags.silent | Silence logging by default |
+| Property | Description |
+|--------------------|-------------|
+| description | Top-level description of the project/gulpfile (Replaces "Tasks for ~/path/of/gulpfile.js") |
+| flags.continue | Continue execution of tasks upon failure by default. |
+| flags.compactTasks | Reduce the output of task dependency tree by default. |
+| flags.tasksDepth | Set default depth of task dependency tree. |
+| flags.gulpfile | Set a default gulpfile |
+| flags.silent | Silence logging by default |
## Flags
@@ -159,11 +162,6 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp
-T |
Print the task dependency tree for the loaded gulpfile. |
-
- --depth [number] |
- |
- Specify the depth of the task dependency tree to print. |
-
--tasks-simple |
|
@@ -174,6 +172,21 @@ __Some flags only work with gulp 4 and will be ignored when invoked against gulp
|
Print the task dependency tree, in JSON format, for the loaded gulpfile. The [path] argument is optional, and if given writes the JSON to the path. |
+
+ --tasks-depth [number] |
+ |
+ Specify the depth of the task dependency tree to print. This flag can be used with --tasks or --tasks-json. (This flag was named --depth before but is deprecated.) |
+
+
+ --compact-tasks |
+ |
+ Reduce the output of task dependency tree by printing only top tasks and their child tasks. This flag can be used with --tasks or --tasks-json. |
+
+
+ --sort-tasks |
+ |
+ Will sort top tasks of task dependency tree. This flag can be used with --tasks. |
+
--color |
|
diff --git a/docs/CLI.md b/docs/CLI.md
index 9752e151..423452bf 100644
--- a/docs/CLI.md
+++ b/docs/CLI.md
@@ -59,6 +59,15 @@ gulp has very few flags to know about. All other flags are for tasks to use if n
**--tasks-json** [path]
Print the task dependency tree, in JSON format, for the loaded gulpfile. The [path] argument is optional, and if given writes the JSON to the path.
+**--tasks-depth** [number]
+ Specify the depth of the task dependency tree to print. This flag can be used with --tasks or --tasks-json. (This flag was named --depth before but is deprecated.)
+
+**--compact-tasks**
+ Reduce the output of task dependency tree by printing only top tasks and their child tasks. This flag can be used with --tasks or --tasks-json.
+
+**--sort-tasks**
+ Will sort top tasks of task dependency tree. This flag can be used with --tasks.
+
**--color**
Will force gulp and gulp plugins to display colors, even when no color support is detected.
diff --git a/lib/shared/cliOptions.js b/lib/shared/cliOptions.js
index d3aa9c4c..90eba586 100644
--- a/lib/shared/cliOptions.js
+++ b/lib/shared/cliOptions.js
@@ -47,12 +47,6 @@ module.exports = {
desc: chalk.gray(
'Print the task dependency tree for the loaded gulpfile.'),
},
- depth: {
- type: 'number',
- requiresArg: true,
- desc: chalk.gray(
- 'Specify the depth of the task dependency tree.'),
- },
'tasks-simple': {
type: 'boolean',
desc: chalk.gray(
@@ -63,6 +57,24 @@ module.exports = {
'Print the task dependency tree, ' +
'in JSON format, for the loaded gulpfile.'),
},
+ 'tasks-depth': {
+ alias: 'depth',
+ type: 'number',
+ requiresArg: true,
+ desc: chalk.gray(
+ 'Specify the depth of the task dependency tree.'),
+ },
+ 'compact-tasks': {
+ type: 'boolean',
+ desc: chalk.gray(
+ 'Reduce the output of task dependency tree by printing ' +
+ 'only top tasks and their child tasks.'),
+ },
+ 'sort-tasks': {
+ type: 'boolean',
+ desc: chalk.gray(
+ 'Will sort top tasks of task dependency tree.'),
+ },
color: {
type: 'boolean',
desc: chalk.gray(
diff --git a/lib/shared/config/cli-flags.js b/lib/shared/config/cli-flags.js
index d3ddedb0..02d1e0a3 100644
--- a/lib/shared/config/cli-flags.js
+++ b/lib/shared/config/cli-flags.js
@@ -6,6 +6,9 @@ var fromTo = {
'flags.silent': 'silent',
'flags.continue': 'continue',
'flags.logLevel': 'logLevel',
+ 'flags.compactTasks': 'compactTasks',
+ 'flags.tasksDepth': 'tasksDepth',
+ 'flags.sortTasks': 'sortTasks',
};
function mergeConfigToCliFlags(opt, config) {
diff --git a/lib/shared/is-array.js b/lib/shared/is-array.js
new file mode 100644
index 00000000..70373f16
--- /dev/null
+++ b/lib/shared/is-array.js
@@ -0,0 +1,7 @@
+'use strict';
+
+function isArray(val) {
+ return Array.isArray(val);
+}
+
+module.exports = isArray;
diff --git a/lib/shared/is-number.js b/lib/shared/is-number.js
new file mode 100644
index 00000000..061505c2
--- /dev/null
+++ b/lib/shared/is-number.js
@@ -0,0 +1,7 @@
+'use strict';
+
+function isNumber(val) {
+ return (typeof val === 'number');
+}
+
+module.exports = isNumber;
diff --git a/lib/shared/log/copy-tree.js b/lib/shared/log/copy-tree.js
new file mode 100644
index 00000000..e32ff90d
--- /dev/null
+++ b/lib/shared/log/copy-tree.js
@@ -0,0 +1,84 @@
+'use strict';
+
+var isArray = require('../is-array');
+var isNumber = require('../is-number');
+
+function copyNode(node) {
+ var newNode = {};
+ Object.keys(node).forEach(function(key) {
+ newNode[key] = node[key];
+ });
+ return newNode;
+}
+
+var defaultNodeFactory = {
+ topNode: copyNode,
+ taskNode: copyNode,
+ childNode: copyNode,
+};
+
+function copyTree(tree, opts, nodeFactory) {
+ opts = opts || {};
+
+ var depth = opts.tasksDepth;
+ depth = !isNumber(depth) ? null : ((depth < 1) ? 1 : depth);
+
+ nodeFactory = nodeFactory || defaultNodeFactory;
+
+ var newTree = nodeFactory.topNode(tree);
+ newTree.nodes = [];
+
+ if (isArray(tree.nodes)) {
+ tree.nodes.forEach(visit);
+ }
+
+ function visit(node) {
+ var newNode = nodeFactory.taskNode(node);
+ newNode.nodes = [];
+ newTree.nodes.push(newNode);
+
+ if (opts.compactTasks) {
+ forEach(node.nodes, copyNotRecursively, newNode);
+
+ } else if (!depth || depth > 1) {
+ forEach(node.nodes, copyRecursively, depth, 2, newNode);
+ }
+ }
+
+ function copyNotRecursively(child, newParent) {
+ var newChild = nodeFactory.childNode(child);
+ newChild.nodes = [];
+ newParent.nodes.push(newChild);
+
+ if (child.branch) {
+ forEach(child.nodes, copyNotRecursively, newChild);
+ }
+ }
+
+ function copyRecursively(child, maxDepth, nowDepth, newParent) {
+ var newChild = nodeFactory.childNode(child);
+ newChild.nodes = [];
+ newParent.nodes.push(newChild);
+
+ if (!maxDepth || maxDepth > nowDepth) {
+ forEach(child.nodes, copyRecursively, maxDepth, nowDepth + 1, newChild);
+ }
+ }
+
+ return newTree;
+}
+
+function forEach(nodes, fn) {
+ if (!isArray(nodes)) {
+ return;
+ }
+
+ var args = Array.prototype.slice.call(arguments, 2);
+
+ for (var i = 0, n = nodes.length; i < n; i++) {
+ fn.apply(nodes[i], [nodes[i]].concat(args));
+ }
+}
+
+module.exports = copyTree;
+
diff --git a/lib/shared/log/tasks.js b/lib/shared/log/tasks.js
index b938bcf9..3e4a7c91 100644
--- a/lib/shared/log/tasks.js
+++ b/lib/shared/log/tasks.js
@@ -6,17 +6,24 @@ var log = require('gulplog');
var sortBy = require('lodash.sortby');
var isObject = require('lodash.isplainobject');
-
var isString = require('../is-string');
-function logTasks(tree, depth, getTask) {
- depth = (typeof depth !== 'number') ? null : ((depth < 1) ? 1 : depth);
+var copyTree = require('./copy-tree');
+
+function sorter(node) {
+ return node.label;
+}
+
+function logTasks(tree, opts, getTask) {
+ if (opts.sortTasks) {
+ tree.nodes = sortBy(tree.nodes, sorter);
+ }
var lineInfos = [];
var entryObserver = getLineInfoCollector(lineInfos);
+ var nodeFactory = getNodeFactory(getTask, entryObserver);
- tree = copyTree(tree, depth, getTask, entryObserver);
-
+ tree = copyTree(tree, opts, nodeFactory);
var spacer = getSpacerForLineIndents(tree, lineInfos);
var lines = getLinesContainingOnlyBranches(tree);
@@ -49,75 +56,52 @@ function getLineInfoCollector(lineInfos) {
};
}
-function copyTree(tree, depth, getTask, entryObserver) {
- var newTree = {
- label: tree.label,
- nodes: [],
- };
-
- sortBy(tree.nodes, sorter).forEach(visit);
-
- function sorter(node) {
- return node.label;
- }
+function getNodeFactory(getTask, entryObserver) {
+ return {
+ topNode: function(node) {
+ return {
+ label: node.label,
+ };
+ },
- function visit(node) {
- var task = getTask(node.label) || {};
-
- var newNode = {
- label: node.label,
- desc: isString(task.description) ? task.description : '',
- opts: [],
- nodes: [],
- };
- entryObserver.topTask(newNode);
- newTree.nodes.push(newNode);
-
- if (isObject(task.flags)) {
- Object.keys(task.flags).sort().forEach(function(flag) {
- if (flag.length === 0) {
- return;
- }
- var opt = {
- label: flag,
- desc: isString(task.flags[flag]) ? task.flags[flag] : '',
- };
- entryObserver.option(opt);
- newNode.opts.push(opt);
- newNode.label += '\n' + opt.label; // The way of archy for options.
- });
- }
+ taskNode: function(node) {
+ var task = getTask(node.label) || {};
- if (!depth || depth > 1) {
- var fn = function(child, maxDepth, nowDepth, newParent) {
- var newChild = {
- label: child.label,
- nodes: [],
- };
- entryObserver.childTask(newChild);
- newChild.label = ''; // Because don't use child tasks to calc indents.
- newParent.nodes.push(newChild);
- if (!maxDepth || maxDepth > nowDepth) {
- forEachNode(child.nodes, fn, maxDepth, nowDepth + 1, newChild);
- }
+ var newNode = {
+ label: node.label,
+ desc: isString(task.description) ? task.description : '',
+ opts: [],
};
- forEachNode(node.nodes, fn, depth, 2, newNode);
- }
- }
-
- return newTree;
-}
+ entryObserver.topTask(newNode);
+
+ if (isObject(task.flags)) {
+ Object.keys(task.flags).sort().forEach(function(flag) {
+ if (flag.length === 0) {
+ return;
+ }
+ var opt = {
+ label: flag,
+ desc: isString(task.flags[flag]) ? task.flags[flag] : '',
+ };
+ entryObserver.option(opt);
+ newNode.opts.push(opt);
+ newNode.label += '\n' + opt.label; // The way of archy for options.
+ });
+ }
-function forEachNode(nodes, fn) {
- if (!Array.isArray(nodes)) {
- return;
- }
+ return newNode;
+ },
- var args = [].slice.call(arguments, 2);
+ childNode: function(node) {
+ var newChild = {
+ label: node.label,
+ };
+ entryObserver.childTask(newChild);
+ newChild.label = ''; // Because don't use child tasks to calc indents.
- for (var i = 0, n = nodes.length; i < n; i++) {
- fn.apply(nodes[i], [nodes[i]].concat(args));
- }
+ return newChild;
+ },
+ };
}
function getSpacerForLineIndents(tree, lineInfos) {
diff --git a/lib/versioned/^3.7.0/index.js b/lib/versioned/^3.7.0/index.js
index bca1d402..6e3eda7e 100644
--- a/lib/versioned/^3.7.0/index.js
+++ b/lib/versioned/^3.7.0/index.js
@@ -6,6 +6,7 @@ var stdout = require('mute-stdout');
var tildify = require('tildify');
var taskTree = require('./taskTree');
+
var logTasks = require('../../shared/log/tasks');
var isString = require('../../shared/is-string');
var logEvents = require('./log/events');
@@ -34,17 +35,19 @@ function execute(opts, env, config) {
stdout.unmute();
process.nextTick(function() {
+ var tree;
+
if (opts.tasksSimple) {
return logTasksSimple(env, gulpInst);
}
if (opts.tasks) {
- var tree = taskTree(gulpInst.tasks);
+ tree = taskTree(gulpInst.tasks);
if (config.description && isString(config.description)) {
tree.label = config.description;
} else {
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
}
- return logTasks(tree, opts.depth, function(task) {
+ return logTasks(tree, opts, function(task) {
return gulpInst.tasks[task].fn;
});
}
diff --git a/lib/versioned/^4.0.0-alpha.1/index.js b/lib/versioned/^4.0.0-alpha.1/index.js
index c47f3efa..3b3aa0f1 100644
--- a/lib/versioned/^4.0.0-alpha.1/index.js
+++ b/lib/versioned/^4.0.0-alpha.1/index.js
@@ -16,6 +16,8 @@ var logSyncTask = require('../^4.0.0/log/syncTask');
var logTasksSimple = require('../^4.0.0/log/tasksSimple');
var registerExports = require('../../shared/registerExports');
+var copyTree = require('../../shared/log/copy-tree');
+
function execute(opts, env, config) {
var tasks = opts._;
@@ -39,23 +41,33 @@ function execute(opts, env, config) {
stdout.unmute();
process.nextTick(function() {
+ var tree;
+
if (opts.tasksSimple) {
return logTasksSimple(gulpInst.tree());
}
if (opts.tasks) {
- var tree = {};
+ tree = {};
if (config.description && isString(config.description)) {
tree.label = config.description;
} else {
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
}
tree.nodes = gulpInst.tree({ deep: true });
- return logTasks(tree, opts.depth, function(taskname) {
+ return logTasks(tree, opts, function(taskname) {
return gulpInst.task(taskname);
});
}
if (opts.tasksJson) {
- var output = JSON.stringify(gulpInst.tree({ deep: true }));
+ tree = {};
+ if (config.description && isString(config.description)) {
+ tree.label = config.description;
+ } else {
+ tree.label = 'Tasks for ' + tildify(env.configPath);
+ }
+ tree.nodes = gulpInst.tree({ deep: true });
+
+ var output = JSON.stringify(copyTree(tree, opts));
if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) {
return console.log(output);
}
diff --git a/lib/versioned/^4.0.0-alpha.2/index.js b/lib/versioned/^4.0.0-alpha.2/index.js
index 987c07a6..aba74979 100644
--- a/lib/versioned/^4.0.0-alpha.2/index.js
+++ b/lib/versioned/^4.0.0-alpha.2/index.js
@@ -16,6 +16,7 @@ var logSyncTask = require('../^4.0.0/log/syncTask');
var logTasksSimple = require('../^4.0.0/log/tasksSimple');
var registerExports = require('../../shared/registerExports');
+var copyTree = require('../../shared/log/copy-tree');
var getTask = require('../^4.0.0/log/getTask');
function execute(opts, env, config) {
@@ -55,7 +56,7 @@ function execute(opts, env, config) {
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
}
- return logTasks(tree, opts.depth, getTask(gulpInst));
+ return logTasks(tree, opts, getTask(gulpInst));
}
if (opts.tasksJson) {
tree = gulpInst.tree({ deep: true });
@@ -65,7 +66,7 @@ function execute(opts, env, config) {
tree.label = 'Tasks for ' + tildify(env.configPath);
}
- var output = JSON.stringify(tree);
+ var output = JSON.stringify(copyTree(tree, opts));
if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) {
return console.log(output);
diff --git a/lib/versioned/^4.0.0/index.js b/lib/versioned/^4.0.0/index.js
index c34c431b..73c19c8b 100644
--- a/lib/versioned/^4.0.0/index.js
+++ b/lib/versioned/^4.0.0/index.js
@@ -16,6 +16,7 @@ var logSyncTask = require('./log/syncTask');
var logTasksSimple = require('./log/tasksSimple');
var registerExports = require('../../shared/registerExports');
+var copyTree = require('../../shared/log/copy-tree');
var getTask = require('./log/getTask');
function execute(opts, env, config) {
@@ -55,7 +56,7 @@ function execute(opts, env, config) {
tree.label = 'Tasks for ' + chalk.magenta(tildify(env.configPath));
}
- return logTasks(tree, opts.depth, getTask(gulpInst));
+ return logTasks(tree, opts, getTask(gulpInst));
}
if (opts.tasksJson) {
tree = gulpInst.tree({ deep: true });
@@ -65,7 +66,7 @@ function execute(opts, env, config) {
tree.label = 'Tasks for ' + tildify(env.configPath);
}
- var output = JSON.stringify(tree);
+ var output = JSON.stringify(copyTree(tree, opts));
if (typeof opts.tasksJson === 'boolean' && opts.tasksJson) {
return console.log(output);
diff --git a/test/config-flags-compactTasks.js b/test/config-flags-compactTasks.js
new file mode 100644
index 00000000..7019646a
--- /dev/null
+++ b/test/config-flags-compactTasks.js
@@ -0,0 +1,55 @@
+'use strict';
+
+var expect = require('expect');
+var path = require('path');
+var fs = require('fs');
+var skipLines = require('gulp-test-tools').skipLines;
+var eraseTime = require('gulp-test-tools').eraseTime;
+
+var fixturesDir = path.join(__dirname, 'fixtures/config');
+var expectedDir = path.join(__dirname, 'expected');
+var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir);
+
+describe ('config: flags.compactTasks', function() {
+
+ it('Should compact task lists when `flags.compactTasks` is true in .gulp.*',
+ function(done) {
+ runner
+ .chdir('flags/compactTasks/t')
+ .gulp('--tasks')
+ .run(cb);
+
+ function cb(err, stdout, stderr) {
+ var filepath = path.join(expectedDir, 'flags-tasks-compact.txt');
+ var expected = fs.readFileSync(filepath, 'utf-8');
+ expected = skipLines(expected, 1);
+
+ stdout = eraseTime(skipLines(stdout, 1));
+
+ expect(stdout).toEqual(expected);
+ expect(stderr).toEqual('');
+ done(err);
+ }
+ });
+
+ it('Should not compact task lists when `flags.compactTasks` is false in ' +
+ '.gulp.*', function(done) {
+ runner
+ .chdir('flags/compactTasks/f')
+ .gulp('--tasks')
+ .run(cb);
+
+ function cb(err, stdout, stderr) {
+ var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt');
+ var expected = fs.readFileSync(filepath, 'utf-8');
+ expected = skipLines(expected, 1);
+
+ stdout = eraseTime(skipLines(stdout, 1));
+
+ expect(stdout).toEqual(expected);
+ expect(stderr).toEqual('');
+ done(err);
+ }
+ });
+
+});
diff --git a/test/config-flags-sortTasks.js b/test/config-flags-sortTasks.js
new file mode 100644
index 00000000..1da46918
--- /dev/null
+++ b/test/config-flags-sortTasks.js
@@ -0,0 +1,55 @@
+'use strict';
+
+var expect = require('expect');
+var path = require('path');
+var fs = require('fs');
+var skipLines = require('gulp-test-tools').skipLines;
+var eraseTime = require('gulp-test-tools').eraseTime;
+
+var fixturesDir = path.join(__dirname, 'fixtures/config');
+var expectedDir = path.join(__dirname, 'expected');
+var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir);
+
+describe ('config: flags.sortTasks', function() {
+
+ it('Should sort top tasks in task list when `flags.sortTasks` is true in ' +
+ '.gulp.*', function(done) {
+ runner
+ .chdir('flags/sortTasks/t')
+ .gulp('--tasks')
+ .run(cb);
+
+ function cb(err, stdout, stderr) {
+ var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt');
+ var expected = fs.readFileSync(filepath, 'utf-8');
+ expected = skipLines(expected, 1);
+
+ stdout = eraseTime(skipLines(stdout, 1));
+
+ expect(stdout).toEqual(expected);
+ expect(stderr).toEqual('');
+ done(err);
+ }
+ });
+
+ it('Should sort top tasks in task list when `flags.sortTasks` is false in ' +
+ '.gulp.*', function(done) {
+ runner
+ .chdir('flags/sortTasks/f')
+ .gulp('--tasks')
+ .run(cb);
+
+ function cb(err, stdout, stderr) {
+ var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt');
+ var expected = fs.readFileSync(filepath, 'utf-8');
+ expected = skipLines(expected, 1);
+
+ stdout = eraseTime(skipLines(stdout, 1));
+
+ expect(stdout).toEqual(expected);
+ expect(stderr).toEqual('');
+ done(err);
+ }
+ });
+
+});
diff --git a/test/config-flags-tasksDepth.js b/test/config-flags-tasksDepth.js
new file mode 100644
index 00000000..90c7822f
--- /dev/null
+++ b/test/config-flags-tasksDepth.js
@@ -0,0 +1,35 @@
+'use strict';
+
+var expect = require('expect');
+var path = require('path');
+var fs = require('fs');
+var skipLines = require('gulp-test-tools').skipLines;
+var eraseTime = require('gulp-test-tools').eraseTime;
+
+var fixturesDir = path.join(__dirname, 'fixtures/config');
+var expectedDir = path.join(__dirname, 'expected');
+var runner = require('gulp-test-tools').gulpRunner().basedir(fixturesDir);
+
+describe ('config: flags.tasksDepth', function() {
+
+ it('Should limit depth of task list when `flags.tasksDepth` is ' +
+ 'specified', function(done) {
+ runner
+ .chdir('flags/tasksDepth')
+ .gulp('--tasks')
+ .run(cb);
+
+ function cb(err, stdout, stderr) {
+ var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt');
+ var expected = fs.readFileSync(filepath, 'utf-8');
+ expected = skipLines(expected, 1);
+
+ stdout = eraseTime(skipLines(stdout, 1));
+
+ expect(stdout).toEqual(expected);
+ expect(stderr).toEqual('');
+ done(err);
+ }
+ });
+
+});
diff --git a/test/expected/copy-tree/copy-tree-compact.json b/test/expected/copy-tree/copy-tree-compact.json
new file mode 100644
index 00000000..113473a4
--- /dev/null
+++ b/test/expected/copy-tree/copy-tree-compact.json
@@ -0,0 +1,70 @@
+{
+ "label": "Label of Top node",
+ "nodes": [
+ {
+ "label": "Label of node 1",
+ "branch": true,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1",
+ "branch": false,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.2",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 3",
+ "nodes": [
+ {
+ "label": "Label of node 3.1",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 3.2",
+ "nodes": []
+ }
+ ]
+ }
+ ]
+}
diff --git a/test/expected/copy-tree/copy-tree-depth-1.json b/test/expected/copy-tree/copy-tree-depth-1.json
new file mode 100644
index 00000000..1f10a3f7
--- /dev/null
+++ b/test/expected/copy-tree/copy-tree-depth-1.json
@@ -0,0 +1,19 @@
+{
+ "label": "Label of Top node",
+ "nodes": [
+ {
+ "label": "Label of node 1",
+ "branch": true,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2",
+ "branch": true,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 3",
+ "nodes": []
+ }
+ ]
+}
diff --git a/test/expected/copy-tree/copy-tree-depth-2.json b/test/expected/copy-tree/copy-tree-depth-2.json
new file mode 100644
index 00000000..a43b47f1
--- /dev/null
+++ b/test/expected/copy-tree/copy-tree-depth-2.json
@@ -0,0 +1,44 @@
+{
+ "label": "Label of Top node",
+ "nodes": [
+ {
+ "label": "Label of node 1",
+ "branch": true,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1",
+ "branch": false,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.2",
+ "branch": true,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 3",
+ "nodes": [
+ {
+ "label": "Label of node 3.1",
+ "branch": true,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 3.2",
+ "nodes": []
+ }
+ ]
+ }
+ ]
+}
diff --git a/test/expected/copy-tree/copy-tree-depth-3.json b/test/expected/copy-tree/copy-tree-depth-3.json
new file mode 100644
index 00000000..29e2acdc
--- /dev/null
+++ b/test/expected/copy-tree/copy-tree-depth-3.json
@@ -0,0 +1,96 @@
+{
+ "label": "Label of Top node",
+ "nodes": [
+ {
+ "label": "Label of node 1",
+ "branch": true,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1",
+ "branch": false,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.2",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 3",
+ "nodes": [
+ {
+ "label": "Label of node 3.1",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 3.2",
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
diff --git a/test/expected/copy-tree/copy-tree-depth-4.json b/test/expected/copy-tree/copy-tree-depth-4.json
new file mode 100644
index 00000000..acfb240c
--- /dev/null
+++ b/test/expected/copy-tree/copy-tree-depth-4.json
@@ -0,0 +1,106 @@
+{
+ "label": "Label of Top node",
+ "nodes": [
+ {
+ "label": "Label of node 1",
+ "branch": true,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1",
+ "branch": false,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.2",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 3",
+ "nodes": [
+ {
+ "label": "Label of node 3.1",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1.1",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 3.2",
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": [
+ {
+ "label": "Label of node 2.1.2.1",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
diff --git a/test/expected/flags-help.txt b/test/expected/flags-help.txt
index 009a10b6..fa313519 100644
--- a/test/expected/flags-help.txt
+++ b/test/expected/flags-help.txt
@@ -2,19 +2,21 @@
Usage: gulp [options] tasks
Options:
- --help, -h Show this help. [boolean]
- --version, -v Print the global and local gulp versions. [boolean]
- --require Will require a module before running the gulpfile. This is useful for transpilers but also has other applications. [string]
- --gulpfile Manually set path of gulpfile. Useful if you have multiple gulpfiles. This will set the CWD to the gulpfile directory as well. [string]
- --cwd Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here. [string]
- --verify Will verify plugins referenced in project's package.json against the plugins blacklist.
- --tasks, -T Print the task dependency tree for the loaded gulpfile. [boolean]
- --depth Specify the depth of the task dependency tree.
- --tasks-simple Print a plaintext list of tasks for the loaded gulpfile. [boolean]
- --tasks-json Print the task dependency tree, in JSON format, for the loaded gulpfile.
- --color Will force gulp and gulp plugins to display colors, even when no color support is detected. [boolean]
- --no-color Will force gulp and gulp plugins to not display colors, even when color support is detected. [boolean]
- --silent, -S Suppress all gulp logging. [boolean]
- --continue Continue execution of tasks upon failure. [boolean]
- --log-level, -L Set the loglevel. -L for least verbose and -LLLL for most verbose. -LLL is default. [count]
+ --help, -h Show this help. [boolean]
+ --version, -v Print the global and local gulp versions. [boolean]
+ --require Will require a module before running the gulpfile. This is useful for transpilers but also has other applications. [string]
+ --gulpfile Manually set path of gulpfile. Useful if you have multiple gulpfiles. This will set the CWD to the gulpfile directory as well. [string]
+ --cwd Manually set the CWD. The search for the gulpfile, as well as the relativity of all requires will be from here. [string]
+ --verify Will verify plugins referenced in project's package.json against the plugins blacklist.
+ --tasks, -T Print the task dependency tree for the loaded gulpfile. [boolean]
+ --tasks-simple Print a plaintext list of tasks for the loaded gulpfile. [boolean]
+ --tasks-json Print the task dependency tree, in JSON format, for the loaded gulpfile.
+ --tasks-depth, --depth Specify the depth of the task dependency tree.
+ --compact-tasks Reduce the output of task dependency tree by printing only top tasks and their child tasks. [boolean]
+ --sort-tasks Will sort top tasks of task dependency tree. [boolean]
+ --color Will force gulp and gulp plugins to display colors, even when no color support is detected. [boolean]
+ --no-color Will force gulp and gulp plugins to not display colors, even when color support is detected. [boolean]
+ --silent, -S Suppress all gulp logging. [boolean]
+ --continue Continue execution of tasks upon failure. [boolean]
+ --log-level, -L Set the loglevel. -L for least verbose and -LLLL for most verbose. -LLL is default. [count]
diff --git a/test/expected/flags-tasks-compact.txt b/test/expected/flags-tasks-compact.txt
new file mode 100644
index 00000000..45bc48d3
--- /dev/null
+++ b/test/expected/flags-tasks-compact.txt
@@ -0,0 +1,15 @@
+gulp-cli/test/fixtures/gulpfiles
+├─┬ taskC
+│ └─┬
+│ ├── func1
+│ └── func2
+├─┬ taskB
+│ └─┬
+│ ├── func3
+│ └── taskC
+└─┬ default
+ └─┬
+ ├── taskC
+ └─┬
+ ├── taskB
+ └── func4
diff --git a/test/expected/flags-tasks-depth4.txt b/test/expected/flags-tasks-depth4.txt
new file mode 100644
index 00000000..b1550ad5
--- /dev/null
+++ b/test/expected/flags-tasks-depth4.txt
@@ -0,0 +1,17 @@
+gulp-cli/test/fixtures/gulpfiles
+├─┬ taskC
+│ └─┬
+│ ├── func1
+│ └── func2
+├─┬ taskB
+│ └─┬
+│ ├── func3
+│ └─┬ taskC
+│ └──
+└─┬ default
+ └─┬
+ ├─┬ taskC
+ │ └──
+ └─┬
+ ├── taskB
+ └── func4
diff --git a/test/expected/flags-tasks-sorted.txt b/test/expected/flags-tasks-sorted.txt
new file mode 100644
index 00000000..65d61c0c
--- /dev/null
+++ b/test/expected/flags-tasks-sorted.txt
@@ -0,0 +1,27 @@
+gulp-cli/test/fixtures/gulpfiles
+├─┬ default
+│ └─┬
+│ ├─┬ taskC
+│ │ └─┬
+│ │ ├── func1
+│ │ └── func2
+│ └─┬
+│ ├─┬ taskB
+│ │ └─┬
+│ │ ├── func3
+│ │ └─┬ taskC
+│ │ └─┬
+│ │ ├── func1
+│ │ └── func2
+│ └── func4
+├─┬ taskB
+│ └─┬
+│ ├── func3
+│ └─┬ taskC
+│ └─┬
+│ ├── func1
+│ └── func2
+└─┬ taskC
+ └─┬
+ ├── func1
+ └── func2
diff --git a/test/expected/flags-tasks-unsorted.txt b/test/expected/flags-tasks-unsorted.txt
new file mode 100644
index 00000000..fe916931
--- /dev/null
+++ b/test/expected/flags-tasks-unsorted.txt
@@ -0,0 +1,27 @@
+gulp-cli/test/fixtures/gulpfiles
+├─┬ taskC
+│ └─┬
+│ ├── func1
+│ └── func2
+├─┬ taskB
+│ └─┬
+│ ├── func3
+│ └─┬ taskC
+│ └─┬
+│ ├── func1
+│ └── func2
+└─┬ default
+ └─┬
+ ├─┬ taskC
+ │ └─┬
+ │ ├── func1
+ │ └── func2
+ └─┬
+ ├─┬ taskB
+ │ └─┬
+ │ ├── func3
+ │ └─┬ taskC
+ │ └─┬
+ │ ├── func1
+ │ └── func2
+ └── func4
diff --git a/test/exports-as-tasks.js b/test/exports-as-tasks.js
index fdd2361a..708c9a52 100644
--- a/test/exports-as-tasks.js
+++ b/test/exports-as-tasks.js
@@ -15,17 +15,18 @@ describe('exports as tasks', function() {
it('prints the task list', function(done) {
runner({ verbose: false })
- .gulp('--tasks',
+ .gulp('--tasks', '--sort-tasks',
'--gulpfile ./test/fixtures/gulpfiles/gulpfile-exports.babel.js')
.run(cb);
function cb(err, stdout, stderr) {
+ expect(err).toEqual(null);
+ expect(stderr).toEqual('');
var filepath = path.join(expectedDir, 'tasks-as-exports.txt');
var expected = fs.readFileSync(filepath, 'utf-8');
- expect(stderr).toEqual('');
stdout = eraseTime(skipLines(stdout, 2));
expect(stdout).toEqual(expected);
- done();
+ done(err);
}
});
diff --git a/test/fixtures/config/flags/compactTasks/f/.gulp.js b/test/fixtures/config/flags/compactTasks/f/.gulp.js
new file mode 100644
index 00000000..53447e50
--- /dev/null
+++ b/test/fixtures/config/flags/compactTasks/f/.gulp.js
@@ -0,0 +1,8 @@
+'use strict';
+
+module.exports = {
+ flags: {
+ compactTasks: false,
+ gulpfile: '../../../../gulpfiles/gulpfile-4.js',
+ },
+};
diff --git a/test/fixtures/config/flags/compactTasks/t/.gulp.js b/test/fixtures/config/flags/compactTasks/t/.gulp.js
new file mode 100644
index 00000000..70c8de7d
--- /dev/null
+++ b/test/fixtures/config/flags/compactTasks/t/.gulp.js
@@ -0,0 +1,8 @@
+'use strict';
+
+module.exports = {
+ flags: {
+ compactTasks: true,
+ gulpfile: '../../../../gulpfiles/gulpfile-4.js',
+ },
+};
diff --git a/test/fixtures/config/flags/sortTasks/f/.gulp.json b/test/fixtures/config/flags/sortTasks/f/.gulp.json
new file mode 100644
index 00000000..ac703623
--- /dev/null
+++ b/test/fixtures/config/flags/sortTasks/f/.gulp.json
@@ -0,0 +1,6 @@
+{
+ "flags": {
+ "sortTasks": false,
+ "gulpfile": "../../../../gulpfiles/gulpfile-4.js"
+ }
+}
diff --git a/test/fixtures/config/flags/sortTasks/t/.gulp.json b/test/fixtures/config/flags/sortTasks/t/.gulp.json
new file mode 100644
index 00000000..7e801098
--- /dev/null
+++ b/test/fixtures/config/flags/sortTasks/t/.gulp.json
@@ -0,0 +1,6 @@
+{
+ "flags": {
+ "sortTasks": true,
+ "gulpfile": "../../../../gulpfiles/gulpfile-4.js"
+ }
+}
diff --git a/test/fixtures/config/flags/tasksDepth/.gulp.json b/test/fixtures/config/flags/tasksDepth/.gulp.json
new file mode 100644
index 00000000..5a9da057
--- /dev/null
+++ b/test/fixtures/config/flags/tasksDepth/.gulp.json
@@ -0,0 +1,6 @@
+{
+ "flags": {
+ "tasksDepth": 4,
+ "gulpfile": "../../../gulpfiles/gulpfile-4.js"
+ }
+}
diff --git a/test/fixtures/copy-tree.json b/test/fixtures/copy-tree.json
new file mode 100644
index 00000000..acfb240c
--- /dev/null
+++ b/test/fixtures/copy-tree.json
@@ -0,0 +1,106 @@
+{
+ "label": "Label of Top node",
+ "nodes": [
+ {
+ "label": "Label of node 1",
+ "branch": true,
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1",
+ "branch": false,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.2",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 3",
+ "nodes": [
+ {
+ "label": "Label of node 3.1",
+ "branch": true,
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1.1",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 3.2",
+ "nodes": [
+ {
+ "label": "Label of node 2.1.1",
+ "nodes": []
+ },
+ {
+ "label": "Label of node 2.1.2",
+ "nodes": [
+ {
+ "label": "Label of node 2.1.2.1",
+ "nodes": []
+ }
+ ]
+ },
+ {
+ "label": "Label of node 2.1.3",
+ "nodes": []
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
diff --git a/test/fixtures/gulpfiles/gulpfile-4.js b/test/fixtures/gulpfiles/gulpfile-4.js
new file mode 100644
index 00000000..79ab3653
--- /dev/null
+++ b/test/fixtures/gulpfiles/gulpfile-4.js
@@ -0,0 +1,26 @@
+'use strict';
+
+var gulp = require('gulp');
+
+function func1(done) {
+ done();
+}
+
+function func2(done) {
+ done();
+}
+
+function func3(done) {
+ done();
+}
+
+function func4(done) {
+ done();
+}
+
+gulp.task('taskC', gulp.series(func1, func2));
+
+gulp.task('taskB', gulp.parallel(func3, 'taskC'));
+
+gulp.task('default', gulp.parallel('taskC', gulp.series('taskB', func4)));
+
diff --git a/test/flags-tasks-json.js b/test/flags-tasks-json.js
index 5acb681c..80c986ce 100644
--- a/test/flags-tasks-json.js
+++ b/test/flags-tasks-json.js
@@ -20,7 +20,7 @@ describe('flag: --tasks-json', function() {
expect(stderr).toEqual('');
stdout = skipLines(stdout, 1);
expect(JSON.parse(stdout)).toEqual(expected);
- done();
+ done(err);
}
});
diff --git a/test/flags-tasks.js b/test/flags-tasks.js
index feaa4d42..10662cc1 100644
--- a/test/flags-tasks.js
+++ b/test/flags-tasks.js
@@ -13,7 +13,7 @@ describe('flag: --tasks', function() {
it('prints the task list', function(done) {
runner({ verbose: false })
- .gulp('--tasks --cwd ./test/fixtures/gulpfiles')
+ .gulp('--tasks --sort-tasks --cwd ./test/fixtures/gulpfiles')
.run(cb);
function cb(err, stdout, stderr) {
@@ -23,13 +23,13 @@ describe('flag: --tasks', function() {
var expected = fs.readFileSync(filepath, 'utf-8');
stdout = eraseTime(skipLines(stdout, 1));
expect(stdout).toEqual(expected);
- done();
+ done(err);
}
});
it('print the task list with description and flags', function(done) {
runner({ verbose: false })
- .gulp('--tasks',
+ .gulp('--tasks', '--sort-tasks',
'--gulpfile ./test/fixtures/gulpfiles/with-desc-and-flags.js',
'--cwd ./test/fixtures')
.run(cb);
@@ -41,14 +41,14 @@ describe('flag: --tasks', function() {
var expected = fs.readFileSync(filepath, 'utf-8');
stdout = eraseTime(skipLines(stdout, 1));
expect(stdout).toEqual(expected);
- done();
+ done(err);
}
});
it('print the task list by gulp.task(s).unwrap and gulp.task(s)',
function(done) {
runner({ verbose: false })
- .gulp('--tasks',
+ .gulp('--tasks', '--sort-tasks',
'--gulpfile ./test/fixtures/gulpfiles/by-unwrap-and-not-by-unwrap.js',
'--cwd ./test/fixtures')
.run(cb);
@@ -60,7 +60,91 @@ describe('flag: --tasks', function() {
var expected = fs.readFileSync(filepath, 'utf-8');
stdout = eraseTime(skipLines(stdout, 1));
expect(stdout).toEqual(expected);
- done();
+ done(err);
+ }
+ });
+
+ it('prints the task list without --sort-tasks flag', function(done) {
+ runner({ verbose: false })
+ .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js')
+ .run(cb);
+
+ function cb(err, stdout, stderr) {
+ expect(err).toEqual(null);
+ expect(stderr).toEqual('');
+ var filepath = path.join(expectedDir, 'flags-tasks-unsorted.txt');
+ var expected = fs.readFileSync(filepath, 'utf-8');
+ stdout = eraseTime(skipLines(stdout, 1));
+ expect(stdout).toEqual(expected);
+ done(err);
+ }
+ });
+
+ it('prints the task list with --sort-tasks flag', function(done) {
+ runner({ verbose: false })
+ .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js',
+ '--sort-tasks')
+ .run(cb);
+
+ function cb(err, stdout, stderr) {
+ expect(err).toEqual(null);
+ expect(stderr).toEqual('');
+ var filepath = path.join(expectedDir, 'flags-tasks-sorted.txt');
+ var expected = fs.readFileSync(filepath, 'utf-8');
+ stdout = eraseTime(skipLines(stdout, 1));
+ expect(stdout).toEqual(expected);
+ done(err);
+ }
+ });
+
+ it('prints the task list with --tasks-depth flag', function(done) {
+ runner({ verbose: false })
+ .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js',
+ '--tasks-depth 4')
+ .run(cb);
+
+ function cb(err, stdout, stderr) {
+ expect(err).toEqual(null);
+ expect(stderr).toEqual('');
+ var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt');
+ var expected = fs.readFileSync(filepath, 'utf-8');
+ stdout = eraseTime(skipLines(stdout, 1));
+ expect(stdout).toEqual(expected);
+ done(err);
+ }
+ });
+
+ it('prints the task list with --depth flag', function(done) {
+ runner({ verbose: false })
+ .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js',
+ '--depth 4')
+ .run(cb);
+
+ function cb(err, stdout, stderr) {
+ expect(err).toEqual(null);
+ expect(stderr).toEqual('');
+ var filepath = path.join(expectedDir, 'flags-tasks-depth4.txt');
+ var expected = fs.readFileSync(filepath, 'utf-8');
+ stdout = eraseTime(skipLines(stdout, 1));
+ expect(stdout).toEqual(expected);
+ done(err);
+ }
+ });
+
+ it('prints the task list with --compact-tasks flag', function(done) {
+ runner({ verbose: false })
+ .gulp('--tasks --gulpfile ./test/fixtures/gulpfiles/gulpfile-4.js',
+ '--compact-tasks')
+ .run(cb);
+
+ function cb(err, stdout, stderr) {
+ expect(err).toEqual(null);
+ expect(stderr).toEqual('');
+ var filepath = path.join(expectedDir, 'flags-tasks-compact.txt');
+ var expected = fs.readFileSync(filepath, 'utf-8');
+ stdout = eraseTime(skipLines(stdout, 1));
+ expect(stdout).toEqual(expected);
+ done(err);
}
});
diff --git a/test/flags-version.js b/test/flags-version.js
index 7ec25ed7..f768f8bb 100644
--- a/test/flags-version.js
+++ b/test/flags-version.js
@@ -15,6 +15,7 @@ describe('flag: --version', function() {
.run(cb);
function cb(err, stdout, stderr) {
+ expect(err).toEqual(null);
expect(stderr).toEqual('');
stdout = eraseTime(stdout);
expect(stdout).toEqual(
diff --git a/test/lib/log-copy-tree.js b/test/lib/log-copy-tree.js
new file mode 100644
index 00000000..ab646443
--- /dev/null
+++ b/test/lib/log-copy-tree.js
@@ -0,0 +1,195 @@
+'use strict';
+
+var expect = require('expect');
+var copyTree = require('../../lib/shared/log/copy-tree');
+
+describe('lib: copy-tree', function() {
+
+ var nonConvertingNodeFactory = {
+ topNode: copyNode,
+ taskNode: copyNode,
+ childNode: copyNode,
+ };
+
+ it('Should copy an empty tree', function(done) {
+ var srcTree = {};
+ var opts = {};
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual({ nodes: [] });
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy a tree having empty nodes', function(done) {
+ var srcTree = {
+ nodes: [
+ {},
+ { nodes: [] },
+ { nodes: [{}, {}] },
+ ],
+ };
+ var opts = {};
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual({
+ nodes: [
+ { nodes: [] },
+ { nodes: [] },
+ {
+ nodes: [
+ { nodes: [] },
+ { nodes: [] },
+ ],
+ },
+ ],
+ });
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy a tree', function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var opts = {};
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(srcTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy with no nodeFactory', function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var opts = {};
+ var newTree = copyTree(srcTree, opts);
+ expect(newTree).toEqual(srcTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy with no opts and no nodeFactory', function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var newTree = copyTree(srcTree);
+ expect(newTree).toEqual(srcTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ describe('opts.tasksDepth', function() {
+
+ it('Should copy a tree until depth 1 if the specified depth is 0',
+ function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var expectedTree = require('../expected/copy-tree/copy-tree-depth-1');
+ var opts = { tasksDepth: 0 };
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(expectedTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy a tree until depth 1 if the specified depth is 1',
+ function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var expectedTree = require('../expected/copy-tree/copy-tree-depth-1');
+ var opts = { tasksDepth: 1 };
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(expectedTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy a tree until depth 2 if the specified depth is 2',
+ function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var expectedTree = require('../expected/copy-tree/copy-tree-depth-2');
+ var opts = { tasksDepth: 2 };
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(expectedTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy a tree until depth 3 if the specified depth is 3',
+ function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var expectedTree = require('../expected/copy-tree/copy-tree-depth-3');
+ var opts = { tasksDepth: 3 };
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(expectedTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy a tree until depth 3 if the specified depth is 4',
+ function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var expectedTree = require('../expected/copy-tree/copy-tree-depth-4');
+ var opts = { tasksDepth: 4 };
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(expectedTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy a full depth tree if the specified depth is too large',
+ function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var expectedTree = require('../expected/copy-tree/copy-tree-depth-4');
+ var opts = { tasksDepth: 5 };
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(expectedTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy a tree until depth 1 if the specified depth < 1',
+ function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var expectedTree = require('../expected/copy-tree/copy-tree-depth-1');
+ var opts = { tasksDepth: -1 };
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(expectedTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ it('Should copy a full depth tree if the specified depth is not number',
+ function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var expectedTree = require('../expected/copy-tree/copy-tree-depth-4');
+ var opts = { tasksDepth: null };
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(expectedTree);
+ expect(newTree).toNotBe(srcTree);
+
+ opts = { tasksDepth: 'A' };
+ newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(expectedTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+
+ });
+
+ describe('opts.compactTasks', function() {
+ it('Should output only nodes of which `.branch` are true and those ' +
+ 'children', function(done) {
+ var srcTree = require('../fixtures/copy-tree');
+ var expectedTree = require('../expected/copy-tree/copy-tree-compact');
+ var opts = { compactTasks: true };
+ var newTree = copyTree(srcTree, opts, nonConvertingNodeFactory);
+ expect(newTree).toEqual(expectedTree);
+ expect(newTree).toNotBe(srcTree);
+ done();
+ });
+ });
+
+});
+
+
+function copyNode(node) {
+ var obj = {};
+ Object.keys(node).forEach(function(key) {
+ obj[key] = node[key];
+ });
+ return obj;
+}
+
diff --git a/test/taskTree.js b/test/lib/taskTree.js
similarity index 94%
rename from test/taskTree.js
rename to test/lib/taskTree.js
index 8345c7a9..49305261 100644
--- a/test/taskTree.js
+++ b/test/lib/taskTree.js
@@ -2,9 +2,9 @@
var expect = require('expect');
-var taskTree = require('../lib/versioned/^3.7.0/taskTree');
+var taskTree = require('../../lib/versioned/^3.7.0/taskTree');
-describe('taskTree', function() {
+describe('lib: taskTree', function() {
it('forms a tree properly', function(done) {
expect(taskTree).toExist(); // Lol shutup jshint