@@ -46,15 +46,21 @@ export class ExecutionResult implements IExecutionResult {
4646
4747class TestBlock {
4848 constructor ( public description : string ) { }
49+ setupFunctions : number [ ] = [ ] ;
50+ teardownFunctions : number [ ] = [ ] ;
4951}
5052
51- class TestCase {
53+ export class TestCase {
5254 fullName : string ;
55+ setupFunctions : number [ ] ;
56+ teardownFunctions : number [ ] ;
5357 constructor (
5458 testBlockStack : TestBlock [ ] ,
5559 public functionIndex : number
5660 ) {
5761 this . fullName = testBlockStack . map ( ( block ) => block . description ) . join ( " " ) ;
62+ this . setupFunctions = testBlockStack . flatMap ( ( block ) => block . setupFunctions ) ;
63+ this . teardownFunctions = testBlockStack . flatMap ( ( block ) => block . teardownFunctions ) ;
5864 }
5965}
6066
@@ -73,6 +79,30 @@ export class ExecutionRecorder implements UnitTestFramework {
7379 _removeDescription ( ) : void {
7480 this . testBlockStack . pop ( ) ;
7581 }
82+
83+ get lastTestBlock ( ) : TestBlock | undefined {
84+ return this . testBlockStack [ this . testBlockStack . length - 1 ] ;
85+ }
86+ // return false if error
87+ _registerSetup ( functionIndex : number ) : boolean {
88+ const lastTestBlock = this . lastTestBlock ;
89+ if ( lastTestBlock === undefined ) {
90+ return false ;
91+ } else {
92+ lastTestBlock . setupFunctions . push ( functionIndex ) ;
93+ return true ;
94+ }
95+ }
96+ // return false if error
97+ _registerTeardown ( functionIndex : number ) : boolean {
98+ const lastTestBlock = this . lastTestBlock ;
99+ if ( lastTestBlock === undefined ) {
100+ return false ;
101+ } else {
102+ lastTestBlock . teardownFunctions . push ( functionIndex ) ;
103+ return true ;
104+ }
105+ }
76106 _addTestCase ( functionIndex : number ) : void {
77107 this . testCases . push ( new TestCase ( this . testBlockStack , functionIndex ) ) ;
78108 }
@@ -128,6 +158,12 @@ export class ExecutionRecorder implements UnitTestFramework {
128158 registerTestFunction : ( index : number ) : void => {
129159 this . _addTestCase ( index ) ;
130160 } ,
161+ registerBeforeEachFunction : ( index : number ) : boolean => {
162+ return this . _registerSetup ( index ) ;
163+ } ,
164+ registerAfterEachFunction : ( index : number ) : boolean => {
165+ return this . _registerTeardown ( index ) ;
166+ } ,
131167 collectCheckResult : ( result : number , codeInfoIndex : number , actualValue : number , expectValue : number ) : void => {
132168 this . collectCheckResult (
133169 result !== 0 ,
0 commit comments