
Security News
AGENTS.md Gains Traction as an Open Format for AI Coding Agents
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
phoenix-socket-mock
Advanced tools
Starts the server socket connection at the url passed, using mock-socket.
Provides out of the box handling of the built in phx_join
and heartbeat
events.
Responds to custom incoming messages from the client by applying the result of responsePayloadFunc
argument
Catches the "A mock server is already listening on this url" from mock-socket and logs a warning, but throws any other errors from mock-socket. This is because your testing framework may attempt to sockets connections to the same URL multiple times during a test run.
Kind: static method of phoenixMockSocket
Param | Type | Description |
---|---|---|
url | string | The url of the web socket connection to start. This should be the same as the url of the actual web socket connection that your client will attempt to join. |
responsePayloadFunc | function | Returns the payload to use in response to an incoming message from the client. Receives the incoming topic, eventName and payload as arguments, and must return the response payload in the form of an object. |
Example
import phoenixMockSocket from 'phoenix-socket-mock';
function myTest() {
const url = 'ws://localhost8000/socket/websocket';
const responsePayloadFunc = (topic, eventName, payload) => {
let responseString;
if (payload.message === 'One fish') {
responseString = 'Two fish';
} else if (payload.message === 'Red fish') {
responseString = 'Blue fish';
} else {
responseString = 'Unknown fish';
}
return {
response: { message: responseString },
};
};
phoenixMockSocket.initialise(url, responsePayloadFunc);
};
// Client code - this is only given as a reference for the above mock server code
import { Socket } from 'phoenix';
const socket = new Socket('ws://localhost8000/socket/websocket');
socket.connect();
const channel = socket.channel('my_topic');
if (channel.state !== 'joined') {
channel
.join()
.receive('ok', (resp) => {
console.log('Joined my_topic channel', resp);
})
.receive('error', (resp) => {
console.log('Unable to join my_topic channel', resp);
});
}
channel.push('my_event_name', {
message: 'One fish',
});
channel.push('my_event_name', {
message: 'Red fish',
});
channel.on('my_event_name', (payload) => {
console.log(payload); // First logs "Two fish", then "Blue fish"
});
Formats a push notification to be sent from the server to the client. Note that this is only used for unpromted push notifications from the server to the client, and not for responses to client messages.
Kind: static method of phoenixMockSocket
Param | Type | Description |
---|---|---|
topic | string | The channel topic to send the push notification to. |
eventName | string | The eventName of the notification |
payload | object | The payload to send to the client. |
Example
import phoenixMockSocket from 'phoenix-socket-mock';
const pushNotification = phoenixMockSocket.formatPushNotification('my_topic', 'my_event_name', {
message: 'This is a push notification from the server'
};
Formats a push notification to be sent from the server to the client. Note that this is only used for unpromted push notifications from the server to the client, and not for responses to client messages.
Kind: static method of phoenixMockSocket
Param | Type | Description |
---|---|---|
message | string | The formatted message to send to the client (See formatPushNotification). |
Example
import phoenixMockSocket from 'phoenix-socket-mock';
const pushNotification = phoenixMockSocket.formatPushNotification('my_topic', 'my_event_name', {
message: 'This is a push notification from the server'
};
phoenixMockSocket.sendPushNotification(pushNotification);
FAQs
Unknown package
The npm package phoenix-socket-mock receives a total of 0 weekly downloads. As such, phoenix-socket-mock popularity was classified as not popular.
We found that phoenix-socket-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.
Security News
/Research
Malicious npm package impersonates Nodemailer and drains wallets by hijacking crypto transactions across multiple blockchains.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.