UI for Zipcoin Blue

client.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. 'use strict';
  2. var _supertest = require('supertest');
  3. var _supertest2 = _interopRequireDefault(_supertest);
  4. var _assert = require('assert');
  5. var _assert2 = _interopRequireDefault(_assert);
  6. var _url = require('url');
  7. var _listen = require('./helpers/listen');
  8. var _listen2 = _interopRequireDefault(_listen);
  9. var _fayeWebsocket = require('faye-websocket');
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. describe('tiny-lr', function () {
  12. before((0, _listen2.default)());
  13. it('accepts ws clients', function (done) {
  14. var url = (0, _url.parse)(this.request.url);
  15. var server = this.app;
  16. var ws = this.ws = new _fayeWebsocket.Client('ws://' + url.host + '/livereload');
  17. ws.onopen = function (event) {
  18. var hello = {
  19. command: 'hello',
  20. protocols: ['http://livereload.com/protocols/official-7']
  21. };
  22. ws.send(JSON.stringify(hello));
  23. };
  24. ws.onmessage = function (event) {
  25. _assert2.default.deepEqual(event.data, JSON.stringify({
  26. command: 'hello',
  27. protocols: ['http://livereload.com/protocols/official-7'],
  28. serverName: 'tiny-lr'
  29. }));
  30. _assert2.default.ok(Object.keys(server.clients).length);
  31. done();
  32. };
  33. });
  34. it('properly cleans up established connection on exit', function (done) {
  35. var ws = this.ws;
  36. ws.onclose = done.bind(null, null);
  37. (0, _supertest2.default)(this.server).get('/kill').expect(200, function () {});
  38. });
  39. });