Permalink
Browse files

v3.3.2. Improvement.

  • Loading branch information...
1 parent d80089e commit c1ce0ae09f7095b302693638bcb8eb599db751c3 @balupton balupton committed Nov 19, 2013
Showing with 48 additions and 2 deletions.
  1. +3 −0 History.md
  2. +1 −1 package.json
  3. +5 −0 src/lib/taskgroup.coffee
  4. +39 −1 src/test/taskgroup-test.coffee
View
@@ -1,5 +1,8 @@
## History
+- v3.3.2 November 19, 2013
+ - Don't add or create empty tasks and groups
+
- v3.3.1 November 6, 2013
- Fixed child event bubbling by using duck typing (regression since v3.3.0)
- Better error handling on uncaught task exceptions
View
@@ -1,7 +1,7 @@
{
"title": "TaskGroup",
"name": "taskgroup",
- "version": "3.3.1",
+ "version": "3.3.2",
"description": "Group together synchronous and asynchronous tasks and execute them with support for concurrency, naming, and nesting.",
"homepage": "https://github.com/bevry/taskgroup",
"license": {
View
@@ -337,6 +337,9 @@ class TaskGroup extends EventEmitter
# Prepare
me = @
+ # Only add the item if it exists
+ return null unless item
+
# Link our item to ourself
item.setConfig({parent: @})
@@ -382,6 +385,7 @@ class TaskGroup extends EventEmitter
createTask: (args...) ->
+ return null unless args[0]
return args[0] if args[0]?.type is 'task'
return new Task(args...)
@@ -394,6 +398,7 @@ class TaskGroup extends EventEmitter
createGroup: (args...) ->
+ return null unless args[0]
return args[0] if args[0]?.type is 'taskgroup'
return new TaskGroup(args...)
@@ -408,7 +408,7 @@ joe.describe 'taskgroup', (describe,it) ->
# Test Runner
joe.describe 'inline', (describe,it) ->
# Work
- it 'should work', (done) ->
+ it 'should work (format 1)', (done) ->
checks = []
tasks = new TaskGroup 'my tests', (addGroup,addTask) ->
@@ -445,4 +445,42 @@ joe.describe 'inline', (describe,it) ->
expect(checks.length, 'checks').to.eql(4)
done()
+ # Work
+ it 'should work (format 2)', (done) ->
+ checks = []
+
+ tasks = new TaskGroup().run()
+
+ tasks.addTask 'my task', (complete) ->
+ checks.push('my task 1')
+ expect(@config.name).to.eql('my task')
+ expect(tasks.remaining.length).to.eql(1)
+ expect(tasks.running).to.eql(1)
+ wait 500, ->
+ checks.push('my task 2')
+ expect(tasks.remaining.length).to.eql(1)
+ expect(tasks.running).to.eql(1)
+ complete()
+
+ tasks.addGroup 'my group', ->
+ checks.push('my group')
+ expect(@config.name).to.eql('my group')
+ expect(tasks.remaining.length, 'my group remaining').to.eql(0)
+ expect(tasks.running).to.eql(1)
+
+ @addTask 'my second task', ->
+ checks.push('my second task')
+ expect(@config.name).to.eql('my second task')
+ expect(tasks.remaining.length, 'my second task remaining').to.eql(0)
+ expect(tasks.running).to.eql(1)
+
+ tasks.on 'complete', (err) ->
+ console.log(err) if err
+ expect(err).to.eql(null)
+
+ console.log(checks) if checks.length isnt 4
+ expect(checks.length, 'checks').to.eql(4)
+
+ done()
+

0 comments on commit c1ce0ae

Please sign in to comment.