{"versions":{"1.0.0":{"name":"eventsourcemock","version":"1.0.0","description":"Mock EventSource in tests.","main":"./lib/index.js","repository":{"type":"git","url":"git+https://github.com/gcedo/eventsourcemock.git"},"scripts":{"flow":"flow","test":"jest","build":"babel src/ -d lib/","format":"prettier --write '{src,__tests__}/**/*.js'","prepublish":"npm run build","precommit":"lint-staged"},"author":{"name":"Edoardo Colombo","email":"edo.gcolombo@gmail.com"},"license":"MIT","devDependencies":{"babel-cli":"^6.24.1","babel-preset-flow":"^6.23.0","babel-preset-latest":"^6.24.1","babel-preset-react":"^6.24.1","enzyme":"^2.8.2","flow-bin":"^0.47.0","husky":"^0.13.4","jest":"^20.0.4","lint-staged":"^3.6.0","prettier":"^1.4.4","react":"^15.5.4","react-addons-test-utils":"^15.5.1","react-dom":"^15.5.4"},"dependencies":{},"lint-staged":{"*.js":["prettier --write","git add"]},"jest":{"setupFiles":["./__test__/configJSDom.js"]},"gitHead":"77c3d4119e99b4e7d240a7b93247502a2299bc4f","bugs":{"url":"https://github.com/gcedo/eventsourcemock/issues"},"homepage":"https://github.com/gcedo/eventsourcemock#readme","_id":"eventsourcemock@1.0.0","_npmVersion":"5.0.0","_nodeVersion":"8.0.0","_npmUser":{"name":"anonymous","email":"edo.gcolombo@gmail.com"},"dist":{"integrity":"sha512-hk2WIB8dvGlPXHrspFONI0EfJQgo/Vi4VawsKSS7ly8V8VftxYHc72NpxMfu7eYRJaBOckHHu2B5IoJDS53VCw==","shasum":"144e474233dd0b293ddb72964c0adc09ae89a065","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/eventsourcemock/-/eventsourcemock-1.0.0.tgz","size":11158},"maintainers":[{"name":"anonymous","email":"edo.gcolombo@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/eventsourcemock-1.0.0.tgz_1497010880658_0.14268346200697124"},"directories":{},"_cnpmcore_publish_time":"2021-12-22T23:52:37.695Z","contributors":[]},"1.0.1":{"name":"eventsourcemock","version":"1.0.1","description":"Mock EventSource in tests.","main":"./lib/index.js","repository":{"type":"git","url":"git+https://github.com/gcedo/eventsourcemock.git"},"scripts":{"flow":"flow","test":"jest","build":"babel src/ -d lib/","format":"prettier --write '{src,__tests__}/**/*.js'","prepublish":"npm run build","precommit":"lint-staged"},"author":{"name":"Edoardo Colombo","email":"edo.gcolombo@gmail.com"},"license":"MIT","devDependencies":{"babel-cli":"^6.24.1","babel-preset-flow":"^6.23.0","babel-preset-latest":"^6.24.1","babel-preset-react":"^6.24.1","enzyme":"^2.8.2","flow-bin":"^0.47.0","husky":"^0.13.4","jest":"^20.0.4","lint-staged":"^3.6.0","prettier":"^1.4.4","react":"^15.5.4","react-addons-test-utils":"^15.5.1","react-dom":"^15.5.4"},"dependencies":{},"lint-staged":{"*.js":["prettier --write","git add"]},"jest":{"setupFiles":["./__test__/configJSDom.js"]},"gitHead":"4bf642a34bd4aa2a59d6dcf7644bbd5b9a93ad52","bugs":{"url":"https://github.com/gcedo/eventsourcemock/issues"},"homepage":"https://github.com/gcedo/eventsourcemock#readme","_id":"eventsourcemock@1.0.1","_npmVersion":"5.0.0","_nodeVersion":"8.0.0","_npmUser":{"name":"anonymous","email":"edo.gcolombo@gmail.com"},"dist":{"integrity":"sha512-U55z5WcTQGT043vdoy3KZJ2JlIzL1zY3NNxb+y6tjplB9qxipYnxD0V1HGh8F7pmMrO//wZLXTjx8iywxyE/fQ==","shasum":"1bcd88f602097c33d4e95f85923bbba7bd847a86","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/eventsourcemock/-/eventsourcemock-1.0.1.tgz","size":12714},"maintainers":[{"name":"anonymous","email":"edo.gcolombo@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/eventsourcemock-1.0.1.tgz_1497016727486_0.1456744617316872"},"directories":{},"_cnpmcore_publish_time":"2021-12-22T23:52:38.824Z","contributors":[]},"1.1.0":{"name":"eventsourcemock","version":"1.1.0","description":"Mock EventSource in tests.","main":"./lib/index.js","repository":{"type":"git","url":"git+https://github.com/gcedo/eventsourcemock.git"},"scripts":{"flow":"flow","test":"jest","build":"babel src/ -d lib/","format":"prettier --write '{src,__tests__}/**/*.js'","prepublish":"npm run build","precommit":"lint-staged"},"author":{"name":"Edoardo Colombo","email":"edo.gcolombo@gmail.com"},"license":"MIT","devDependencies":{"babel-cli":"^6.24.1","babel-preset-flow":"^6.23.0","babel-preset-latest":"^6.24.1","babel-preset-react":"^6.24.1","enzyme":"^2.8.2","flow-bin":"^0.47.0","husky":"^0.13.4","jest":"^20.0.4","lint-staged":"^3.6.0","prettier":"^1.4.4","react":"^15.5.4","react-addons-test-utils":"^15.5.1","react-dom":"^15.5.4"},"dependencies":{},"lint-staged":{"*.js":["prettier --write","git add"]},"jest":{"setupFiles":["./__test__/configJSDom.js"]},"gitHead":"1fe5bad48132a80f52a7225b8bc06cfe6e4006ec","bugs":{"url":"https://github.com/gcedo/eventsourcemock/issues"},"homepage":"https://github.com/gcedo/eventsourcemock#readme","_id":"eventsourcemock@1.1.0","_npmVersion":"5.6.0","_nodeVersion":"8.9.1","_npmUser":{"name":"anonymous","email":"edo.gcolombo@gmail.com"},"dist":{"integrity":"sha512-1/MT6z4PIZW38f8MyCLl5650nCdY6N7/4Uino9eYQOoCnlf2eN0+w5PQWjggTeyC7r1Iu2OpCjbY4Ieaj+4Ngw==","shasum":"388984a51fe1678b5b959bbcf2ca7a6fedff32e9","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/eventsourcemock/-/eventsourcemock-1.1.0.tgz","size":12570},"maintainers":[{"name":"anonymous","email":"edo.gcolombo@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/eventsourcemock-1.1.0.tgz_1515351175612_0.8258998941164464"},"directories":{},"_cnpmcore_publish_time":"2021-12-22T23:52:39.768Z","contributors":[]},"2.0.0":{"name":"eventsourcemock","version":"2.0.0","description":"Mock EventSource in tests.","main":"./lib/index.js","repository":{"type":"git","url":"https://github.com/gcedo/eventsourcemock.git"},"scripts":{"flow":"flow","test":"jest","build":"babel src/ -d lib/","format":"prettier --write '{src,__tests__}/**/*.js'","prepare":"npm run build","precommit":"lint-staged"},"author":{"name":"Edoardo Colombo","email":"edo.gcolombo@gmail.com"},"license":"MIT","devDependencies":{"babel-cli":"^6.24.1","babel-preset-flow":"^6.23.0","babel-preset-latest":"^6.24.1","babel-preset-react":"^6.24.1","enzyme":"^2.8.2","flow-bin":"^0.47.0","husky":"^0.13.4","jest":"^20.0.4","lint-staged":"^3.6.0","prettier":"^1.4.4","react":"^15.5.4","react-addons-test-utils":"^15.5.1","react-dom":"^15.5.4"},"dependencies":{},"lint-staged":{"*.js":["prettier --write","git add"]},"jest":{"setupFiles":["./__test__/configJSDom.js"]},"licenseText":"MIT License\n\nCopyright (c) 2017 Edoardo Colombo\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","_id":"eventsourcemock@2.0.0","dist":{"shasum":"83f66bc537e4909ef385bf84272e300737954ef0","tarball":"http://123.232.10.234:8212/nexus/content/groups/npm-public/eventsourcemock/-/eventsourcemock-2.0.0.tgz","fileCount":25,"unpackedSize":183054,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJa5ixFCRA9TVsSAnZWagAA0PIP/0HmKf9RyP2MqNMHhxBe\n288XFX1gnJmpLKz1279cD3Oef6Ms/+eYvpTEVhF+q3M6PjhTJq2DO+QpbZ1Q\nJU2R1v610ci0vCgVb+loKQWnVrClgTkUlwKg4ibvg5lpRoK7h2T6um/JCpne\nFYV2CY8bZaCaS3ECEHokCVUr4vp3EkqGMT3uscVCoM67k0EnDcd7bgt92ylv\nualQt+zbEbFX9WLs+OdOmvlaIkm9G09EmypwVnkCqGG0fMP63W5xGAvjMoAg\nBGpdrzPsKylwWsDkSW2xYpP1CzrbDkHInj3IekXzFREvGgrusUVPOogogVI4\n8OT7uXyLHZLvK8alpMAtKs3Lmi1jWY46sxYlIAOlhvBldMDxD7jc5CBTUpaL\nF22+28pM0jHBkSAR08t3FMPkXJKI2Kh8cO81/PVpWbf29tE9QvF6TQpB+JoF\n9alVD/UXkwIgOFjs6Tve616e6XVtVge5ctFIwqxHcBs4SBBHsD2KphmyM0o7\nVuYp3ua0zIiMbweLKNs0EIM3MfxgYpcjh+zaY0C/xHbUZjbLMPZLv9i5/6T6\nNCNoiUa+KaZjd635SSsrciWPXYZzDbQARwy4IIG9BvTrmbePPY1OWDT3f9h/\nNJr/vPwFrURuAfet48jcZOxUmpfTQByjft0TkkEsCgRPTsz6gPN0nHEF3Hf8\ngpW6\r\n=f9Cr\r\n-----END PGP SIGNATURE-----\r\n","size":39699,"integrity":"sha512-tSmJnuE+h6A8/hLRg0usf1yL+Q8w01RQtmg0Uzgoxk/HIPZrIUeAr/A4es/8h1wNsoG8RdiESNQLTKiNwbSC3Q=="},"maintainers":[{"name":"anonymous","email":"edo.gcolombo@gmail.com"}],"_npmUser":{"name":"anonymous","email":"edo.gcolombo@gmail.com"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/eventsourcemock_2.0.0_1525034052711_0.776168838325499"},"_cnpmcore_publish_time":"2021-12-22T23:52:39.874Z","contributors":[]}},"dist-tags":{"latest":"2.0.0"},"name":"eventsourcemock","time":{"created":"2022-01-26T18:48:20.776Z","modified":"2022-01-26T18:48:20.776Z","1.0.0":"2017-06-09T12:21:21.619Z","1.0.1":"2017-06-09T13:58:48.377Z","1.1.0":"2018-01-07T18:52:56.546Z","2.0.0":"2018-04-29T20:34:12.778Z"},"readme":"# `eventsourcemock` [![Build Status](https://travis-ci.org/gcedo/eventsourcemock.svg?branch=master)](https://travis-ci.org/gcedo/eventsourcemock)\n\nA dependency free mock for EventSource objects.\n\n\n## Example (with Jest)\n### Setup\nTo setup the mock create a new file where the mock is assigned to the `window` object.\n\n```js\n// __test__/configJSDom.js\nimport EventSource from 'eventsourcemock';\n\nObject.defineProperty(window, 'EventSource', {\n  value: EventSource,\n});\n```\n[Then instruct Jest to use that file during setup in `package.json`](https://facebook.github.io/jest/docs/configuration.html#setupfiles-array).\n```json\n\"jest\": {\n  \"setupFiles\": [\n    \"./__test__/configJSDom.js\"\n  ]\n}\n```\n\n### Usage\nSuppose we want to test this component, which updates its state when a message is received from an `EventSource` instance.\n\n```js\nexport default class Component extends React.Component {\n  props: Props;\n  state: State;\n  source: $PropertyType<window, 'EventSource'>;\n\n  constructor(props: Props) {\n    super(props);\n    this.state = {\n      counter: 0,\n    };\n  }\n\n  componentDidMount() {\n    this.source = new window.EventSource('http://example.com/events');\n    this.source.addEventListener('foo', messageEvent => {\n      this.setState({ counter: parseInt(messageEvent.data, 10) });\n    });\n  }\n\n  componentWillUnmount() {\n    this.source.close();\n  }\n\n  render() {\n    return <div className=\"Component\">{this.state.counter}</div>;\n  }\n}\n```\n\nWe can write a test file that grabs the source from the global `sources` object and simulates messages:\n\n```js\n// @flow\nimport React from 'react';\nimport { mount } from 'enzyme';\n\nimport Component from './Component';\nimport { sources } from 'eventsourcemock';\n\nconst messageEvent = new MessageEvent('foo', {\n  data: '1',\n});\n\ndescribe('update counter on SSE', () => {\n  let wrapper;\n  beforeAll(() => {\n    wrapper = mount(<Component />);\n    sources['http://example.com/events'].emitOpen();\n  });\n\n  it('should initialise counter to 0', () => {\n    expect(wrapper.state('counter')).toBe(0);\n  });\n\n  it('should display \"0\"', () => {\n    expect(wrapper.text()).toBe('0');\n  });\n\n  it('should update the counter to 1', () => {\n    sources['http://example.com/events'].emit(\n      messageEvent.type,\n      messageEvent\n    );\n    expect(wrapper.state('counter')).toBe(1);\n  });\n\n  it('should close the EventSource on unmount', () => {\n    wrapper.unmount();\n    expect(sources['http://example.com/events'].readyState).toBe(2);\n  });\n});\n\n```\n\n## API\n### `sources: { [key: string]: EventSource }`\n`sources` holds the `EventSource` instances created.\n\n```js\nimport { sources } from 'eventsourcemock';\n```\n\n### `EventSource`\n`EventSource` mocks `window.EventSource`, providing methods to simulate messages and errors from the network.\n```js\nimport EventSource from 'eventsourcemock';\n```\n#### Constructor\n```js\nEventSource(\n  url: string,\n  options?: {\n    withCredentials: boolean\n  }\n)\n```\n\n#### Properties\n##### `__emitter`\nA reference to the [node `EventEmitter`](https://nodejs.org/api/events.html#events_class_eventemitter) instance used internally.\n\n##### `onopen`\nSee [eventSource.onopen](https://developer.mozilla.org/en-US/docs/Web/API/EventSource/onopen).\n\n##### `onmessage`\nSee [eventSource.onmessage](https://developer.mozilla.org/en-US/docs/Web/API/EventSource/onmessage).\n\n##### `onerror`\nSee [eventSource.onerror](https://developer.mozilla.org/en-US/docs/Web/API/EventSource/onerror).\n\n##### `readyState`\nSee [eventSource.readyState](https://developer.mozilla.org/en-US/docs/Web/API/EventSource/readyState).\n\n##### `url`\nSee [eventSource.url](https://developer.mozilla.org/en-US/docs/Web/API/EventSource/url).\n\n##### `withCredentials`\nSee [eventSource.withCredentials](https://developer.mozilla.org/en-US/docs/Web/API/EventSource/withCredentials).\n\n\n#### Methods\n##### `emit(eventName: string, messageEvent?: MessageEvent)`\nCalls each of the listeners registered for the event named `eventName`, providing `messageEvent` as argument.\n\n*Example*\n```js\nconst messageEvent = new MessageEvent('type', {\n  data: 'message event data'\n});\nsource.emit(messageEvent.type, messageEvent);\n```\n\n#### `emitOpen()`\nSimulates the opening of a connection. It sets the ready state to open and invokes the callback.\n\n##### `emitMessage(message: any)`\nSimulates dispatching of a message, it invokes the `onmessage` callback.\n\n#### `emitError(error: Error)`\nSimulates dispatching an error event on the `EventSource` instance. Causes `onerror` to be called.\n\n*Example (jest)*\n```js\nconst onErrorSpy = jest.fn();\nconst error = new Error('Something went wrong.');\neventSource.onerror = onErrorSpy;\neventSource.emitError(error);\nexpect(onErrorSpy).toHaveBeenCalledWith(error);\n```\n\n##### `addEventListener(eventName: string, listener: Function)`\nSee [EventTarget.addEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener).\n\n##### `removeEventListener(eventName: string, listener: Function)`\nSee [EventTarget.removeEventListener](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener)\n\n##### `close()`\nSee [EventSource.close](https://developer.mozilla.org/en-US/docs/Web/API/EventSource/close).","users":{}}