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

Commit

Permalink
feat: make setUrl work like url.resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
realzoberg committed May 25, 2017
1 parent 6cd6c99 commit dcf6f17
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
7 changes: 3 additions & 4 deletions lib/config/browser-config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var path = require('path'),
url = require('url'),
_ = require('lodash');

function BrowserConfig(id, systemOptions, browserOptions) {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions test/unit/browser-config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

Expand Down

0 comments on commit dcf6f17

Please sign in to comment.