blob: 2fa664a446c3daa16eb5fab1aed0ecb172638ffa [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001
2import request from 'supertest';
3import assert from 'assert';
4import {parse} from 'url';
5import listen from './helpers/listen';
6import {Client as WebSocket} from 'faye-websocket';
7
8describe('tiny-lr', () => {
9 before(listen());
10 it('accepts ws clients', function (done) {
11 const url = parse(this.request.url);
12 const server = this.app;
13
14 const ws = this.ws = new WebSocket('ws://' + url.host + '/livereload');
15
16 ws.onopen = event => {
17 const hello = {
18 command: 'hello',
19 protocols: ['http://livereload.com/protocols/official-7']
20 };
21
22 ws.send(JSON.stringify(hello));
23 };
24
25 ws.onmessage = event => {
26 assert.deepEqual(event.data, JSON.stringify({
27 command: 'hello',
28 protocols: ['http://livereload.com/protocols/official-7'],
29 serverName: 'tiny-lr'
30 }));
31
32 assert.ok(Object.keys(server.clients).length);
33 done();
34 };
35 });
36
37 it('properly cleans up established connection on exit', function (done) {
38 const ws = this.ws;
39
40 ws.onclose = done.bind(null, null);
41
42 request(this.server)
43 .get('/kill')
44 .expect(200, () => {});
45 });
46});