GithubHelp home page GithubHelp logo

pcraciunoiu / sockete Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ismasan/sockete

0.0 2.0 0.0 80 KB

Client-side WebSocket mock for easy testing of Websocket clients

Ruby 0.48% JavaScript 94.06% CSS 5.46%

sockete's Introduction

The point

As a websockets client developer

I want to mock the WebSocket object

So I can simulate interaction with a websockets server on the browser

And inspect a log of sent and received messages

And test my client code without the need to setup an actual WebSockets server.

The gist

Sockete.Server.configure('ws://fake.host', function () {
  
  this.onmessage('blah').respond('Ok buddy!');
  
  this.onmessage('Wrong message').fail('So sorry');
  
  // this.onconnect().fail('Nope!')
});

// Replace native window.WebSocket with Sockete.Client

Sockete.mock();

var socket = new WebSocket('ws://fake.host');

socket.readyState // => 1 (CONNECTED)

socket.onmessage = function (evt) {
  console.log(evt.data)
}

socket.send('blah'); // => logs 'Ok buddy!'

socket.send('Wrong message'); // => closes connection and fires socket.onclose()

Install

git pull
bundle install

Test

ruby test/app.rb
open test/index.html

Release

Change version in ./Jfile and build distribution with

jbundle

Commit and push.

TODO

  • Be able to inspect message history on both server and client (kinda the point of this library)
  • Tokenized server URLs and messages, so we can test query variable strings, etc.
  • Be able to facading native Websocket (instead of completely replacing) so we can use with real server while maintaining history and testing capabilities (cool fo running integration tests?)

sockete's People

Contributors

ismasan avatar pcraciunoiu avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.