Skip to content

Commit

Permalink
Handle bailouts better after test end happens
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Sep 7, 2016
1 parent 11042eb commit 62dbb2b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
11 changes: 11 additions & 0 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1552,6 +1552,17 @@ Test.prototype.push = function (c, e) {
}

Test.prototype.bailout = function (message) {
if (this._parent && (this._ended || this._bailedOut)) {
this._parent.bailout(message)
return
}

if (this._currentChild && this._currentChild.bailout) {
var child = this._currentChild
this._currentChild = null
child.bailout(message)
}

message = message ? ' # ' + ('' + message).trim() : ''
message = message.replace(/^( #)+ /, ' # ')
message = message.replace(/[\r\n]/g, ' ')
Expand Down
12 changes: 12 additions & 0 deletions test/test/bail-teardown-async-bail.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TAP version 13
# Subtest: foobar test
1..0
ok 1 - foobar test ___/# time=[0-9.]+(ms)?/~~~

# Subtest: barfoo
# Subtest: barfoo2
# Subtest: barf3
# Subtest: b3rf
Bail out! # teardown fail
Bail out! # teardown fail

20 changes: 20 additions & 0 deletions test/test/bail-teardown-async.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
var t = require('../..')

t.test('foobar test', function (t) {
t.tearDown(function () {
setTimeout(function () {
t.bailout('teardown fail')
})
})
t.end()
})

t.test('barfoo', function (t) {
return t.test('barfoo2', function (t) {
return t.test('barf3', function (t) {
return t.test('b3rf', function (t) {
setTimeout(t.end, 1000)
})
})
})
})
12 changes: 12 additions & 0 deletions test/test/bail-teardown-async.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
TAP version 13
# Subtest: foobar test
1..0
ok 1 - foobar test ___/# time=[0-9.]+(ms)?/~~~

# Subtest: barfoo
# Subtest: barfoo2
# Subtest: barf3
# Subtest: b3rf
Bail out! # teardown fail
Bail out! # teardown fail

1 change: 0 additions & 1 deletion test/test/bail-teardown-bail.tap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ ok 1 - this is fine
1..1
ok 2 - child ___/# time=[0-9.]+(ms)?/~~~

Bail out! # i did not want to be torn down
Bail out! # i did not want to be torn down

1 change: 0 additions & 1 deletion test/test/bail-teardown.tap
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ ok 1 - this is fine
1..1
ok 2 - child ___/# time=[0-9.]+(ms)?/~~~

Bail out! # i did not want to be torn down
Bail out! # i did not want to be torn down

0 comments on commit 62dbb2b

Please sign in to comment.