diff --git a/lib/step.js b/lib/step.js index b524a6a..fbe4840 100755 --- a/lib/step.js +++ b/lib/step.js @@ -118,6 +118,10 @@ function Step() { }; }; + next.exitChain = function () { + steps = new Array(); + } + // Start the engine an pass nothing to the first step. next(); } diff --git a/test/exitChain.js b/test/exitChain.js new file mode 100644 index 0000000..c3bf7a2 --- /dev/null +++ b/test/exitChain.js @@ -0,0 +1,25 @@ +require('./helper'); + +var selfText = fs.readFileSync(__filename, 'utf8'); + +// This example tests stopping a step chain before running all the registered steps + +expect('one'); +expect('two'); +Step( + function readSelf() { + fulfill("one"); + fs.readFile(__filename, 'utf8', this); + }, + function capitalize(err, text) { + fulfill("two"); + if (err) throw err; + assert.equal(selfText, text, "Text Loaded"); + return this.exitChain(); + }, + function showIt(err, newText) { + expect("three"); + if (err) throw err; + assert.equal(selfText.toUpperCase(), newText, "Text Uppercased"); + } +);