3 var url = require('../lib/url');
4 var expect = require('expect.js');
6 describe('url', function () {
7 it('works with undefined', function () {
8 loc.hostname = 'woot.com';
9 loc.protocol = 'https:';
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');
18 it('works with relative paths', function () {
19 loc.hostname = 'woot.com';
20 loc.protocol = 'https:';
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');
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');
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');
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);
54 it('identifies the namespace', function () {
55 loc.protocol = 'http:';
56 loc.hostname = 'woot.com';
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('/');
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');
71 it('works with ipv6 location', function () {
72 loc.protocol = 'http:';
73 loc.hostname = '[::1]';
75 loc.host = loc.hostname + ':' + loc.port;
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');