url.js
1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var loc = {};
var url = require('../lib/url');
var expect = require('expect.js');
describe('url', function(){
it('works with undefined', function(){
loc.hostname = 'woot.com';
loc.protocol = 'https:';
loc.port = 4005;
loc.host = loc.hostname + ':' + loc.port;
var parsed = url(undefined, loc);
expect(parsed.host).to.be('woot.com');
expect(parsed.protocol).to.be('https');
expect(parsed.port).to.be('4005');
});
it('works with relative paths', function(){
loc.hostname = 'woot.com';
loc.protocol = 'https:';
var parsed = url('/test', loc);
expect(parsed.host).to.be('woot.com');
expect(parsed.protocol).to.be('https');
});
it('works with no protocol', function(){
loc.protocol = 'http:';
var parsed = url('localhost:3000', loc);
expect(parsed.host).to.be('localhost');
expect(parsed.port).to.be('3000');
expect(parsed.protocol).to.be('http');
});
it('works with no schema', function(){
loc.protocol = 'http:';
var parsed = url('//localhost:3000', loc);
expect(parsed.host).to.be('localhost');
expect(parsed.port).to.be('3000');
expect(parsed.protocol).to.be('http');
});
it('forces ports for unique url ids', function(){
var id1 = url('http://google.com:80/');
var id2 = url('http://google.com/');
var id3 = url('https://google.com/');
expect(id1.id).to.be(id2.id);
expect(id1.id).to.not.be(id3.id);
expect(id2.id).to.not.be(id3.id);
});
it('identifies the namespace', function(){
loc.protocol = 'http:';
loc.hostname = 'woot.com';
expect(url('/woot', loc).path).to.be('/woot');
expect(url('http://google.com').path).to.be('/');
expect(url('http://google.com/').path).to.be('/');
});
});