@@ -100,7 +100,11 @@ export default function runTest(
100100 mapCoverage : globalConfig . mapCoverage ,
101101 } ) ;
102102 const start = Date . now ( ) ;
103- return testFramework ( globalConfig , config , environment , runtime , path )
103+ return ( environment . setup ? environment . setup ( ) : ( async ( ) => ( { } ) ) ( ) )
104+ . then ( testSetup => {
105+ setGlobal ( environment . global , 'setup' , testSetup ) ;
106+ return testFramework ( globalConfig , config , environment , runtime , path ) ;
107+ } )
104108 . then ( ( result : TestResult ) => {
105109 const testCount =
106110 result . numPassingTests +
@@ -117,22 +121,36 @@ export default function runTest(
117121 } )
118122 . then (
119123 result =>
120- Promise . resolve ( ) . then ( ( ) => {
121- environment . dispose ( ) ;
122- if ( globalConfig . logHeapUsage ) {
123- if ( global . gc ) {
124- global . gc ( ) ;
124+ Promise . resolve ( )
125+ . then (
126+ ( ) =>
127+ environment . teardown
128+ ? environment . teardown ( )
129+ : ( async ( ) => ( { } ) ) ( ) ,
130+ )
131+ . then ( ( ) => {
132+ environment . dispose ( ) ;
133+ if ( globalConfig . logHeapUsage ) {
134+ if ( global . gc ) {
135+ global . gc ( ) ;
136+ }
137+ result . memoryUsage = process . memoryUsage ( ) . heapUsed ;
125138 }
126- result . memoryUsage = process . memoryUsage ( ) . heapUsed ;
127- }
128139
129- // Delay the resolution to allow log messages to be output.
130- return new Promise ( resolve => setImmediate ( ( ) => resolve ( result ) ) ) ;
131- } ) ,
140+ // Delay the resolution to allow log messages to be output.
141+ return new Promise ( resolve => setImmediate ( ( ) => resolve ( result ) ) ) ;
142+ } ) ,
132143 err =>
133- Promise . resolve ( ) . then ( ( ) => {
134- environment . dispose ( ) ;
135- throw err ;
136- } ) ,
144+ Promise . resolve ( )
145+ . then (
146+ ( ) =>
147+ environment . teardown
148+ ? environment . teardown ( )
149+ : ( async ( ) => ( { } ) ) ( ) ,
150+ )
151+ . then ( ( ) => {
152+ environment . dispose ( ) ;
153+ throw err ;
154+ } ) ,
137155 ) ;
138156}
0 commit comments