Skip to content

Commit dcc7f5d

Browse files
🤖 dprint fmt
1 parent 73ca7f6 commit dcc7f5d

4 files changed

Lines changed: 143 additions & 145 deletions

File tree

types/k6__x__socketio/index.d.ts

Lines changed: 94 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,114 +1,113 @@
1-
21
declare module "k6/x/socketio" {
3-
interface SocketIOOptions {
4-
/**
5-
* Socket.IO path (default: "/socket.io/")
6-
*/
7-
path?: string;
8-
/**
9-
* Namespace to connect to (default: "/")
10-
* Example: "/chat"
11-
*/
12-
namespace?: string;
13-
/**
14-
* Auth payload sent in the connect packet
15-
*/
16-
auth?: Record<string, any>;
17-
/**
18-
* Query parameters appended to the URL
19-
*/
20-
query?: Record<string, any>;
21-
/**
22-
* Passed directly to k6/ws.connect
23-
*/
24-
params?: {
25-
/** Request headers. */
26-
headers?: { [name: string]: string };
2+
interface SocketIOOptions {
3+
/**
4+
* Socket.IO path (default: "/socket.io/")
5+
*/
6+
path?: string;
7+
/**
8+
* Namespace to connect to (default: "/")
9+
* Example: "/chat"
10+
*/
11+
namespace?: string;
12+
/**
13+
* Auth payload sent in the connect packet
14+
*/
15+
auth?: Record<string, any>;
16+
/**
17+
* Query parameters appended to the URL
18+
*/
19+
query?: Record<string, any>;
20+
/**
21+
* Passed directly to k6/ws.connect
22+
*/
23+
params?: {
24+
/** Request headers. */
25+
headers?: { [name: string]: string };
2726

28-
/**
29-
* Compression algorithm. The only supported algorithm is `deflate`.
30-
* If the option is left unset or empty, it defaults to no compression.
31-
*/
32-
compression?: string;
27+
/**
28+
* Compression algorithm. The only supported algorithm is `deflate`.
29+
* If the option is left unset or empty, it defaults to no compression.
30+
*/
31+
compression?: string;
3332

34-
/** Response time metric tags. */
35-
tags?: { [name: string]: string };
36-
};
37-
}
33+
/** Response time metric tags. */
34+
tags?: { [name: string]: string };
35+
};
36+
}
3837

39-
/**
40-
* Socket.IO socket wrapper
41-
*
42-
* Provides Socket.IO-like API on top of k6/ws WebSocket connection.
43-
* Socket.IO-specific methods (on, emit, send) override the original k6/ws methods.
44-
* All other k6/ws socket methods are available as-is via the wrapper.
45-
*/
46-
interface Socket {
4738
/**
39+
* Socket.IO socket wrapper
40+
*
41+
* Provides Socket.IO-like API on top of k6/ws WebSocket connection.
42+
* Socket.IO-specific methods (on, emit, send) override the original k6/ws methods.
43+
* All other k6/ws socket methods are available as-is via the wrapper.
44+
*/
45+
interface Socket {
46+
/**
4847
* Register an event handler (Socket.IO version)
4948
* Overrides the original k6/ws on() method
5049
*
5150
* @param event - Event name ("connect", "disconnect", or custom event)
5251
* @param handler - Handler function that receives event data
5352
*/
54-
on(event: string, handler: (data?: any) => void): void;
53+
on(event: string, handler: (data?: any) => void): void;
5554

56-
/**
57-
* Emit an event to the server (Socket.IO specific)
58-
*
59-
* @param event - Event name
60-
* @param data - Optional data to send with the event
61-
*/
62-
emit(event: string, data?: any): void;
55+
/**
56+
* Emit an event to the server (Socket.IO specific)
57+
*
58+
* @param event - Event name
59+
* @param data - Optional data to send with the event
60+
*/
61+
emit(event: string, data?: any): void;
6362

64-
/**
65-
* Send data (Socket.IO version - alias for emit("message", data))
66-
* Overrides the original k6/ws send() method
67-
*
68-
* @param data - Data to send
69-
*/
70-
send(data: any): void;
63+
/**
64+
* Send data (Socket.IO version - alias for emit("message", data))
65+
* Overrides the original k6/ws send() method
66+
*
67+
* @param data - Data to send
68+
*/
69+
send(data: any): void;
7170

72-
/**
73-
* Close connection.
74-
* https://grafana.com/docs/k6/latest/javascript-api/k6-ws/socket/socket-close/
75-
*
76-
* @param code - WebSocket status code.
77-
* @example
78-
* socket.close();
79-
*/
80-
close(code?: number): void;
81-
}
71+
/**
72+
* Close connection.
73+
* https://grafana.com/docs/k6/latest/javascript-api/k6-ws/socket/socket-close/
74+
*
75+
* @param code - WebSocket status code.
76+
* @example
77+
* socket.close();
78+
*/
79+
close(code?: number): void;
80+
}
8281

83-
/**
84-
* Connect to a Socket.IO server
85-
*
86-
* @param host - Base URL such as "http://localhost:4000" or "wss://example.com"
87-
* @param options - Optional configuration
88-
* @param handler - Optional callback function called with a Socket.IO-like socket wrapper
89-
* @returns The underlying k6/ws.connect result
90-
*
91-
* @example
92-
* ```typescript
93-
* import { io } from "k6/x/socketio";
94-
*
95-
* io("http://localhost:4000", {}, (socket) => {
96-
* socket.on("connect", () => {
97-
* socket.emit("hello", { payload: "hi from k6" });
98-
* });
99-
* });
100-
* ```
101-
*/
102-
function io(
103-
host: string,
104-
options?: SocketIOOptions,
105-
handler?: (socket: Socket) => void
106-
): any;
82+
/**
83+
* Connect to a Socket.IO server
84+
*
85+
* @param host - Base URL such as "http://localhost:4000" or "wss://example.com"
86+
* @param options - Optional configuration
87+
* @param handler - Optional callback function called with a Socket.IO-like socket wrapper
88+
* @returns The underlying k6/ws.connect result
89+
*
90+
* @example
91+
* ```typescript
92+
* import { io } from "k6/x/socketio";
93+
*
94+
* io("http://localhost:4000", {}, (socket) => {
95+
* socket.on("connect", () => {
96+
* socket.emit("hello", { payload: "hi from k6" });
97+
* });
98+
* });
99+
* ```
100+
*/
101+
function io(
102+
host: string,
103+
options?: SocketIOOptions,
104+
handler?: (socket: Socket) => void,
105+
): any;
107106

108-
export { io, Socket, SocketIOOptions };
107+
export { io, Socket, SocketIOOptions };
109108
}
110109

111110
declare module "xk6-socketio" {
112-
import { io, Socket, SocketIOOptions } from "k6/x/socketio";
113-
export { io, Socket, SocketIOOptions };
114-
}
111+
import { io, Socket, SocketIOOptions } from "k6/x/socketio";
112+
export { io, Socket, SocketIOOptions };
113+
}

types/k6__x__socketio/k6__x__socketio-tests.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
import { io, type Socket, type SocketIOOptions } from "k6/x/socketio";
22

33
const opts: SocketIOOptions = {
4-
path: "/socket.io/",
5-
namespace: "/chat",
6-
auth: { token: "abc" },
7-
query: { a: 1 },
8-
params: {
9-
headers: { Authorization: "Bearer token" },
10-
compression: "deflate",
11-
tags: { name: "socketio" },
12-
},
4+
path: "/socket.io/",
5+
namespace: "/chat",
6+
auth: { token: "abc" },
7+
query: { a: 1 },
8+
params: {
9+
headers: { Authorization: "Bearer token" },
10+
compression: "deflate",
11+
tags: { name: "socketio" },
12+
},
1313
};
1414

1515
io("http://localhost:4000", opts, (socket: Socket) => {
16-
socket.on("connect", () => {});
17-
socket.on("hello", (data) => {
18-
const _x: any = data;
19-
});
16+
socket.on("connect", () => {});
17+
socket.on("hello", (data) => {
18+
const _x: any = data;
19+
});
2020

21-
socket.emit("hello", { payload: "hi from k6" });
22-
socket.send({ msg: "message" });
23-
24-
socket.close();
21+
socket.emit("hello", { payload: "hi from k6" });
22+
socket.send({ msg: "message" });
2523

24+
socket.close();
2625
});
2726

2827
// also works without options/handler

types/k6__x__socketio/package.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
{
2-
"name": "@types/k6__x__socketio",
3-
"version": "0.1.9999",
4-
"private": true,
5-
"nonNpm": true,
6-
"nonNpmDescription": "Type definitions for xk6 extension providing Socket.IO support in k6, not distributed via npm",
7-
"projects": ["https://github.com/XEmAX32/xk6-socket.io"],
8-
"owners": [
9-
{
10-
"name": "Emanuele Sacco",
11-
"url": "https://github.com/xemax32"
2+
"name": "@types/k6__x__socketio",
3+
"version": "0.1.9999",
4+
"private": true,
5+
"nonNpm": true,
6+
"nonNpmDescription": "Type definitions for xk6 extension providing Socket.IO support in k6, not distributed via npm",
7+
"projects": ["https://github.com/XEmAX32/xk6-socket.io"],
8+
"owners": [
9+
{
10+
"name": "Emanuele Sacco",
11+
"url": "https://github.com/xemax32"
12+
}
13+
],
14+
"dependencies": {
15+
"@types/k6": "*"
16+
},
17+
"devDependencies": {
18+
"@types/k6__x__socketio": "workspace:."
1219
}
13-
],
14-
"dependencies": {
15-
"@types/k6": "*"
16-
},
17-
"devDependencies": {
18-
"@types/k6__x__socketio": "workspace:."
19-
}
2020
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
{
2-
"compilerOptions": {
3-
"module": "node16",
4-
"lib": ["es2015"],
5-
"noEmit": true,
6-
"types": [],
7-
"forceConsistentCasingInFileNames": true,
8-
"noImplicitAny": true,
9-
"noImplicitThis": true,
10-
"strictNullChecks": true,
11-
"strictFunctionTypes": true
12-
},
13-
"files": [
14-
"index.d.ts",
15-
"k6__x__socketio-tests.ts"
16-
]
17-
}
2+
"compilerOptions": {
3+
"module": "node16",
4+
"lib": ["es2015"],
5+
"noEmit": true,
6+
"types": [],
7+
"forceConsistentCasingInFileNames": true,
8+
"noImplicitAny": true,
9+
"noImplicitThis": true,
10+
"strictNullChecks": true,
11+
"strictFunctionTypes": true
12+
},
13+
"files": [
14+
"index.d.ts",
15+
"k6__x__socketio-tests.ts"
16+
]
17+
}

0 commit comments

Comments
 (0)