import { EventEmitter } from "node:events";
class MockWebSocket extends EventEmitter {
  constructor(url, opts) {
    super();
    this.url = url;
    this.opts = opts;
    MockWebSocket.instances.push(this);
  }
  static OPEN = 1;
  static instances = [];
  readyState = 0;
  // CONNECTING
  sent = [];
  terminated = false;
  send(data) {
    this.sent.push(data);
  }
  close() {
    this.readyState = 3;
    this.emit("close", 1e3, Buffer.from(""));
  }
  terminate() {
    this.terminated = true;
    this.readyState = 3;
  }
  /** Simulate a successful upgrade. */
  simulateOpen() {
    this.readyState = MockWebSocket.OPEN;
    this.emit("open");
  }
  /** Simulate the server rejecting the upgrade with an HTTP status. */
  simulateUnexpectedResponse(statusCode) {
    this.emit("unexpected-response", {}, { statusCode });
  }
  /** Simulate a server message frame carrying a JSON payload. */
  simulateMessage(payload) {
    this.emit("message", Buffer.from(JSON.stringify(payload)));
  }
}
export {
  MockWebSocket
};
//# sourceMappingURL=_mock_ws.js.map