Skip to content

Commit

Permalink
Don't drop buffered child output when it satisfies a plan
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Dec 30, 2016
1 parent 157ffdd commit 86e82fa
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,13 @@ Test.prototype._runChild = function runChild (child, name, extra, cb) {
bail = true
self._bail = false
}

var endThis = false
if (self._plan === self._count + 1) {
endThis = true
self._ending = true
}

self.ok(child._ok, child._name + ' {', { diagnostic: false })
var b = child._buffer.trim().split('\n').join('\n ') + '\n'
b = b.split('\n \n').join('\n\n')
Expand All @@ -580,6 +587,9 @@ Test.prototype._runChild = function runChild (child, name, extra, cb) {
self.push(' ' + b + '}\n')
if (bail) {
self.bailout(child._name)
} else if (endThis) {
self._ending = false
self.end(IMPLICIT)
}
} else {
self.ok(child._ok, name + ' ' + time, extra)
Expand Down
12 changes: 12 additions & 0 deletions test/test/before-after-each-plan-bail-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ after 2 child
after 1 child
after 1 parent
ok 1 - parent {
1..1
ok 1 - child {
1..1
ok 1 - grandchild {
1..1
ok 1 - the only actual assertion
___/# time=[0-9.]+(ms)?/~~~
}
___/# time=[0-9.]+(ms)?/~~~
}
___/# time=[0-9.]+(ms)?/~~~
}
___/# time=[0-9.]+(ms)?/~~~
done

12 changes: 12 additions & 0 deletions test/test/before-after-each-plan-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ after 2 child
after 1 child
after 1 parent
ok 1 - parent {
1..1
ok 1 - child {
1..1
ok 1 - grandchild {
1..1
ok 1 - the only actual assertion
___/# time=[0-9.]+(ms)?/~~~
}
___/# time=[0-9.]+(ms)?/~~~
}
___/# time=[0-9.]+(ms)?/~~~
}
___/# time=[0-9.]+(ms)?/~~~
done

8 changes: 8 additions & 0 deletions test/test/promise-plan-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ not ok 4 - broken promises {
}

not ok 2 - plan {
1..1
ok 1 - this is fine
___/# time=[0-9.]+(ms)?/~~~
}
# failed 2 of 2 tests
___/# time=[0-9.]+(ms)?/~~~
}
Expand All @@ -44,6 +48,10 @@ not ok 5 - thrown with timeouts {
}

not ok 2 - plan {
1..1
ok 1 - this is fine
___/# time=[0-9.]+(ms)?/~~~
}
# failed 2 of 2 tests
___/# time=[0-9.]+(ms)?/~~~
}
Expand Down
26 changes: 26 additions & 0 deletions test/test/subtest-preplan-bail-buffer.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TAP version 13
ok 1 - with timeout {
1..1
ok 1 - child test {
1..2
ok 1 - this is fine
ok 2 - i am ok with how things are proceeding
___/# time=[0-9.]+(ms)?/~~~
}
___/# time=[0-9.]+(ms)?/~~~
}

ok 2 - no timeout {
1..1
ok 1 - child test {
1..2
ok 1 - this is fine
ok 2 - i am ok with how things are proceeding
___/# time=[0-9.]+(ms)?/~~~
}
___/# time=[0-9.]+(ms)?/~~~
}

1..2
___/# time=[0-9.]+(ms)?/~~~

23 changes: 23 additions & 0 deletions test/test/subtest-preplan-bail.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
TAP version 13
# Subtest: with timeout
1..1
# Subtest: child test
1..2
ok 1 - this is fine
ok 2 - i am ok with how things are proceeding
ok 1 - child test ___/# time=[0-9.]+(ms)?/~~~
ok 1 - with timeout ___/# time=[0-9.]+(ms)?/~~~

# Subtest: no timeout
1..1
# Subtest: child test
1..2
ok 1 - this is fine
ok 2 - i am ok with how things are proceeding
ok 1 - child test ___/# time=[0-9.]+(ms)?/~~~

ok 2 - no timeout ___/# time=[0-9.]+(ms)?/~~~

1..2
___/# time=[0-9.]+(ms)?/~~~

26 changes: 26 additions & 0 deletions test/test/subtest-preplan-buffer.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
TAP version 13
ok 1 - with timeout {
1..1
ok 1 - child test {
1..2
ok 1 - this is fine
ok 2 - i am ok with how things are proceeding
___/# time=[0-9.]+(ms)?/~~~
}
___/# time=[0-9.]+(ms)?/~~~
}

ok 2 - no timeout {
1..1
ok 1 - child test {
1..2
ok 1 - this is fine
ok 2 - i am ok with how things are proceeding
___/# time=[0-9.]+(ms)?/~~~
}
___/# time=[0-9.]+(ms)?/~~~
}

1..2
___/# time=[0-9.]+(ms)?/~~~

20 changes: 20 additions & 0 deletions test/test/subtest-preplan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var t = require('../..')
t.test('with timeout', function (t) {
t.plan(1)
t.test('child test', function (t) {
t.plan(2)
setTimeout(function () {
t.pass('this is fine')
t.pass('i am ok with how things are proceeding')
})
})
})

t.test('no timeout', function (t) {
t.plan(1)
t.test('child test', function (t) {
t.plan(2)
t.pass('this is fine')
t.pass('i am ok with how things are proceeding')
})
})
23 changes: 23 additions & 0 deletions test/test/subtest-preplan.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
TAP version 13
# Subtest: with timeout
1..1
# Subtest: child test
1..2
ok 1 - this is fine
ok 2 - i am ok with how things are proceeding
ok 1 - child test ___/# time=[0-9.]+(ms)?/~~~
ok 1 - with timeout ___/# time=[0-9.]+(ms)?/~~~

# Subtest: no timeout
1..1
# Subtest: child test
1..2
ok 1 - this is fine
ok 2 - i am ok with how things are proceeding
ok 1 - child test ___/# time=[0-9.]+(ms)?/~~~

ok 2 - no timeout ___/# time=[0-9.]+(ms)?/~~~

1..2
___/# time=[0-9.]+(ms)?/~~~

8 changes: 8 additions & 0 deletions test/test/throw-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ not ok 1 - nesting {
}

not ok 3 - thrower {
not ok 1 - Error: here hold this for a second
---
{"at":{"column":14,"file":"test/test/throw.js","line":18},"message":"Error: here hold this for a second","source":"var er = new Error('here hold this for a second')\n","syscall":"ring ring","test":"thrower"}
...
1..1
# failed 1 of 1 tests
___/# time=[0-9.]+(ms)?/~~~
}
# failed 2 of 3 tests
___/# time=[0-9.]+(ms)?/~~~
}
Expand Down

0 comments on commit 86e82fa

Please sign in to comment.