1
+ import http from 'http' ;
1
2
import path from 'path' ;
2
3
import assert from 'assert' ;
3
4
@@ -6,7 +7,7 @@ import request from 'supertest';
6
7
// register hook to allow require to resolve these modules
7
8
import { register } from 'ts-node' ;
8
9
import readPackageUp from 'read-pkg-up' ;
9
- import { shutdownApp , startApp } from '@openapi-typescript-infra/service' ;
10
+ import { listen , startApp } from '@openapi-typescript-infra/service' ;
10
11
import type {
11
12
Service ,
12
13
RequestLocals ,
@@ -20,6 +21,7 @@ import type {
20
21
21
22
let app : ServiceExpress | undefined ;
22
23
let appService : ServiceFactory < ServiceLocals , RequestLocals > | undefined ;
24
+ let listener : http . Server | undefined ;
23
25
24
26
register ( ) ;
25
27
require ( 'tsconfig-paths/register' ) ;
@@ -148,6 +150,7 @@ export async function getReusableApp<
148
150
} ) ;
149
151
appService = options . service as ServiceFactory < ServiceLocals , RequestLocals > ;
150
152
app = typedApp ;
153
+ listener = await listen ( typedApp ) ;
151
154
}
152
155
return typedApp ;
153
156
} catch ( error ) {
@@ -158,12 +161,14 @@ export async function getReusableApp<
158
161
}
159
162
160
163
export async function clearReusableApp ( ) {
161
- const oldApp = app ;
164
+ const oldListener = listener ;
162
165
app = undefined ;
163
166
appService = undefined ;
164
167
try {
165
- if ( oldApp ) {
166
- await shutdownApp ( oldApp ) ;
168
+ if ( oldListener ) {
169
+ return new Promise ( ( resolve ) => {
170
+ oldListener ?. close ( resolve ) ;
171
+ } ) ;
167
172
}
168
173
} catch ( error ) {
169
174
// eslint-disable-next-line no-console
0 commit comments