@@ -5,6 +5,7 @@ const assert = require('assert');
55const { test, describe, it, before, after, beforeEach, afterEach } = require ( 'node:test' ) ;
66
77before ( ( t ) => t . diagnostic ( 'before 1 called' ) ) ;
8+ after ( ( t ) => t . diagnostic ( 'after 1 called' ) ) ;
89
910describe ( 'describe hooks' , ( ) => {
1011 const testArr = [ ] ;
@@ -107,17 +108,20 @@ test('test hooks', async (t) => {
107108 await t . test ( 'nested 2' , ( ) => testArr . push ( 'nested 2' ) ) ;
108109 } ) ;
109110
110- assert . deepStrictEqual ( testArr , [
111- 'before test hooks' ,
112- 'beforeEach 1' , '1' , 'afterEach 1' ,
113- 'beforeEach 2' , '2' , 'afterEach 2' ,
114- 'beforeEach nested' ,
115- 'nested before nested' ,
116- 'beforeEach nested 1' , 'nested beforeEach nested 1' , 'nested1' , 'afterEach nested 1' , 'nested afterEach nested 1' ,
117- 'beforeEach nested 2' , 'nested beforeEach nested 2' , 'nested 2' , 'afterEach nested 2' , 'nested afterEach nested 2' ,
118- 'afterEach nested' ,
119- 'nested after nested' ,
120- ] ) ;
111+ t . after ( common . mustCall ( ( ) => {
112+ assert . deepStrictEqual ( testArr , [
113+ 'before test hooks' ,
114+ 'beforeEach 1' , '1' , 'afterEach 1' ,
115+ 'beforeEach 2' , '2' , 'afterEach 2' ,
116+ 'beforeEach nested' ,
117+ 'nested before nested' ,
118+ 'beforeEach nested 1' , 'nested beforeEach nested 1' , 'nested1' , 'afterEach nested 1' , 'nested afterEach nested 1' ,
119+ 'beforeEach nested 2' , 'nested beforeEach nested 2' , 'nested 2' , 'afterEach nested 2' , 'nested afterEach nested 2' ,
120+ 'afterEach nested' ,
121+ 'nested after nested' ,
122+ 'after test hooks' ,
123+ ] ) ;
124+ } ) ) ;
121125} ) ;
122126
123127test ( 't.before throws' , async ( t ) => {
@@ -164,3 +168,4 @@ test('t.after() is called if test body throws', (t) => {
164168} ) ;
165169
166170before ( ( t ) => t . diagnostic ( 'before 2 called' ) ) ;
171+ after ( ( t ) => t . diagnostic ( 'after 2 called' ) ) ;
0 commit comments