Skip to content
This repository was archived by the owner on Sep 21, 2022. It is now read-only.

Commit dcf6f17

Browse files
committed
feat: make setUrl work like url.resolve
1 parent 6cd6c99 commit dcf6f17

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

lib/config/browser-config.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var path = require('path'),
4+
url = require('url'),
45
_ = require('lodash');
56

67
function BrowserConfig(id, systemOptions, browserOptions) {
@@ -18,10 +19,8 @@ BrowserConfig.prototype.getScreenshotPath = function(suite, state) {
1819
};
1920

2021
BrowserConfig.prototype.getAbsoluteUrl = function(relUrl) {
21-
return [
22-
this.rootUrl.replace(/\/$/, ''),
23-
relUrl.replace(/^\//, '')
24-
].join('/');
22+
const rootUrl = this.rootUrl.endsWith('/') ? this.rootUrl : `${this.rootUrl}/`;
23+
return url.resolve(rootUrl, relUrl);
2524
};
2625

2726
function getPathForSuite(suite) {

test/unit/browser-config.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ describe('BrowserConfig', function() {
1414
assert.equal(url, 'http://example.com/path/sub/path');
1515
});
1616

17-
it('should ignore slash at the end of the root', function() {
17+
it('should resolve url without slash at the end of the root', function() {
1818
var config = createConfig({rootUrl: 'http://example.com/path'}),
1919
url = config.getAbsoluteUrl('sub/path');
2020
assert.equal(url, 'http://example.com/path/sub/path');
2121
});
2222

23-
it('should ignore slash at the begining of the passed relUrl', function() {
23+
it('should resolve url with slash at the begining of the passed relUrl', function() {
2424
var config = createConfig({rootUrl: 'http://example.com/path/'}),
2525
url = config.getAbsoluteUrl('/sub/path');
26-
assert.equal(url, 'http://example.com/path/sub/path');
26+
assert.equal(url, 'http://example.com/sub/path');
2727
});
2828
});
2929

0 commit comments

Comments
 (0)