"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var mock_ws_exports = {};
__export(mock_ws_exports, {
  MockWebSocket: () => MockWebSocket
});
module.exports = __toCommonJS(mock_ws_exports);
var import_node_events = require("node:events");
class MockWebSocket extends import_node_events.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)));
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  MockWebSocket
});
//# sourceMappingURL=_mock_ws.cjs.map