{"_id":"mock-socket-with-protocol","_rev":"3-5beff88c6770f8596741487031cfc734","name":"mock-socket-with-protocol","dist-tags":{"latest":"7.1.1"},"versions":{"7.1.0":{"name":"mock-socket-with-protocol","version":"7.1.0","description":"Javascript mocking library for websockets and socket.io","main":"./dist/mock-socket","directories":{"test":"tests"},"engines":{"node":">= 4"},"scripts":{"test":"cross-env NODE_ENV=test ava --serial --verbose","test:coverage":"cross-env NODE_ENV=test nyc ava --serial","build":"rm -rf dist && rollup -c rollup.config.js","lint":"eslint src tests","format":"prettier --print-width 120 --single-quote --write '{src,tests}/**/*.js'","precommit":"lint-staged","prepublishOnly":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/lgandecki/mock-socket.git"},"keywords":["websockets","mock","mocksocket","sockets"],"author":{"name":"Travis Hoover"},"license":"MIT","bugs":{"url":"https://github.com/lgandecki/mock-socket/issues"},"homepage":"https://github.com/lgandecki/mock-socket","devDependencies":{"ava":"^0.19.1","babel-core":"^6.24.1","babel-loader":"^7.0.0","babel-polyfill":"^6.23.0","babel-preset-latest":"^6.24.1","cross-env":"^5.0.0","eslint":"^3.19.0","eslint-config-airbnb-base":"^11.2.0","eslint-plugin-import":"^2.0.1","husky":"^0.13.3","jsdom":"^11.5.1","lint-staged":"^3.4.1","nyc":"^10.3.2","prettier":"^1.3.1","rollup":"^0.41.6","rollup-plugin-buble":"^0.15.0","rollup-plugin-commonjs":"^8.2.6","rollup-plugin-node-resolve":"^3.0.0","systemjs":"^0.20.12"},"ava":{"files":["tests/**/*.test.js"],"require":["babel-register","babel-polyfill"],"babel":"inherit"},"lint-staged":{"*.js":["format","lint","git add"]},"dependencies":{"url-parse":"^1.2.0"},"gitHead":"a95f1267129e54e407170155bf117c3a25c8148c","_id":"mock-socket-with-protocol@7.1.0","_npmVersion":"5.6.0","_nodeVersion":"9.3.0","_npmUser":{"name":"lgandecki","email":"lgandecki@thebrain.pro"},"dist":{"integrity":"sha512-ycd/4DXP32YzL1NE9CH2rj7wG4kYVpnW4i1PR3hFzMhZM/+ZfWj8GnWgr4XYo5wIA9bgDTbXl6zzjb+/isJgTw==","shasum":"1e63dc9ba0273f072023667462e58cec0dde42a9","tarball":"https://registry.npmjs.org/mock-socket-with-protocol/-/mock-socket-with-protocol-7.1.0.tgz","fileCount":35,"unpackedSize":936847,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIAwdgK6/56I89DtJh6SEfKnfutH506gEZQ+Z/crhQj9QAiB2hqV//bdnTPeRksDSMlZpGvIblfX/Kn2Hn0hAXl5ejA=="}]},"maintainers":[{"name":"lgandecki","email":"lgandecki@thebrain.pro"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mock-socket-with-protocol_7.1.0_1521293202230_0.9513255109683616"},"_hasShrinkwrap":false},"7.1.1":{"name":"mock-socket-with-protocol","version":"7.1.1","description":"Javascript mocking library for websockets and socket.io, compatible with apollographql subscriptions-transport-ws","main":"./dist/mock-socket","directories":{"test":"tests"},"engines":{"node":">= 4"},"scripts":{"test":"cross-env NODE_ENV=test ava --serial --verbose","test:coverage":"cross-env NODE_ENV=test nyc ava --serial","build":"rm -rf dist && rollup -c rollup.config.js","lint":"eslint src tests","format":"prettier --print-width 120 --single-quote --write '{src,tests}/**/*.js'","precommit":"lint-staged","prepublishOnly":"yarn build"},"repository":{"type":"git","url":"git+https://github.com/TheBrainFamily/mock-socket-with-protocol.git"},"keywords":["websockets","mock","mocksocket","sockets"],"author":{"name":"Travis Hoover"},"license":"MIT","bugs":{"url":"https://github.com/TheBrainFamily/mock-socket-with-protocol/issues"},"homepage":"https://github.com/TheBrainFamily/mock-socket-with-protocol","devDependencies":{"ava":"^0.19.1","babel-core":"^6.24.1","babel-loader":"^7.0.0","babel-polyfill":"^6.23.0","babel-preset-latest":"^6.24.1","cross-env":"^5.0.0","eslint":"^3.19.0","eslint-config-airbnb-base":"^11.2.0","eslint-plugin-import":"^2.0.1","husky":"^0.13.3","jsdom":"^11.5.1","lint-staged":"^3.4.1","nyc":"^10.3.2","prettier":"^1.3.1","rollup":"^0.41.6","rollup-plugin-buble":"^0.15.0","rollup-plugin-commonjs":"^8.2.6","rollup-plugin-node-resolve":"^3.0.0","systemjs":"^0.20.12"},"ava":{"files":["tests/**/*.test.js"],"require":["babel-register","babel-polyfill"],"babel":"inherit"},"lint-staged":{"*.js":["format","lint","git add"]},"dependencies":{"url-parse":"^1.2.0"},"gitHead":"4c7d37369f50e99605ca90f84145a1d854a80d95","_id":"mock-socket-with-protocol@7.1.1","_npmVersion":"5.6.0","_nodeVersion":"9.3.0","_npmUser":{"name":"lgandecki","email":"lgandecki@thebrain.pro"},"dist":{"integrity":"sha512-JZULAR8DOrPiehDWxIXDpP7pxovf7JgsmmfPmEWbppqFlkU+aCAnfQKRdYjA4otFV1tPB/cMzuwPaI8HE0X1XA==","shasum":"b0061c439882fa50f59bb3889bca3e912dd28c90","tarball":"https://registry.npmjs.org/mock-socket-with-protocol/-/mock-socket-with-protocol-7.1.1.tgz","fileCount":35,"unpackedSize":935248,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCB3TlfZR6NmNvUjzZhu0NKC5C6uCVZHzf3NwsrDT3LXQIhAIHYPK0/yXU0pPUBU9jlSLp74aDMT0yhcXNQO/g9yVzQ"}]},"maintainers":[{"name":"lgandecki","email":"lgandecki@thebrain.pro"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mock-socket-with-protocol_7.1.1_1521547379308_0.07181928702779428"},"_hasShrinkwrap":false}},"time":{"created":"2018-03-17T13:26:42.230Z","7.1.0":"2018-03-17T13:26:42.376Z","modified":"2022-05-09T14:45:32.376Z","7.1.1":"2018-03-20T12:02:59.418Z"},"maintainers":[{"name":"lgandecki","email":"lgandecki@thebrain.pro"}],"description":"Javascript mocking library for websockets and socket.io, compatible with apollographql subscriptions-transport-ws","homepage":"https://github.com/TheBrainFamily/mock-socket-with-protocol","keywords":["websockets","mock","mocksocket","sockets"],"repository":{"type":"git","url":"git+https://github.com/TheBrainFamily/mock-socket-with-protocol.git"},"author":{"name":"Travis Hoover"},"bugs":{"url":"https://github.com/TheBrainFamily/mock-socket-with-protocol/issues"},"license":"MIT","readme":"<p align=\"center\">\n  <img width=600 src=\"http://imgur.com/Xt9X83M.png\">\n</p>\n\n<p align=\"center\">\nJavascript mocking library for <a href=\"https://developer.mozilla.org/en-US/docs/WebSockets\">websockets</a> and <a href=\"http://socket.io/\">socket.io</a>\n</p>\n\n## Why?\n\nThis is basically mock-socket made to work with apollo subscriptions-transport-ws.\nThe implementation is not perfect, which was noticed over two years ago by @brian-mann of cypress.io :\nhttps://github.com/thoov/mock-socket/issues/72 . Since two years later this architectural problem is still not fixed,\nI've decided to fork with the tiny change that's just enough to make it work in this specific usecase.\nThanks @thoov for the amazing work on this package! I actually started writing my own websocket server implementation, when, after a half day of happy hacking I came to realization \"this is nodejs.. someone had to got this to work before me\", and there it was. :)\n\n## Installation\n\n```shell\nnpm install mock-socket-with-protocol --dev\n```\n\n## Usage\n\nTo use within a node environment you can simply import or require the files directly. This\noption is great for phantomjs or CI environments.\n\n```js\nimport { WebSocket, Server, SocketIO } from 'mock-socket-with-protocol';\n\n// OR\n\nconst mockServer = require('mock-socket-with-protocol').Server;\nconst socketIO = require('mock-socket-with-protocol').SocketIO;\nconst mockWebSocket = require('mock-socket-with-protocol').WebSocket;\n```\n\n## Native WebSocket Example\n\n```js\n// chat.js\nfunction Chat() {\n  const chatSocket = new WebSocket('ws://localhost:8080');\n  this.messages = [];\n\n  chatSocket.onmessage = (event) => {\n    this.messages.push(event.data);\n  };\n}\n```\n\n```js\n// chat-test.js\nimport { Server } from 'mock-socket-with-protocol';\n\ndescribe('Chat Unit Test', () => {\n  it('basic test', (done) => {\n    const mockServer = new Server('ws://localhost:8080');\n    mockServer.on('connection', server => {\n      mockServer.send('test message 1');\n      mockServer.send('test message 2');\n    });\n\n    // Now when Chat tries to do new WebSocket() it\n    // will create a MockWebSocket object \\\n    var chatApp = new Chat();\n\n    setTimeout(() => {\n      const messageLen = chatApp.messages.length;\n      assert.equal(messageLen, 2, '2 messages where sent from the s server');\n\n      mockServer.stop(done);\n    }, 100);\n  });\n});\n```\n\n## Socket.IO Example\n\n```js\n// chat.js\nfunction Chat() {\n  const chatSocket = new io('http://localhost:8080');\n  this.messages = [];\n\n  chatSocket.on('chat-message', data => {\n    this.messages.push(data);\n  };\n}\n```\n\n```js\n// chat-test.js\nimport { SocketIO, Server } from 'mock-socket-with-protocol';\n\ndescribe('Chat Unit Test', () => {\n  it('basic test', (done) => {\n    const mockServer = new Server('http://localhost:8080');\n    mockServer.on('connection', server => {\n      mockServer.emit('chat-message', 'test message 1');\n      mockServer.emit('chat-message', 'test message 2');\n    });\n\n    /*\n      This step is very important! It tells our chat app to use the mocked\n      websocket object instead of the native one. The great thing\n      about this is that our actual code did not need to change and\n      thus is agnostic to how we test it.\n    */\n    window.io = SocketIO;\n\n    // Now when Chat tries to do io() or io.connect()\n    // it will use MockSocketIO object\n    var chatApp = new Chat();\n\n    setTimeout(() => {\n      const messageLen = chatApp.messages.length;\n      assert.equal(messageLen, 2, '2 messages where sent from the server');\n      mockServer.stop(done);\n    }, 100);\n  });\n});\n```\n\n## Working with the source code\n\n### Local builds\nThe easiest way to work on the project is to clone the repo down via:\n\n```shell\ngit clone git@github.com:TheBrainFamily/mock-socket-with-protocol.git\ncd mock-socket-with-protocol\nyarn\n```\nThen to create a local build via:\n\n```shell\nyarn build\n```\n\nThen create a local npm link via:\n\n```shell\nyarn link\n```\n\nAt this point you can create other projects / apps locally and reference this local build via:\n\n```shell\nyarn link mock-socket-with-protocol\n```\n\nfrom within your other projects folder. Make sure that after any changes you run `yarn build`!\n\n### Tests\nThis project uses mocha as its test framework. Tests are located in /test and have 1 of 3 file name prefixes (functional-, issue-#, or unit-).\n\n```shell\nyarn test\n```\n\n### Linting\n\nThis project uses eslint and a rules set from [airbnb's javascript style guides](https://github.com/airbnb/javascript). To run linting:\n\n```shell\nyarn lint\n```\n\n### Formatting\n\nThis project uses prettier with --single-quote and --print-width 120. To run the formatting:\n\n```shell\nyarn format\n```\n\n\n### Code Coverage\n\nCode coverage reports are created in /coverage after all of the tests have successfully passed. To run the coverage:\n\n```shell\nyarn test:coverage\n```\n\n## Feedback / Issues\n\nIf you have any feedback, encounter any bugs, or just have a question, please feel free to create a [github issue](https://github.com/thoov/mock-socket-with-protocol/issues/new)\n","readmeFilename":"README.md"}