Skip to content

fix(nodejs): fixing tests #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@questdb/nodejs-client",
"version": "4.0.0",
"version": "3.0.0",
"description": "QuestDB Node.js Client",
"scripts": {
"test": "vitest",
Expand Down
12 changes: 6 additions & 6 deletions src/sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const RETRIABLE_STATUS_CODES = [500, 503, 504, 507, 509, 523, 524, 529, 599];
* </p>
* <p>
* It is recommended that the Sender is created by using one of the static factory methods,
* <i>Sender.fromConfig(configString, extraOptions)</i> or <i>Sender.fromEnv(extraOptions)</i>).
* <i>Sender.fromConfig(configString, extraOptions)</i> or <i>Sender.fromEnv(extraOptions)</i>.
* If the Sender is created via its constructor, at least the SenderOptions configuration object should be
* initialized from a configuration string to make sure that the parameters are validated. <br>
* Detailed description of the Sender's configuration options can be found in
Expand Down Expand Up @@ -407,7 +407,7 @@ class Sender {
"info",
`Authenticating with ${(connectOptions as tls.ConnectionOptions).host}:${(connectOptions as tls.ConnectionOptions).port}`,
);
await this.socket.write(`${this.jwk.kid}\n`, (err) => {
await this.socket.write(`${this.jwk.kid}\n`, (err: Error) => {
if (err) {
reject(err);
}
Expand Down Expand Up @@ -570,7 +570,7 @@ class Sender {
throw new Error("Sender is not connected");
}
return new Promise((resolve, reject) => {
this.socket.write(dataToSend, (err) => { // Use the copied dataToSend
this.socket.write(dataToSend, (err: Error) => { // Use the copied dataToSend
if (err) {
reject(err);
} else {
Expand Down Expand Up @@ -614,7 +614,7 @@ class Sender {
* If the last row is not finished it stays in the sender's buffer.
* This operation is added to a queue and executed sequentially.
*
* @return {Promise<boolean>} Resolves to true when there was data in the buffer to send and it was sent successfully.
* @return {Promise<boolean>} Resolves to true when there was data in the buffer to send, and it was sent successfully.
*/
async flush(): Promise<boolean> {
// Add to the promise chain to ensure sequential execution
Expand All @@ -626,7 +626,7 @@ class Sender {
}
return this._executeFlush();
})
.catch((err) => {
.catch((err: Error) => {
// Log or handle error. If _executeFlush throws, it will be caught here.
// The error should have already been logged by _executeFlush.
// We re-throw to ensure the promise chain reflects the failure.
Expand Down Expand Up @@ -893,7 +893,7 @@ async function authenticate(
return new Promise((resolve, reject) => {
sender.socket.write(
`${Buffer.from(signature).toString("base64")}\n`,
(err) => {
(err: Error) => {
if (err) {
reject(err);
} else {
Expand Down
14 changes: 10 additions & 4 deletions test/_utils_/mockhttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ import http from "node:http";
import https from "node:https";

class MockHttp {
server;
mockConfig;
numOfRequests;
server: http.Server | https.Server;
mockConfig: {
responseDelays?: number[],
responseCodes?: number[],
username?: string,
password?: string,
token?: string,
};
numOfRequests: number;

constructor() {
this.reset();
Expand All @@ -15,7 +21,7 @@ class MockHttp {
this.numOfRequests = 0;
}

async start(listenPort, secure = false, options?: Record<string, unknown>) {
async start(listenPort: number, secure: boolean = false, options?: Record<string, unknown>) {
const serverCreator = secure ? https.createServer : http.createServer;
// @ts-expect-error - Testing different options, so typing is not important
this.server = serverCreator(options, (req, res) => {
Expand Down
2 changes: 0 additions & 2 deletions test/options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,9 @@ describe("Configuration string parser suite", function () {
expect(() => SenderOptions.fromConfig("")).toThrow(
"Configuration string is missing",
);
// @ts-expect-error - Testing invalid input
expect(() => SenderOptions.fromConfig(null)).toThrow(
"Configuration string is missing",
);
// @ts-expect-error - Testing invalid input
expect(() => SenderOptions.fromConfig(undefined)).toThrow(
"Configuration string is missing",
);
Expand Down
Loading