Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

can-fixture-socket

Package Overview
Dependencies
Maintainers
7
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-fixture-socket - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

161

can-fixture-socket.md

@@ -29,26 +29,26 @@ @module {Object} can-fixture-socket

```js
var fixtureSocket = require("can-fixture-socket");
import fixtureSocket from "can-fixture-socket";
// Import socket-io client:
var io = require("socket.io-client");
import io from "socket.io-client";
// Create a mock server that intercepts socket.io:
var mockServer = new fixtureSocket.Server(io);
const mockServer = new fixtureSocket.Server( io );
// Mock server behavior
mockServer.on("connection", function(){
mockServer.emit("notifications", {test: "OK"})
});
mockServer.on( "connection", function() {
mockServer.emit( "notifications", { test: "OK" } );
} );
// Client. Create socket.io connection:
var socket = io("http://localhost:8080/api");
const socket = io( "http://localhost:8080/api" );
// Test your application:
socket.on("connect", function(){
assert.ok(true, "socket connected");
});
socket.on( "connect", function() {
assert.ok( true, "socket connected" );
} );
socket.on("notifications", function(data){
assert.deepEqual(data, {test: "OK"}, "received notifications message");
});
socket.on( "notifications", function( data ) {
assert.deepEqual( data, { test: "OK" }, "received notifications message" );
} );
```

@@ -66,10 +66,11 @@

```js
var socket = io();
socket.on("connect", function(){
socket.emit("messages create", {text: "A new message"});
});
socket.on("message created", function(data){
// data.text === "A new message"
console.log("Server sent out a new message we just created", data);
});
const socket = io();
socket.on( "connect", function() {
socket.emit( "messages create", { text: "A new message" } );
} );
socket.on( "message created", function( data ) {
// data.text === "A new message"
console.log( "Server sent out a new message we just created", data );
} );
```

@@ -80,5 +81,5 @@

```js
var io = require("socket.io-client");
var fixtureSocket = require("can-fixture-socket");
var mockServer = new fixtureSocket.Server(io);
import io from "socket.io-client";
import fixtureSocket from "can-fixture-socket";
const mockServer = new fixtureSocket.Server( io );
```

@@ -89,6 +90,6 @@

```js
mockServer.on("messages create", function(data){
console.log("New message received", data);
mockServer.emit("message created", data);
});
mockServer.on( "messages create", function( data ) {
console.log( "New message received", data );
mockServer.emit( "message created", data );
} );
```

@@ -105,9 +106,9 @@

```js
mockServer.on("users create", function(user, ackCb){
console.log("Simulating saving a new user to DB and return the new user id", user);
mockServer.on( "users create", function( user, ackCb ) {
console.log( "Simulating saving a new user to DB and return the new user id", user );
ackCB({
id: Math.random()
});
});
ackCB( {
id: Math.random()
} );
} );
```

@@ -118,10 +119,11 @@

```js
var socket = io();
socket.on("connect", function(){
socket.emit("users create", {name: "Ilya", likes: "skiing"}, function (data) {
// data is what server calls the acknowledgement callback
// with (e.g. data.id is the new user id).
console.log(data.id);
});
});
const socket = io();
socket.on( "connect", function() {
socket.emit( "users create", { name: "Ilya", likes: "skiing" }, function( data ) {
// data is what server calls the acknowledgement callback
// with (e.g. data.id is the new user id).
console.log( data.id );
} );
} );
```

@@ -135,11 +137,12 @@

// Import can-fixture that provides `store` method for creating a store:
var fixture = require("can-fixture");
var canSet = require("can-set");
import fixture from "can-fixture";
import canSet from "can-set";
// Create a fixture store:
var messagesStore = fixture.store([
{id: 1, title: "One"},
{id: 2, title: "Two"},
{id: 3, title: "Three"}
], new canSet.Algebra({}));
const messagesStore = fixture.store( [
{ id: 1, title: "One" },
{ id: 2, title: "Two" },
{ id: 3, title: "Three" }
], new canSet.Algebra( {} ) );
```

@@ -151,7 +154,7 @@

```js
var fixtureSocket = require("can-fixture-socket");
var io = require("socket.io-client");
var mockServer = new fixtureSocket.Server(io);
import fixtureSocket from "can-fixture-socket";
import io from "socket.io-client";
const mockServer = new fixtureSocket.Server( io );
mockServer.on("messages get", fixtureSocket.requestHandlerToListener( messagesStore.getData ));
mockServer.on( "messages get", fixtureSocket.requestHandlerToListener( messagesStore.getData ) );
```

@@ -162,8 +165,8 @@

```js
var listeners = fixtureSocket.storeToListeners( messagesStore );
mockServer.on({
"messages remove": listeners.destroyData,
"messages create": listeners.createData,
"messages update": listeners.updateData
});
const listeners = fixtureSocket.storeToListeners( messagesStore );
mockServer.on( {
"messages remove": listeners.destroyData,
"messages create": listeners.createData,
"messages update": listeners.updateData
} );
```

@@ -180,9 +183,9 @@

```js
var socket = io("http://api.my-feathers-server.com");
var app = feathers()
.configure(hooks())
.configure(feathersSocketio(socket));
const socket = io( "http://api.my-feathers-server.com" );
const app = feathers()
.configure( hooks() )
.configure( feathersSocketio( socket ) );
// Create FeathersJS CRUD service for "messages" resource:
var messagesService = app.service("messages");
const messagesService = app.service( "messages" );
```

@@ -193,9 +196,9 @@

```js
var messagesStore = fixture.store([
{id: 1, title: "One"},
{id: 2, title: "Two"},
{id: 3, title: "Three"}
], new canSet.Algebra({}));
const messagesStore = fixture.store( [
{ id: 1, title: "One" },
{ id: 2, title: "Two" },
{ id: 3, title: "Three" }
], new canSet.Algebra( {} ) );
mockServer.onFeathersService("messages", fixtureStore);
mockServer.onFeathersService( "messages", fixtureStore );
```

@@ -206,11 +209,11 @@

```js
messagesService.find({}).then(function(data){
assert.equal(data.total, 3, "find should receive 3 items");
});
messagesService.get(1).then(function(data){
assert.deepEqual(data, {id: 1, title: "One"}, "get should receive an item");
});
messagesService.create({title: "Four"}).then(function(data){
assert.equal(data.title, "Four", "create should add an new item");
});
messagesService.find( {} ).then( function( data ) {
assert.equal( data.total, 3, "find should receive 3 items" );
} );
messagesService.get( 1 ).then( function( data ) {
assert.deepEqual( data, { id: 1, title: "One" }, "get should receive an item" );
} );
messagesService.create( { title: "Four" } ).then( function( data ) {
assert.equal( data.title, "Four", "create should add an new item" );
} );
```

@@ -12,11 +12,11 @@ @typedef {function} can-fixture-socket.socket-event-listener SocketEventListener

// Client:
socket.on("news": function handler(data, ackCb){
console.log("received some news", data);
ackCb("Acknowledged", "thank you");
});
socket.on( "news", function handler( data, ackCb ) {
console.log( "received some news", data );
ackCb( "Acknowledged", "thank you" );
} );
// Server:
server.emit("news", {some: "news here"}, function ackFn(...data){
console.log("Client acknowledged data receiving")
});
server.emit( "news", { some: "news here" }, function ackFn( ...data ) {
console.log( "Client acknowledged data receiving" );
} );
```

@@ -23,0 +23,0 @@

@@ -30,9 +30,9 @@ @function can-fixture-socket.Server.prototype.onFeathersService onFeathersService

```js
var fixtureStore = fixture.store([
{_id: 1, title: 'One'},
{_id: 2, title: 'Two'},
{_id: 3, title: 'Three'}
], new canSet.Algebra(canSet.props.id('_id')));
*
mockServer.onFeathersService('messages', fixtureStore, {id: "_id"});
const fixtureStore = fixture.store( [
{ _id: 1, title: "One" },
{ _id: 2, title: "Two" },
{ _id: 3, title: "Three" }
], new canSet.Algebra( canSet.props.id( "_id" ) ) );
mockServer.onFeathersService( "messages", fixtureStore, { id: "_id" } );
```

@@ -45,20 +45,21 @@

// Import dependencies:
var io = require("socket.io-client");
var feathers = require('feathers/client');
var feathersSocketio = require('feathers-socketio/client');
var hooks = require('feathers-hooks');
import io from "socket.io-client";
import feathers from "feathers/client";
import feathersSocketio from "feathers-socketio/client";
import hooks from "feathers-hooks";
// Configure Feathers client app:
var socket = io("http://api.my-feathers-server.com");
var app = feathers()
.configure(hooks())
.configure(feathersSocketio(socket));
const socket = io( "http://api.my-feathers-server.com" );
const app = feathers()
.configure( hooks() )
.configure( feathersSocketio( socket ) );
// Create client Feathers service:
var messagesService = app.service('messages');
const messagesService = app.service( "messages" );
// Test:
messagesService.get(1).then(function(data){
assert.deepEqual(data, {id: 1, title: 'One'}, 'get should receive an item');
});
messagesService.get( 1 ).then( function( data ) {
assert.deepEqual( data, { id: 1, title: "One" }, "get should receive an item" );
} );
```

@@ -12,7 +12,7 @@ @constructor can-fixture-socket.Server Server

- override `io.Manager.prototype` to work with current instance of the mocked server.
```js
var io = require("socket.io-client");
var fixtureSocket = require("can-fixture-socket");
var mockServer = new fixtureSocket.Server(io);
import io from "socket.io-client";
import fixtureSocket from "can-fixture-socket";
const mockServer = new fixtureSocket.Server( io );
```

@@ -28,5 +28,5 @@

```js
var io = require("socket.io-client");
var fixtureSocket = require("can-fixture-socket");
var mockServer = new fixtureSocket.Server(io);
import io from "socket.io-client";
import fixtureSocket from "can-fixture-socket";
const mockServer = new fixtureSocket.Server( io );
```

@@ -36,10 +36,10 @@

```js
mockServer.on("connection", function(){
mockServer.emit("notifications", [{text: "A new notification"}]);
});
mockServer.on( "connection", function() {
mockServer.emit( "notifications", [ { text: "A new notification" } ] );
} );
mockServer.on("some event", function(data, ackCb){
console.log("Client send some ", data);
ackCb("thanks");
});
mockServer.on( "some event", function( data, ackCb ) {
console.log( "Client send some ", data );
ackCb( "thanks" );
} );
```

@@ -49,6 +49,6 @@

```js
var socket = io("http://localhost:8080/ws");
socket.emit("some event", "some data", function(data){
assert.equal(data, "thanks", "Server acknowledged our event");
});
const socket = io( "http://localhost:8080/ws" );
socket.emit( "some event", "some data", function( data ) {
assert.equal( data, "thanks", "Server acknowledged our event" );
} );
```

@@ -63,15 +63,16 @@

```js
var fixture = require("can-fixture");
import fixture from "can-fixture";
// First, lets create fixture store:
var fixtureStore = fixture.store([
{id: 1, title: "One", rank: "good"},
{id: 2, title: "Two", rank: "average"},
{id: 3, title: "Three", rank: "good"}
], new canSet.Algebra({}));
const fixtureStore = fixture.store( [
{ id: 1, title: "One", rank: "good" },
{ id: 2, title: "Two", rank: "average" },
{ id: 3, title: "Three", rank: "good" }
], new canSet.Algebra( {} ) );
// And instantiate a mocked server:
var io = require("socket.io-client");
var fixtureSocket = require("can-fixture-socket");
var mockServer = new fixtureSocket.Server(io);
import io from "socket.io-client";
import fixtureSocket from "can-fixture-socket";
const mockServer = new fixtureSocket.Server( io );
```

@@ -83,8 +84,8 @@

```js
var toListener = fixtureSocket.requestHandlerToListener
mockServer.on("messages find", toListener( fixtureStore.getListData ));
mockServer.on("messages get", toListener( fixtureStore.getData ));
mockServer.on("messages remove", toListener( fixtureStore.destroyData ));
mockServer.on("messages create", toListener( fixtureStore.createData ));
mockServer.on("messages update", toListener( fixtureStore.updateData ));
const toListener = fixtureSocket.requestHandlerToListener;
mockServer.on( "messages find", toListener( fixtureStore.getListData ) );
mockServer.on( "messages get", toListener( fixtureStore.getData ) );
mockServer.on( "messages remove", toListener( fixtureStore.destroyData ) );
mockServer.on( "messages create", toListener( fixtureStore.createData ) );
mockServer.on( "messages update", toListener( fixtureStore.updateData ) );
```

@@ -106,12 +107,12 @@

```js
var socket = io("localhost");
const socket = io( "localhost" );
socket.emit("messages find", {rank: "good"}, function(err, response){
if (err){
console.log("Error: ", err);
return;
}
console.log(`We found ${response.count} good items", response.data);
assert.equal(response.count, 3)
});
socket.emit( "messages find", { rank: "good" }, function( err, response ) {
if ( err ) {
console.log( "Error: ", err );
return;
}
console.log( `We found ${response.count} good items`, response.data );
assert.equal( response.count, 3 );
} );
```

@@ -121,11 +122,15 @@

```js
socket.emit("messages get", {id: 1}, function(err, data){s
assert.deepEqual(data, {id: 1, title: "One"}, "received the item");
});
socket.emit("messages update", {id: 2, title: "TwoPlus"}, function(err, data){
assert.deepEqual(data, {id: 2, title: "TwoPlus"}, "received the updated item");
});
socket.emit("messages get", {id: 999}, function(err, data){
assert.deepEqual(err, {error: 404, message: "no data"}, "received 404 when looking for a non-existent item id");
});
socket.emit( "messages get", { id: 1 }, function( err, data ) {
s;
assert.deepEqual( data, { id: 1, title: "One" }, "received the item" );
} );
socket.emit( "messages update", { id: 2, title: "TwoPlus" }, function( err, data ) {
assert.deepEqual( data, { id: 2, title: "TwoPlus" }, "received the updated item" );
} );
socket.emit( "messages get", { id: 999 }, function( err, data ) {
assert.deepEqual( err,
{ error: 404, message: "no data" },
"received 404 when looking for a non-existent item id"
);
} );
```
{
"name": "can-fixture-socket",
"version": "1.0.0",
"version": "1.0.1",
"description": "Simulate socket connections",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/canjs/can-fixture-socket",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc