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')