From b890daa0248a293b17bf2c23e20a336525452dfb Mon Sep 17 00:00:00 2001 From: Ilya Radchenko Date: Fri, 16 Sep 2016 16:48:31 -0400 Subject: [PATCH] Add more tests --- dist/index.js | 16 ++++++++++++---- lib/index.js | 16 ++++++++++++---- test/index.js | 14 ++++++++++++++ 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/dist/index.js b/dist/index.js index a4a3b09..244c4d0 100644 --- a/dist/index.js +++ b/dist/index.js @@ -21,10 +21,16 @@ module.exports = class Runner { * */ start() {return __async(function*(){ - const startTask = this.getTask(this.workflow.startTaskId) + const startTaskId = this.workflow.startTaskId + + if (!startTaskId) { + throw new Error('`startTaskId` must be specified') + } + + const startTask = this.getTask(startTaskId) if (!startTask) { - throw new Error('Invalid workflow - missing start task') + throw new Error('Invalid workflow - start task not found') } yield this.runTask(startTask) @@ -106,10 +112,12 @@ module.exports = class Runner { }.call(this))} getTask(id, source) { - source = source || this.workflow.tasks + source = source || this.workflow.tasks || {} const task = source[id] - task._id = id + if (task) { + task._id = id + } return task } diff --git a/lib/index.js b/lib/index.js index 1bfae12..622c282 100644 --- a/lib/index.js +++ b/lib/index.js @@ -21,10 +21,16 @@ module.exports = class Runner { * */ async start() { - const startTask = this.getTask(this.workflow.startTaskId) + const startTaskId = this.workflow.startTaskId + + if (!startTaskId) { + throw new Error('`startTaskId` must be specified') + } + + const startTask = this.getTask(startTaskId) if (!startTask) { - throw new Error('Invalid workflow - missing start task') + throw new Error('Invalid workflow - start task not found') } await this.runTask(startTask) @@ -106,10 +112,12 @@ module.exports = class Runner { } getTask(id, source) { - source = source || this.workflow.tasks + source = source || this.workflow.tasks || {} const task = source[id] - task._id = id + if (task) { + task._id = id + } return task } diff --git a/test/index.js b/test/index.js index 58e454d..1b9a073 100644 --- a/test/index.js +++ b/test/index.js @@ -10,6 +10,20 @@ test('requires workflow', t => { }, 'Invalid workflow specified', 'Throws on invalid workflow') }) +test('workflow requires startTaskId', async t => { + const runner = new Runner({}) + + t.throws(runner.start(), '`startTaskId` must be specified', + 'Throws on invalid') +}) + +test('workflow requires startTask', async t => { + const runner = new Runner({startTaskId: 'a'}) + + t.throws(runner.start(), 'Invalid workflow - start task not found', + 'Throws on invalid') +}) + test('All pass', async t => { const workflow = require('./fixtures/all-pass')