tape-testing / tape

tap-producing test harness for node and browsers
MIT License
5.77k stars 307 forks source link

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

Closed aral closed 3 years ago

aral commented 3 years ago

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 commented 3 years ago

Wow, great find :-) will fix asap

aral commented 3 years ago

@ljharb Thanks, Jordan, appreciate it :)

ljharb commented 3 years ago

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 commented 3 years ago

Released in v5.2.1.

aral commented 3 years ago

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