forked from parcel-bundler/parcel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathurl-join.js
74 lines (63 loc) · 1.98 KB
/
url-join.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
const assert = require('assert');
const urlJoin = require('../src/utils/urlJoin');
describe('Url Join', () => {
it('should join a filename with a URL', () => {
assert.equal(
urlJoin('https://parceljs.org', 'a.js'),
'https://parceljs.org/a.js'
);
});
it('should join a path with a URL', () => {
assert.equal(
urlJoin('https://parceljs.org', 'bar/a.js'),
'https://parceljs.org/bar/a.js'
);
});
it('should join a paths together', () => {
assert.equal(
urlJoin('https://parceljs.org/foo/', 'bar/a.js'),
'https://parceljs.org/foo/bar/a.js'
);
});
it('should join an absolute path with a URL', () => {
assert.equal(
urlJoin('https://parceljs.org/foo/', '/bar/a.js'),
'https://parceljs.org/foo/bar/a.js'
);
});
it('should join a URL with a querystring', () => {
assert.equal(
urlJoin('https://parceljs.org/foo', '/bar/a.js?a=123'),
'https://parceljs.org/foo/bar/a.js?a=123'
);
assert.equal(
urlJoin('https://parceljs.org/foo', '/bar/a.js?a=123&b=456'),
'https://parceljs.org/foo/bar/a.js?a=123&b=456'
);
});
it('should join a URL with a hash', () => {
assert.equal(
urlJoin('https://parceljs.org/foo', '/bar/a.js#hello'),
'https://parceljs.org/foo/bar/a.js#hello'
);
assert.equal(
urlJoin('https://parceljs.org/foo', '/bar/a.js?a=123&b=456#hello'),
'https://parceljs.org/foo/bar/a.js?a=123&b=456#hello'
);
});
it('should join two paths together', () => {
assert.equal(
urlJoin('/Users/people/projects/parcel', '/bar/foo.js'),
'/Users/people/projects/parcel/bar/foo.js'
);
});
it('should support windows paths', () => {
assert.equal(urlJoin('dist\\foo', '\\bar\\foo.js'), 'dist/foo/bar/foo.js');
});
it('should parse double slashes as host', () => {
assert.equal(
urlJoin('//parceljs.org/foo', 'bar/a.js?a=123&b=456#hello'),
'//parceljs.org/foo/bar/a.js?a=123&b=456#hello'
);
});
});