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

The teardown function is called twice when test is async and t.plan() is used #551

Closed
aral opened this issue Feb 27, 2021 · 5 comments
Closed

Comments

@aral
Copy link

aral commented Feb 27, 2021

Summary

The teardown function is called twice when test is async and t.plan() is used. (Tape version: 5.2.0.)

To reproduce

import test from 'tape'

test ('something', async t => {
  t.plan(1)
  t.teardown(function () {
    console.log('Tearing down!')
  })
  t.pass()
})

What should happen

The teardown function should be called just once.

What actually happens

The teardown function is called twice.

Notes

This issue does not trigger when the test is synchronous or when t.end() is used.

@ljharb
Copy link
Collaborator

ljharb commented Feb 27, 2021

Wow, great find :-) will fix asap

@aral
Copy link
Author

aral commented Feb 27, 2021

@ljharb Thanks, Jordan, appreciate it :)

@ljharb
Copy link
Collaborator

ljharb commented Feb 27, 2021

hmm - oddly enough in my test, i'm able to reproduce this example as calling it zero times (which is still a bug), but not twice. When I add your example as a lone file, it calls it twice. Also, even in your test case, when t.end() is added but t.plan(1) remains, it still calls it twice, but i can reproduce that it calls it once when t.plan is used but t.end is not. This is clearly a fun one.

Update: i was able to pretty quickly fix your issue (but not yet create a test for it) but my own issue still occurs.

Update again: i was able to reproduce your issue in tests.

@ljharb ljharb self-assigned this Feb 27, 2021
@ljharb ljharb closed this as completed in 3ea7921 Feb 28, 2021
ljharb added a commit that referenced this issue Feb 28, 2021
 - [Fix] `t.teardown()`: ensure callback is only called once (#551)
 - [Deps] update `object-is`, `string.prototype.trim`
@ljharb
Copy link
Collaborator

ljharb commented Feb 28, 2021

Released in v5.2.1.

@aral
Copy link
Author

aral commented Feb 28, 2021

Thanks so much, Jordan. It’s working like a charm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants