Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit 05987bd

Browse files
committed
add a client.close call to the tests
1 parent ed162de commit 05987bd

File tree

7 files changed

+40
-1
lines changed

7 files changed

+40
-1
lines changed

axios.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe("Axios Interceptors", () => {
8282
expect(JSON.stringify(response.body)).toBe(JSON.stringify({ ping: "pong" }));
8383
expect(published).toBe(true);
8484
expect(pingCalled).toBe(true);
85+
await client.close();
8586
});
8687
it("should intercept axios via responseError", async () => {
8788
let published = false;
@@ -124,5 +125,6 @@ describe("Axios Interceptors", () => {
124125
expect(JSON.stringify(response.body)).toBe(JSON.stringify({ hello: "error" }));
125126
// expect(published).toBe(true)
126127
// expect(pingCalled).toBe(true)
128+
await client.close();
127129
});
128130
});

axios.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ describe("Axios Interceptors", () => {
6262
expect(JSON.stringify(response.body)).toBe(JSON.stringify({ ping: "pong" }));
6363
expect(published).toBe(true);
6464
expect(pingCalled).toBe(true);
65+
66+
await client.close();
6567
});
6668

6769
it("should intercept axios via responseError", async () => {
@@ -113,5 +115,7 @@ describe("Axios Interceptors", () => {
113115
expect(JSON.stringify(response.body)).toBe(JSON.stringify({ hello: "error" }));
114116
// expect(published).toBe(true)
115117
// expect(pingCalled).toBe(true)
118+
119+
await client.close();
116120
});
117121
});

index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ class APIToolkit {
7474
}
7575
return new APIToolkit(pubsubClient, topic_id, project_id, config);
7676
}
77+
async close() {
78+
await __classPrivateFieldGet(this, _APIToolkit_topic, "f")?.flush();
79+
await __classPrivateFieldGet(this, _APIToolkit_pubsub, "f")?.close();
80+
}
7781
static async getClientMetadata(rootURL, apiKey) {
7882
const resp = await (0, node_fetch_1.default)(rootURL + "/api/client_metadata", {
7983
method: "GET",

index.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ describe("Express SDK API Tests", () => {
9696
expect(response.status).toBe(200);
9797
expect(response.body.status).toBe("success");
9898
expect(published).toBe(true);
99+
await client.close();
99100
});
100101
it("should get data", async () => {
101102
const app = (0, express_1.default)();
@@ -138,6 +139,7 @@ describe("Express SDK API Tests", () => {
138139
expect(response.status).toBe(200);
139140
expect(JSON.stringify(response.body)).toBe(JSON.stringify(exampleRequestData));
140141
expect(published).toBe(true);
142+
await client.close();
141143
});
142144
it("should check sub routes", async () => {
143145
const app = (0, express_1.default)();
@@ -174,6 +176,7 @@ describe("Express SDK API Tests", () => {
174176
expect(response.status).toBe(200);
175177
expect(JSON.stringify(response.body)).toBe(JSON.stringify(exampleRequestData));
176178
expect(published).toBe(true);
179+
await client.close();
177180
});
178181
it("should check sub sub sub routes", async () => {
179182
const app = (0, express_1.default)();
@@ -214,6 +217,7 @@ describe("Express SDK API Tests", () => {
214217
expect(response.status).toBe(200);
215218
expect(JSON.stringify(response.body)).toBe(JSON.stringify(exampleRequestData));
216219
expect(published).toBe(true);
220+
await client.close();
217221
});
218222
it("should ignore path for endpoins with OPTION", async () => {
219223
const app = (0, express_1.default)();
@@ -250,6 +254,7 @@ describe("Express SDK API Tests", () => {
250254
expect(response.status).toBe(200);
251255
expect(response.body.message).toBe("OPTIONS ignored");
252256
expect(published).toBe(true);
257+
await client.close();
253258
});
254259
});
255260
describe("File Upload Endpoint", () => {
@@ -311,6 +316,7 @@ describe("File Upload Endpoint", () => {
311316
expect(response.status).toBe(200);
312317
expect(response.body.message).toBe("File upload successful.");
313318
expect(published).toBe(true);
319+
await client.close();
314320
});
315321
it("should upload files (formidable)", async () => {
316322
const app = (0, express_1.default)();
@@ -362,6 +368,7 @@ describe("File Upload Endpoint", () => {
362368
expect(response.status).toBe(200);
363369
expect(response.body.message).toBe("Uploaded successfully");
364370
expect(published).toBe(true);
371+
await client.close();
365372
});
366373
it("should upload files (busboy)", async () => {
367374
const app = (0, express_1.default)();
@@ -422,6 +429,7 @@ describe("File Upload Endpoint", () => {
422429
expect(response.status).toBe(200);
423430
expect(response.body.message).toBe("Uploaded successfully");
424431
expect(published).toBe(true);
432+
await client.close();
425433
});
426434
});
427435
describe("testing headers and jsonpath redaction", () => {

index.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ describe("Express SDK API Tests", () => {
7878
expect(response.status).toBe(200);
7979
expect(response.body.status).toBe("success");
8080
expect(published).toBe(true);
81+
82+
await client.close()
8183
});
8284

8385
it("should get data", async () => {
@@ -126,6 +128,8 @@ describe("Express SDK API Tests", () => {
126128
expect(response.status).toBe(200);
127129
expect(JSON.stringify(response.body)).toBe(JSON.stringify(exampleRequestData));
128130
expect(published).toBe(true);
131+
132+
await client.close()
129133
});
130134

131135
it("should check sub routes", async () => {
@@ -167,6 +171,8 @@ describe("Express SDK API Tests", () => {
167171
expect(response.status).toBe(200);
168172
expect(JSON.stringify(response.body)).toBe(JSON.stringify(exampleRequestData));
169173
expect(published).toBe(true);
174+
175+
await client.close()
170176
});
171177

172178
it("should check sub sub sub routes", async () => {
@@ -212,6 +218,8 @@ describe("Express SDK API Tests", () => {
212218
expect(response.status).toBe(200);
213219
expect(JSON.stringify(response.body)).toBe(JSON.stringify(exampleRequestData));
214220
expect(published).toBe(true);
221+
222+
await client.close()
215223
});
216224

217225
it("should ignore path for endpoins with OPTION", async () => {
@@ -251,6 +259,8 @@ describe("Express SDK API Tests", () => {
251259
expect(response.status).toBe(200);
252260
expect(response.body.message).toBe("OPTIONS ignored");
253261
expect(published).toBe(true);
262+
263+
await client.close()
254264
});
255265
});
256266

@@ -325,6 +335,8 @@ describe("File Upload Endpoint", () => {
325335
expect(response.status).toBe(200);
326336
expect(response.body.message).toBe("File upload successful.");
327337
expect(published).toBe(true);
338+
339+
await client.close()
328340
});
329341

330342
it("should upload files (formidable)", async () => {
@@ -379,6 +391,8 @@ describe("File Upload Endpoint", () => {
379391
expect(response.status).toBe(200);
380392
expect(response.body.message).toBe("Uploaded successfully");
381393
expect(published).toBe(true);
394+
395+
await client.close()
382396
});
383397

384398
it("should upload files (busboy)", async () => {
@@ -443,6 +457,8 @@ describe("File Upload Endpoint", () => {
443457
expect(response.status).toBe(200);
444458
expect(response.body.message).toBe("Uploaded successfully");
445459
expect(published).toBe(true);
460+
461+
await client.close()
446462
});
447463
});
448464

index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ export class APIToolkit {
9090
return new APIToolkit(pubsubClient, topic_id, project_id, config);
9191
}
9292

93+
public async close(){
94+
await this.#topic?.flush();
95+
await this.#pubsub?.close();
96+
}
97+
9398
static async getClientMetadata(rootURL: string, apiKey: string) {
9499
const resp = await fetch(rootURL + "/api/client_metadata", {
95100
method: "GET",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "apitoolkit-express",
3-
"version": "1.1.20",
3+
"version": "1.1.21",
44
"description": "",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)