Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add pull-stream tests to validate pull-stream use cases
- Loading branch information
1 parent
bdad187
commit 31efcfb
Showing
5 changed files
with
259 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
var test = require('tape'); | ||
var task = require('..')(); | ||
var executed = []; | ||
var a; | ||
var b; | ||
var c; | ||
|
||
function trackTask() { | ||
executed.push(this.name); | ||
setTimeout(this.async(), 50); | ||
} | ||
|
||
test('specify a dependency', function(t) { | ||
a = task('a', { deps: ['b'] }, trackTask); | ||
executed = []; | ||
|
||
// run a | ||
t.plan(2); | ||
task.exec(['a'], function(err) { | ||
t.ok(err, 'captured error'); | ||
t.equal(err.message, 'Task "b" not found'); | ||
}); | ||
}); | ||
|
||
test('specify dependency (jake style)', function(t) { | ||
a = task('a', ['b'], trackTask); | ||
executed = []; | ||
|
||
// run a | ||
t.plan(2); | ||
task.exec(['a'], function(err) { | ||
t.ok(err, 'captured error'); | ||
t.equal(err.message, 'Task "b" not found'); | ||
}); | ||
}); | ||
|
||
test('register task b', function(t) { | ||
b = task('b', trackTask); | ||
executed = []; | ||
|
||
t.plan(2); | ||
task.exec(['a'], function(err) { | ||
t.ifError(err, 'no error'); | ||
t.deepEqual(executed, ['b', 'a']); | ||
}); | ||
}) | ||
|
||
test('register additional dependency', function(t) { | ||
c = task('c', trackTask); | ||
b.depends('c'); | ||
executed = []; | ||
|
||
t.plan(2); | ||
task.exec(['a'], function(err) { | ||
t.ifError(err, 'no error'); | ||
t.deepEqual(executed, ['c', 'b', 'a']); | ||
}); | ||
}); | ||
|
||
test('reject cyclic dependency (c --> c)', function(t) { | ||
c.depends('c'); | ||
executed = []; | ||
|
||
t.plan(2); | ||
task.exec(['a'], function(err) { | ||
t.ifError(err, 'no error'); | ||
t.deepEqual(executed, ['c', 'b', 'a']); | ||
}); | ||
}); | ||
|
||
/* | ||
// TODO | ||
test('reject cyclic dependency (c --> a)', function(t) { | ||
c.depends('a'); | ||
executed = []; | ||
t.plan(2); | ||
taskify.run('a').once('complete', function(err) { | ||
t.ifError(err, 'no error'); | ||
t.deepEqual(executed, ['c', 'b', 'a']); | ||
}); | ||
});*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
var test = require('tape'); | ||
var task = require('..')(); | ||
var pull = require('pull-stream'); | ||
var executed = []; | ||
var a; | ||
var b; | ||
var c; | ||
|
||
function trackTask() { | ||
var callback = this.async(); | ||
|
||
executed.push(this.name); | ||
setTimeout(function() { | ||
callback(null, true); | ||
}, 50); | ||
} | ||
|
||
test('specify a dependency', function(t) { | ||
a = task('a', { deps: ['b'] }, trackTask); | ||
executed = []; | ||
|
||
// run a | ||
t.plan(2); | ||
pull( | ||
pull.values(['a', 'a', 'a']), | ||
pull.asyncMap(task.exec), | ||
pull.collect(function(err, values) { | ||
t.ok(err instanceof Error); | ||
t.equal(err.message, 'Task "b" not found'); | ||
}) | ||
); | ||
}); | ||
|
||
test('specify dependency (jake style)', function(t) { | ||
a = task('a', ['b'], trackTask); | ||
executed = []; | ||
|
||
// run a | ||
t.plan(2); | ||
pull( | ||
pull.values(['a', 'a', 'a']), | ||
pull.asyncMap(task.exec), | ||
pull.collect(function(err, values) { | ||
t.ok(err instanceof Error); | ||
t.equal(err.message, 'Task "b" not found'); | ||
}) | ||
); | ||
}); | ||
|
||
test('register task b', function(t) { | ||
b = task('b', trackTask); | ||
executed = []; | ||
|
||
t.plan(2); | ||
pull( | ||
pull.values(['a', 'a', 'a']), | ||
pull.asyncMap(task.exec), | ||
pull.collect(function(err, values) { | ||
t.ifError(err); | ||
t.deepEqual(values, [true, true, true], 'executed tasks'); | ||
}) | ||
); | ||
}) | ||
|
||
test('register additional dependency', function(t) { | ||
c = task('c', trackTask); | ||
b.depends('c'); | ||
executed = []; | ||
|
||
t.plan(3); | ||
pull( | ||
pull.values(['a', 'a', 'a']), | ||
pull.asyncMap(task.exec), | ||
pull.collect(function(err, values) { | ||
t.ifError(err); | ||
t.deepEqual(values, [true, true, true], 'executed tasks'); | ||
t.deepEqual(executed, ['c', 'b', 'a', 'c', 'b', 'a', 'c', 'b', 'a'], 'executed in expected order'); | ||
}) | ||
); | ||
}); | ||
|
||
test('reject cyclic dependency (c --> c)', function(t) { | ||
c.depends('c'); | ||
executed = []; | ||
|
||
t.plan(3); | ||
pull( | ||
pull.values(['a', 'a', 'a']), | ||
pull.asyncMap(task.exec), | ||
pull.collect(function(err, values) { | ||
t.ifError(err); | ||
t.deepEqual(values, [true, true, true], 'executed tasks'); | ||
t.deepEqual(executed, ['c', 'b', 'a', 'c', 'b', 'a', 'c', 'b', 'a'], 'executed in expected order'); | ||
}) | ||
); | ||
}); | ||
|
||
/* | ||
// TODO | ||
test('reject cyclic dependency (c --> a)', function(t) { | ||
c.depends('a'); | ||
executed = []; | ||
t.plan(2); | ||
taskify.run('a').once('complete', function(err) { | ||
t.ifError(err, 'no error'); | ||
t.deepEqual(executed, ['c', 'b', 'a']); | ||
}); | ||
});*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var test = require('tape'); | ||
var task = require('..')(); | ||
var executed = []; | ||
var pull = require('pull-stream'); | ||
var a, b, c; | ||
|
||
function trackTask() { | ||
executed.push(this.name); | ||
|
||
return true; | ||
} | ||
|
||
test('register a', function(t) { | ||
t.plan(1); | ||
a = task('a', { deps: ['b'] }, trackTask); | ||
t.ok(task.get('a'), 'registered'); | ||
}); | ||
|
||
test('catch dependency error', function(t) { | ||
t.plan(2); | ||
|
||
pull( | ||
pull.values(['a', 'a', 'a']), | ||
pull.asyncMap(task.exec), | ||
pull.collect(function(err, values) { | ||
t.ok(err instanceof Error); | ||
t.equal(err.message, 'Task "b" not found'); | ||
}) | ||
); | ||
}); | ||
|
||
test('register b', function(t) { | ||
t.plan(1); | ||
b = task('b', trackTask); | ||
t.ok(task.get('b'), 'registered'); | ||
}); | ||
|
||
test('run a + b', function(t) { | ||
executed = []; | ||
|
||
t.plan(2); | ||
pull( | ||
pull.values(['a', 'a', 'a']), | ||
pull.asyncMap(task.exec), | ||
pull.collect(function(err, values) { | ||
t.ifError(err); | ||
t.deepEqual(values, [true, true, true], 'executed tasks'); | ||
}) | ||
); | ||
}); |