Built motion from commit 76eb00b9e.|1.0.24
[motion.git] / public / bower_components / socket.io-client / test / url.js
1
2 var loc = {};
3 var url = require('../lib/url');
4 var expect = require('expect.js');
5
6 describe('url', function () {
7   it('works with undefined', function () {
8     loc.hostname = 'woot.com';
9     loc.protocol = 'https:';
10     loc.port = 4005;
11     loc.host = loc.hostname + ':' + loc.port;
12     var parsed = url(undefined, loc);
13     expect(parsed.host).to.be('woot.com');
14     expect(parsed.protocol).to.be('https');
15     expect(parsed.port).to.be('4005');
16   });
17
18   it('works with relative paths', function () {
19     loc.hostname = 'woot.com';
20     loc.protocol = 'https:';
21     loc.port = 3000;
22     loc.host = loc.hostname + ':' + loc.port;
23     var parsed = url('/test', loc);
24     expect(parsed.host).to.be('woot.com');
25     expect(parsed.protocol).to.be('https');
26     expect(parsed.port).to.be('3000');
27   });
28
29   it('works with no protocol', function () {
30     loc.protocol = 'http:';
31     var parsed = url('localhost:3000', loc);
32     expect(parsed.host).to.be('localhost');
33     expect(parsed.port).to.be('3000');
34     expect(parsed.protocol).to.be('http');
35   });
36
37   it('works with no schema', function () {
38     loc.protocol = 'http:';
39     var parsed = url('//localhost:3000', loc);
40     expect(parsed.host).to.be('localhost');
41     expect(parsed.port).to.be('3000');
42     expect(parsed.protocol).to.be('http');
43   });
44
45   it('forces ports for unique url ids', function () {
46     var id1 = url('http://google.com:80/');
47     var id2 = url('http://google.com/');
48     var id3 = url('https://google.com/');
49     expect(id1.id).to.be(id2.id);
50     expect(id1.id).to.not.be(id3.id);
51     expect(id2.id).to.not.be(id3.id);
52   });
53
54   it('identifies the namespace', function () {
55     loc.protocol = 'http:';
56     loc.hostname = 'woot.com';
57
58     expect(url('/woot', loc).path).to.be('/woot');
59     expect(url('http://google.com').path).to.be('/');
60     expect(url('http://google.com/').path).to.be('/');
61   });
62
63   it('works with ipv6', function () {
64     var parsed = url('http://[::1]');
65     expect(parsed.protocol).to.be('http');
66     expect(parsed.host).to.be('::1');
67     expect(parsed.port).to.be('80');
68     expect(parsed.id).to.be('http://[::1]:80');
69   });
70
71   it('works with ipv6 location', function () {
72     loc.protocol = 'http:';
73     loc.hostname = '[::1]';
74     loc.port = '';
75     loc.host = loc.hostname + ':' + loc.port;
76
77     var parsed = url(undefined, loc);
78     expect(parsed.protocol).to.be('http');
79     expect(parsed.host).to.be('::1');
80     expect(parsed.port).to.be('80');
81     expect(parsed.id).to.be('http://[::1]:80');
82   });
83 });