Skip to content

Commit 7e63cf5

Browse files
authored
fix(nodejs): fixing tests (#46)
* fix(nodejs): fixing tests * change version back to 3.0.0, so the client cannot be released accidentally * add todo to investigate flapping test
1 parent 9018102 commit 7e63cf5

File tree

6 files changed

+102
-156
lines changed

6 files changed

+102
-156
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@questdb/nodejs-client",
3-
"version": "4.0.0",
3+
"version": "3.0.0",
44
"description": "QuestDB Node.js Client",
55
"scripts": {
66
"test": "vitest",

src/sender.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const RETRIABLE_STATUS_CODES = [500, 503, 504, 507, 509, 523, 524, 529, 599];
8181
* </p>
8282
* <p>
8383
* It is recommended that the Sender is created by using one of the static factory methods,
84-
* <i>Sender.fromConfig(configString, extraOptions)</i> or <i>Sender.fromEnv(extraOptions)</i>).
84+
* <i>Sender.fromConfig(configString, extraOptions)</i> or <i>Sender.fromEnv(extraOptions)</i>.
8585
* If the Sender is created via its constructor, at least the SenderOptions configuration object should be
8686
* initialized from a configuration string to make sure that the parameters are validated. <br>
8787
* Detailed description of the Sender's configuration options can be found in
@@ -407,7 +407,7 @@ class Sender {
407407
"info",
408408
`Authenticating with ${(connectOptions as tls.ConnectionOptions).host}:${(connectOptions as tls.ConnectionOptions).port}`,
409409
);
410-
await this.socket.write(`${this.jwk.kid}\n`, (err) => {
410+
await this.socket.write(`${this.jwk.kid}\n`, (err: Error) => {
411411
if (err) {
412412
reject(err);
413413
}
@@ -570,7 +570,7 @@ class Sender {
570570
throw new Error("Sender is not connected");
571571
}
572572
return new Promise((resolve, reject) => {
573-
this.socket.write(dataToSend, (err) => { // Use the copied dataToSend
573+
this.socket.write(dataToSend, (err: Error) => { // Use the copied dataToSend
574574
if (err) {
575575
reject(err);
576576
} else {
@@ -614,7 +614,7 @@ class Sender {
614614
* If the last row is not finished it stays in the sender's buffer.
615615
* This operation is added to a queue and executed sequentially.
616616
*
617-
* @return {Promise<boolean>} Resolves to true when there was data in the buffer to send and it was sent successfully.
617+
* @return {Promise<boolean>} Resolves to true when there was data in the buffer to send, and it was sent successfully.
618618
*/
619619
async flush(): Promise<boolean> {
620620
// Add to the promise chain to ensure sequential execution
@@ -626,7 +626,7 @@ class Sender {
626626
}
627627
return this._executeFlush();
628628
})
629-
.catch((err) => {
629+
.catch((err: Error) => {
630630
// Log or handle error. If _executeFlush throws, it will be caught here.
631631
// The error should have already been logged by _executeFlush.
632632
// We re-throw to ensure the promise chain reflects the failure.
@@ -893,7 +893,7 @@ async function authenticate(
893893
return new Promise((resolve, reject) => {
894894
sender.socket.write(
895895
`${Buffer.from(signature).toString("base64")}\n`,
896-
(err) => {
896+
(err: Error) => {
897897
if (err) {
898898
reject(err);
899899
} else {

test/_utils_/mockhttp.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@ import http from "node:http";
22
import https from "node:https";
33

44
class MockHttp {
5-
server;
6-
mockConfig;
7-
numOfRequests;
5+
server: http.Server | https.Server;
6+
mockConfig: {
7+
responseDelays?: number[],
8+
responseCodes?: number[],
9+
username?: string,
10+
password?: string,
11+
token?: string,
12+
};
13+
numOfRequests: number;
814

915
constructor() {
1016
this.reset();
@@ -15,7 +21,7 @@ class MockHttp {
1521
this.numOfRequests = 0;
1622
}
1723

18-
async start(listenPort, secure = false, options?: Record<string, unknown>) {
24+
async start(listenPort: number, secure: boolean = false, options?: Record<string, unknown>) {
1925
const serverCreator = secure ? https.createServer : http.createServer;
2026
// @ts-expect-error - Testing different options, so typing is not important
2127
this.server = serverCreator(options, (req, res) => {

test/options.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,9 @@ describe("Configuration string parser suite", function () {
376376
expect(() => SenderOptions.fromConfig("")).toThrow(
377377
"Configuration string is missing",
378378
);
379-
// @ts-expect-error - Testing invalid input
380379
expect(() => SenderOptions.fromConfig(null)).toThrow(
381380
"Configuration string is missing",
382381
);
383-
// @ts-expect-error - Testing invalid input
384382
expect(() => SenderOptions.fromConfig(undefined)).toThrow(
385383
"Configuration string is missing",
386384
);

0 commit comments

Comments
 (0)