Files
bun.sh/test/js/third_party/socket.io/socket.io-socket-middleware.test.ts
Jarred Sumner e848c3f226 Get Bun.write tests to pass on Windows and bun:sqlite tests to pass (#8393)
* Move ReadFile and WriteFile to separate file

* Use libuv for Bun.write()

* Update windows_event_loop.zig

* build

* Get bun-write tests to pass. Implement Bun.write with two files.

* UPdate

* Update

* Update failing test list

* update

* More

* More

* More

* More

* Mark the rest

* ok

* oops

* Update bun-write.test.js

* Update blob.zig

---------

Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Co-authored-by: Dave Caruso <me@paperdave.net>
Co-authored-by: Georgijs Vilums <georgijs.vilums@gmail.com>
2024-01-23 20:03:56 -08:00

90 lines
2.4 KiB
TypeScript

// TODO: uncomment when Blob bug in isBinary is fixed
import { Server } from "socket.io";
import { describe, it, expect } from "bun:test";
import { success, fail, createClient } from "./support/util.ts";
describe("socket middleware", () => {
it.skip("should call functions", done => {
const io = new Server(0);
const clientSocket = createClient(io, "/", { multiplex: false });
const timeout = setTimeout(() => {
fail(done, io, new Error("timeout"), clientSocket);
}, 200);
clientSocket.emit("join", "woot");
let run = 0;
io.on("connection", socket => {
socket.use((event, next) => {
try {
expect(event).toStrictEqual(["join", "woot"]);
event.unshift("wrap");
run++;
next();
} catch (err) {
clearTimeout(timeout);
fail(done, io, err, clientSocket);
}
});
socket.use((event, next) => {
try {
expect(event).toStrictEqual(["wrap", "join", "woot"]);
run++;
next();
} catch (err) {
clearTimeout(timeout);
fail(done, io, err, clientSocket);
}
});
socket.on("wrap", (data1, data2) => {
try {
clearTimeout(timeout);
expect(data1).toBe("join");
expect(data2).toBe("woot");
expect(run).toBe(2);
success(done, io, clientSocket);
} catch (err) {
fail(done, io, err, clientSocket);
}
});
});
});
it.skip("should pass errors", done => {
const io = new Server(0);
const clientSocket = createClient(io, "/", { multiplex: false });
const timeout = setTimeout(() => {
fail(done, io, new Error("timeout"), clientSocket);
}, 200);
clientSocket.emit("join", "woot");
io.on("connection", socket => {
socket.use((event, next) => {
next(new Error("Authentication error"));
});
socket.use((event, next) => {
done(new Error("should not happen"));
});
socket.on("join", () => {
done(new Error("should not happen"));
});
socket.on("error", err => {
try {
clearTimeout(timeout);
expect(err).toBeInstanceOf(Error);
expect(err.message).toBe("Authentication error");
success(done, io, clientSocket);
} catch (err) {
fail(done, io, err, clientSocket);
}
});
});
});
});