From dcf6f17760ef324cdc473ea78f0977daa66513fe Mon Sep 17 00:00:00 2001 From: Ruslan Login Date: Fri, 12 May 2017 16:41:43 +0300 Subject: [PATCH] feat: make setUrl work like url.resolve --- lib/config/browser-config.js | 7 +++---- test/unit/browser-config.test.js | 6 +++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/config/browser-config.js b/lib/config/browser-config.js index 4ee8c0cb2..f35979654 100644 --- a/lib/config/browser-config.js +++ b/lib/config/browser-config.js @@ -1,6 +1,7 @@ 'use strict'; var path = require('path'), + url = require('url'), _ = require('lodash'); function BrowserConfig(id, systemOptions, browserOptions) { @@ -18,10 +19,8 @@ BrowserConfig.prototype.getScreenshotPath = function(suite, state) { }; BrowserConfig.prototype.getAbsoluteUrl = function(relUrl) { - return [ - this.rootUrl.replace(/\/$/, ''), - relUrl.replace(/^\//, '') - ].join('/'); + const rootUrl = this.rootUrl.endsWith('/') ? this.rootUrl : `${this.rootUrl}/`; + return url.resolve(rootUrl, relUrl); }; function getPathForSuite(suite) { diff --git a/test/unit/browser-config.test.js b/test/unit/browser-config.test.js index 7d212067e..ea5b7f6c4 100644 --- a/test/unit/browser-config.test.js +++ b/test/unit/browser-config.test.js @@ -14,16 +14,16 @@ describe('BrowserConfig', function() { assert.equal(url, 'http://example.com/path/sub/path'); }); - it('should ignore slash at the end of the root', function() { + it('should resolve url without slash at the end of the root', function() { var config = createConfig({rootUrl: 'http://example.com/path'}), url = config.getAbsoluteUrl('sub/path'); assert.equal(url, 'http://example.com/path/sub/path'); }); - it('should ignore slash at the begining of the passed relUrl', function() { + it('should resolve url with slash at the begining of the passed relUrl', function() { var config = createConfig({rootUrl: 'http://example.com/path/'}), url = config.getAbsoluteUrl('/sub/path'); - assert.equal(url, 'http://example.com/path/sub/path'); + assert.equal(url, 'http://example.com/sub/path'); }); });