@@ -139,6 +139,16 @@ export function pushTestResult() {
139
139
}
140
140
}
141
141
142
+ type TestemCallback = ( config : any , data : any , callback : ( ) => void ) => void ;
143
+
144
+ declare global {
145
+ interface Window {
146
+ Testem ?: {
147
+ afterTests : ( callback : TestemCallback ) => void ;
148
+ } ;
149
+ }
150
+ }
151
+
142
152
/**
143
153
* Sets up the middleware reporter, which reports results when the test suite is done.
144
154
*/
@@ -149,15 +159,28 @@ export function setupMiddlewareReporter() {
149
159
150
160
QUnit . testDone ( pushTestResult ) ;
151
161
152
- QUnit . done ( async function ( ) {
153
- let response = await fetch ( '/report-violations' , {
154
- method : 'POST' ,
155
- headers : {
156
- 'Content-Type' : 'application/json' ,
157
- } ,
158
- body : JSON . stringify ( TEST_SUITE_RESULTS ) ,
162
+ if ( window . Testem ) {
163
+ window . Testem . afterTests ( async function ( _config , _data , callback ) {
164
+ try {
165
+ await sendViolationsToServer ( ) ;
166
+ } finally {
167
+ callback ( ) ;
168
+ }
169
+ } ) ;
170
+ } else {
171
+ QUnit . done ( async function ( ) {
172
+ await sendViolationsToServer ( ) ;
159
173
} ) ;
174
+ }
175
+ }
160
176
161
- return response . json ( ) ;
177
+ async function sendViolationsToServer ( ) {
178
+ let response = await fetch ( '/report-violations' , {
179
+ method : 'POST' ,
180
+ headers : {
181
+ 'Content-Type' : 'application/json' ,
182
+ } ,
183
+ body : JSON . stringify ( TEST_SUITE_RESULTS ) ,
162
184
} ) ;
185
+ return response . json ( ) ;
163
186
}
0 commit comments