Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teardown in reverse order #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ class Test extends Base {
}

teardown (fn) {
this.onTeardown.push(fn)
this.onTeardown.unshift(fn)
}

shouldAutoend () {
Expand Down
13 changes: 13 additions & 0 deletions tap-snapshots/test/test.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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] = ''
Expand Down