@@ -113,18 +113,22 @@ tap.test('teardowns', function (tt) {
113113 ) ;
114114 } ) ,
115115 typeof Promise === 'function' ? [
116+ '# teardown is only ever called once, even when async' ,
117+ 'ok ' + ( 11 + v . nonFunctions . length ) + ' passes' ,
118+ '# teardown: once?' ,
116119 '# success (promise)' ,
117- 'ok ' + ( 11 + v . nonFunctions . length ) + ' should be truthy' ,
120+ 'ok ' + ( 12 + v . nonFunctions . length ) + ' should be truthy' ,
118121 '# success (promise) teardown: 1' ,
119122 '# success (promise) teardown: 2' ,
120123 '# success (promise) teardown: 3'
121124 ] : [
125+ '# SKIP teardown is only ever called once, even when async' ,
122126 '# SKIP success (promise)'
123127 ] , [
124128 '' ,
125- '1..' + ( ( typeof Promise === 'function' ? 1 : 0 ) + 10 + v . nonFunctions . length ) ,
126- '# tests ' + ( ( typeof Promise === 'function' ? 1 : 0 ) + 10 + v . nonFunctions . length ) ,
127- '# pass ' + ( ( typeof Promise === 'function' ? 1 : 0 ) + 5 ) ,
129+ '1..' + ( ( typeof Promise === 'function' ? 2 : 0 ) + 10 + v . nonFunctions . length ) ,
130+ '# tests ' + ( ( typeof Promise === 'function' ? 2 : 0 ) + 10 + v . nonFunctions . length ) ,
131+ '# pass ' + ( ( typeof Promise === 'function' ? 2 : 0 ) + 5 ) ,
128132 '# fail ' + ( 5 + v . nonFunctions . length ) ,
129133 ''
130134 ] ) ) ;
@@ -226,6 +230,18 @@ tap.test('teardowns', function (tt) {
226230 } ) ;
227231 } ) ;
228232
233+ test ( 'teardown is only ever called once, even when async' , { skip : typeof Promise !== 'function' } , function ( t ) {
234+ t . plan ( 1 ) ;
235+
236+ t . teardown ( function ( ) {
237+ t . comment ( 'teardown: once?' ) ;
238+ } ) ;
239+
240+ t . pass ( 'passes' ) ;
241+
242+ return Promise . resolve ( ) ;
243+ } ) ;
244+
229245 test ( 'success (promise)' , { skip : typeof Promise !== 'function' } , function ( t ) {
230246 t . plan ( 1 ) ;
231247
@@ -265,3 +281,36 @@ tap.test('teardown with promise', { skip: typeof Promise !== 'function', timeout
265281 t . end ( ) ;
266282 } ) ;
267283} ) ;
284+
285+ tap . test ( 'teardown only runs once' , { skip : typeof Promise !== 'function' , timeout : 1e3 } , function ( tt ) {
286+ tt . plan ( 1 ) ;
287+
288+ var test = tape . createHarness ( ) ;
289+ test . createStream ( ) . pipe ( concat ( function ( body ) {
290+ tt . same ( stripFullStack ( body . toString ( 'utf8' ) ) , [ ] . concat (
291+ 'TAP version 13' ,
292+ '# teardown is only called once, even with a plan' ,
293+ 'ok 1 passes' ,
294+ '# Tearing down!' ,
295+ '' ,
296+ '1..1' ,
297+ '# tests 1' ,
298+ '# pass 1' ,
299+ '' ,
300+ '# ok' ,
301+ ''
302+ ) ) ;
303+ } ) ) ;
304+
305+ test ( 'teardown is only called once, even with a plan' , function ( t ) {
306+ t . plan ( 1 ) ;
307+
308+ t . teardown ( function ( ) {
309+ t . comment ( 'Tearing down!' ) ;
310+ } ) ;
311+
312+ t . pass ( 'passes' ) ;
313+
314+ return Promise . resolve ( ) ;
315+ } ) ;
316+ } ) ;
0 commit comments