|
1 | 1 | import path from 'path'; |
2 | 2 | import fs from 'fs'; |
3 | 3 |
|
4 | | -import { findPlugin, getFileExtension, parseVersion, compareVersions } from '../src/Common/Helpers'; |
| 4 | +import { joinUrl, findPlugin, getFileExtension, parseVersion, compareVersions } from '../src/Common/Helpers'; |
5 | 5 | import WeakMapIterable from '../src/Common/WeakMapIterable'; |
6 | 6 | import VMScript from '../src/Common/VMScript'; |
7 | 7 | import { HtmlParser } from '../src/Common/HtmlParser'; |
@@ -87,6 +87,80 @@ describe('misc', () => { |
87 | 87 | }); |
88 | 88 | }); |
89 | 89 |
|
| 90 | +describe('joinUrl', () => { |
| 91 | + test(`'https://cdn.com', '/path/to'`, () => { |
| 92 | + const received = joinUrl('https://cdn.com', '/path/to'); |
| 93 | + const expected = 'https://cdn.com/path/to'; |
| 94 | + return expect(received).toStrictEqual(expected); |
| 95 | + }); |
| 96 | + |
| 97 | + test(`'https://cdn.com/', 'path/to'`, () => { |
| 98 | + const received = joinUrl('https://cdn.com/', 'path/to'); |
| 99 | + const expected = 'https://cdn.com/path/to'; |
| 100 | + return expect(received).toStrictEqual(expected); |
| 101 | + }); |
| 102 | + |
| 103 | + test(`'https://cdn.com', 'path/to'`, () => { |
| 104 | + const received = joinUrl('https://cdn.com', 'path/to'); |
| 105 | + const expected = 'https://cdn.com/path/to'; |
| 106 | + return expect(received).toStrictEqual(expected); |
| 107 | + }); |
| 108 | + |
| 109 | + test(`'https://cdn.com/v1/', '/path/to'`, () => { |
| 110 | + const received = joinUrl('https://cdn.com/v1/', '/path/to'); |
| 111 | + const expected = 'https://cdn.com/v1/path/to'; |
| 112 | + return expect(received).toStrictEqual(expected); |
| 113 | + }); |
| 114 | + |
| 115 | + test(`'https://cdn.com/v1/', '/path', '/to'`, () => { |
| 116 | + const received = joinUrl('https://cdn.com/v1/', '/path', '/to'); |
| 117 | + const expected = 'https://cdn.com/v1/path/to'; |
| 118 | + return expect(received).toStrictEqual(expected); |
| 119 | + }); |
| 120 | + |
| 121 | + test(`'https://cdn.com/v1/', '/path/', '/to/'`, () => { |
| 122 | + const received = joinUrl('https://cdn.com/v1/', '/path/', '/to/'); |
| 123 | + const expected = 'https://cdn.com/v1/path/to'; |
| 124 | + return expect(received).toStrictEqual(expected); |
| 125 | + }); |
| 126 | + |
| 127 | + test(`'//cdn.com/v1/', '/path/', '/to/'`, () => { |
| 128 | + const received = joinUrl('//cdn.com/v1/', '/path/', '/to/'); |
| 129 | + const expected = '//cdn.com/v1/path/to'; |
| 130 | + return expect(received).toStrictEqual(expected); |
| 131 | + }); |
| 132 | + |
| 133 | + test(`'/', 'path', 'to/'`, () => { |
| 134 | + const received = joinUrl('/', 'path', 'to/'); |
| 135 | + const expected = '/path/to'; |
| 136 | + return expect(received).toStrictEqual(expected); |
| 137 | + }); |
| 138 | + |
| 139 | + test(`'/path', ''`, () => { |
| 140 | + const received = joinUrl('/path', ''); |
| 141 | + const expected = '/path'; |
| 142 | + return expect(received).toStrictEqual(expected); |
| 143 | + }); |
| 144 | + |
| 145 | + test(`'/path', '', ''`, () => { |
| 146 | + const received = joinUrl('/path', '', ''); |
| 147 | + const expected = '/path'; |
| 148 | + return expect(received).toStrictEqual(expected); |
| 149 | + }); |
| 150 | + |
| 151 | + test(`'/path', '', '', 'to', ''`, () => { |
| 152 | + const received = joinUrl('/path', '', '', 'to', ''); |
| 153 | + const expected = '/path/to'; |
| 154 | + return expect(received).toStrictEqual(expected); |
| 155 | + }); |
| 156 | + |
| 157 | + test(`'/path'`, () => { |
| 158 | + const received = joinUrl('/path'); |
| 159 | + const expected = '/path'; |
| 160 | + return expect(received).toStrictEqual(expected); |
| 161 | + }); |
| 162 | +}); |
| 163 | + |
90 | 164 | describe('compareVersions', () => { |
91 | 165 | test('1.2.99 < 1.2.100', () => { |
92 | 166 | const expected = compareVersions('1.2.99', '<', '1.2.100'); |
|
0 commit comments