Closed tunnckoCore closed 9 years ago
var erasm = require('./erasm.js');
var test = require('tape');
test('functions that return errors', function (t) {
t.plan(2)
var tasks = {
a: function (cb) {
t.pass('cb 1')
cb(new Error('oops'))
},
b: ['a', function (cb) {
t.fail('cb 2 should not get called')
}]
}
erasm(tasks)
.run(function (err) {
t.ok(err instanceof Error, 'should be true')
})
});
test('empty tasks object', function (t) {
t.plan(2)
erasm({})
.run(function (err) {
t.equals(err, undefined)
t.pass('did not throw')
t.end()
})
});
test('tasks property count should be zero', function (t) {
t.plan(1)
t.deepEqual(erasm({}).tasks, {})
t.end()
});
test('empty tasks object and no callback', function (t) {
erasm([])
t.pass('did not throw')
t.end()
})
test('auto error should pass partial results', function (t) {
t.plan(3)
var tasks = {
task1: function (cb) {
cb(false, 'result1')
},
task2: ['task1', function (cb) {
cb(new Error('testerror'), 'result2')
}],
task3: ['task2', function (cb) {
t.fail('task3 should not be called')
}]
}
erasm(tasks)
.run(function (err, results) {
t.ok(err instanceof Error, 'should be true')
t.equals(results.task1, 'result1')
t.equals(results.task2, 'result2')
t.end()
})
});
test('should have .task method', function(t) {
t.plan(3)
erasm()
.task('task1', function(cb) {
cb(false, 'result1')
})
.task('task2', ['task1'], function(cb) {
cb(new Error('testerror'), 'result2')
})
.task('task3', ['task2'], function(cb) {
t.fail('task3 should not be called')
})
.run(function(err, results) {
t.ok(err instanceof Error, 'should be true')
t.equals(results.task1, 'result1')
t.equals(results.task2, 'result2')
t.end()
})
})
var callOrder = [];
test('functions run in parallel', function (t) {
erasm()
.task('task1', function (cb) {
callOrder.push('task1')
cb()
})
.task('task2', function (cb) {
callOrder.push('task2')
cb()
})
.task('task3', function (cb) {
setTimeout(function () {
callOrder.push('task3')
cb()
}, 50)
})
.task('task4', ['task3'], function (cb) {
setTimeout(function () {
callOrder.push('task4')
cb()
}, 30)
})
.task('task5', ['task4'], function (cb) {
setTimeout(function () {
callOrder.push('task5')
cb()
}, 150)
})
.task('task6', function (cb) {
callOrder.push('task6')
cb()
})
.run(function (err) {
t.deepEqual(callOrder, ['task1','task2','task6','task3','task4','task5'])
t.end()
})
});
closing, follow https://github.com/tunnckoCore/ideas/issues/11