Skip to content

Commit 76c0888

Browse files
committed
feat(app): listen on a port for the app to make openapi testing work properly
1 parent b5cad22 commit 76c0888

File tree

3 files changed

+414
-696
lines changed

3 files changed

+414
-696
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,21 +52,21 @@
5252
"devDependencies": {
5353
"@commitlint/cli": "^19.3.0",
5454
"@commitlint/config-conventional": "^19.2.2",
55-
"@openapi-typescript-infra/coconfig": "^4.3.0",
56-
"@openapi-typescript-infra/service": "^4.16.0",
55+
"@openapi-typescript-infra/coconfig": "^4.4.0",
56+
"@openapi-typescript-infra/service": "^4.18.0",
5757
"@semantic-release/changelog": "^6.0.3",
5858
"@semantic-release/commit-analyzer": "^12.0.0",
5959
"@semantic-release/exec": "^6.0.3",
6060
"@semantic-release/git": "^10.0.1",
6161
"@semantic-release/release-notes-generator": "^13.0.0",
6262
"@typescript-eslint/eslint-plugin": "^6.21.0",
6363
"@typescript-eslint/parser": "^6.21.0",
64-
"@vitest/coverage-v8": "1.3.1",
64+
"@vitest/coverage-v8": "1.5.2",
6565
"coconfig": "^1.5.2",
6666
"eslint-config-prettier": "^9.1.0",
6767
"eslint-plugin-import": "^2.29.1",
6868
"ts-node": "^10.9.2",
69-
"vitest": "1.3.1"
69+
"vitest": "1.5.2"
7070
},
7171
"dependencies": {
7272
"@types/supertest": "^6.0.2",

src/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import http from 'http';
12
import path from 'path';
23
import assert from 'assert';
34

@@ -6,7 +7,7 @@ import request from 'supertest';
67
// register hook to allow require to resolve these modules
78
import { register } from 'ts-node';
89
import readPackageUp from 'read-pkg-up';
9-
import { shutdownApp, startApp } from '@openapi-typescript-infra/service';
10+
import { listen, startApp } from '@openapi-typescript-infra/service';
1011
import type {
1112
Service,
1213
RequestLocals,
@@ -20,6 +21,7 @@ import type {
2021

2122
let app: ServiceExpress | undefined;
2223
let appService: ServiceFactory<ServiceLocals, RequestLocals> | undefined;
24+
let listener: http.Server | undefined;
2325

2426
register();
2527
require('tsconfig-paths/register');
@@ -148,6 +150,7 @@ export async function getReusableApp<
148150
});
149151
appService = options.service as ServiceFactory<ServiceLocals, RequestLocals>;
150152
app = typedApp;
153+
listener = await listen(typedApp);
151154
}
152155
return typedApp;
153156
} catch (error) {
@@ -158,12 +161,14 @@ export async function getReusableApp<
158161
}
159162

160163
export async function clearReusableApp() {
161-
const oldApp = app;
164+
const oldListener = listener;
162165
app = undefined;
163166
appService = undefined;
164167
try {
165-
if (oldApp) {
166-
await shutdownApp(oldApp);
168+
if (oldListener) {
169+
return new Promise((resolve) => {
170+
oldListener?.close(resolve);
171+
});
167172
}
168173
} catch (error) {
169174
// eslint-disable-next-line no-console

0 commit comments

Comments
 (0)