diff --git a/lib/test.js b/lib/test.js index f1bf5ef..63896fe 100644 --- a/lib/test.js +++ b/lib/test.js @@ -925,7 +925,7 @@ class Test extends Base { } teardown (fn) { - this.onTeardown.push(fn) + this.onTeardown.unshift(fn) } shouldAutoend () { diff --git a/tap-snapshots/test/test.js.test.cjs b/tap-snapshots/test/test.js.test.cjs index c6d5dc65..bbe9d5b 100644 --- a/tap-snapshots/test/test.js.test.cjs +++ b/tap-snapshots/test/test.js.test.cjs @@ -2580,6 +2580,19 @@ not ok 2 - expect never emitted event to be emitted ` +exports[`test/test.js TAP assertions and weird stuff teardown in reverse order > output 1`] = ` +TAP version 13 +# Subtest: parent + ok 1 - this is fine + 1..1 +ok 1 - parent # {time} + +# second teardown +# first teardown +1..1 + +` + exports[`test/test.js TAP assertions and weird stuff teardown promise > output 1`] = ` TAP version 13 # Subtest: parent diff --git a/test/test.js b/test/test.js index 819195e..5575f16 100644 --- a/test/test.js +++ b/test/test.js @@ -768,6 +768,20 @@ t.test('assertions and weird stuff', t => { tt.end() }, + 'teardown in reverse order': tt => { + tt.test('parent', tt => { + tt.teardown(() => { + tt.comment('first teardown') + }) + tt.teardown(() => { + tt.comment('second teardown') + }) + tt.pass('this is fine') + tt.end() + }) + tt.end() + }, + 'fullname without main': tt => { const main = process.argv[1] process.argv[1] = ''