Skip to content
Open
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
28 changes: 22 additions & 6 deletions test/e2e/__snapshots__/client.test.js.snap.webpack5
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing

exports[`client option configure client entry should disable client entry: console messages 1`] = `[]`;
exports[`client option configure client entry should disable client entry: console messages 1`] = `
[
"Failed to load resource: the server responded with a status of 404 (Not Found)",
]
`;

exports[`client option configure client entry should disable client entry: page errors 1`] = `[]`;

exports[`client option configure client entry should disable client entry: response status 1`] = `200`;

exports[`client option default behaviour responds with a 200 status code for /ws path: console messages 1`] = `[]`;
exports[`client option configure client entry should disable client entry: webSockets 1`] = `[]`;

exports[`client option default behaviour responds with a 200 status code for /ws path: page errors 1`] = `[]`;
exports[`client option default behaviour responds with a 200 status code for / path: console messages 1`] = `
[
"Failed to load resource: the server responded with a status of 404 (Not Found)",
]
`;

exports[`client option default behaviour responds with a 200 status code for /ws path: response status 1`] = `200`;
exports[`client option default behaviour responds with a 200 status code for / path: page errors 1`] = `[]`;

exports[`client option default behaviour responds with a 200 status code for / path: response status 1`] = `404`;

exports[`client option default behaviour responds with a 200 status code for / path: webSockets 1`] = `[]`;

exports[`client option override client entry should disable client entry: response status 1`] = `200`;

exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: console messages 1`] = `[]`;
exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: console messages 1`] = `
[
"Failed to load resource: the server responded with a status of 404 (Not Found)",
]
`;

exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: page errors 1`] = `[]`;

exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: response status 1`] = `200`;
exports[`client option should respect path option responds with a 200 status code for /foo/test/bar path: webSockets 1`] = `[]`;
57 changes: 57 additions & 0 deletions tmp-client/clients/WebSocketClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { log } from "../utils/log.js";

/** @typedef {import("../index").EXPECTED_ANY} EXPECTED_ANY */

/**
* @implements {CommunicationClient}
*/
var WebSocketClient = /*#__PURE__*/function () {
/**
* @param {string} url url to connect
*/
function WebSocketClient(url) {
_classCallCheck(this, WebSocketClient);
this.client = new WebSocket(url);
this.client.onerror = function (error) {
log.error(error);
};
}

/**
* @param {(...args: EXPECTED_ANY[]) => void} fn function
*/
return _createClass(WebSocketClient, [{
key: "onOpen",
value: function onOpen(fn) {
this.client.onopen = fn;
}

/**
* @param {(...args: EXPECTED_ANY[]) => void} fn function
*/
}, {
key: "onClose",
value: function onClose(fn) {
this.client.onclose = fn;
}

// call f with the message string as the first argument
/**
* @param {(...args: EXPECTED_ANY[]) => void} fn function
*/
}, {
key: "onMessage",
value: function onMessage(fn) {
this.client.onmessage = function (err) {
fn(err.data);
};
}
}]);
}();
export { WebSocketClient as default };
Loading