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

Commit

Permalink
Merge pull request #144 from bem/fix.rootUrl.abs.path
Browse files Browse the repository at this point in the history
Don't use url.resolve to get full url, just join via /
  • Loading branch information
Sergej Tatarincev committed Apr 10, 2015
2 parents bb587e3 + dede56a commit 3f13891
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
8 changes: 5 additions & 3 deletions lib/config/index.js
@@ -1,7 +1,6 @@
'use strict';

var url = require('url'),
path = require('path'),
var path = require('path'),
format = require('util').format,
fs = require('fs'),
yaml = require('js-yaml'),
Expand Down Expand Up @@ -110,7 +109,10 @@ module.exports = inherit({
},

getAbsoluteUrl: function getAbsoluteUrl(relUrl) {
return url.resolve(this.rootUrl, relUrl);
return [
this.rootUrl.replace(/\/$/, ''),
relUrl.replace(/^\//, '')
].join('/');
},

getScreenshotsDir: function(suite, state) {
Expand Down
22 changes: 17 additions & 5 deletions test/config.test.js
Expand Up @@ -3,7 +3,8 @@ var Config = require('../lib/config'),
GeminiError = require('../lib/errors/gemini-error'),
createSuite = require('../lib/suite').create,
sinon = require('sinon'),
extend = require('node.extend');
extend = require('node.extend'),
_ = require('lodash');

describe('config', function() {
beforeEach(function() {
Expand Down Expand Up @@ -607,13 +608,24 @@ describe('config', function() {
});

describe('getAbsoluteUrl', function() {
function mkConfig(data) {
return new Config(_.extend({projectRoot: '/'}, data));
}

it('should resolve url relative to root', function() {
var config = new Config({
projectRoot: '/',
rootUrl: 'http://example.com/path/'
});
var config = mkConfig({rootUrl: 'http://example.com/path/'});
config.getAbsoluteUrl('sub/path').must.be('http://example.com/path/sub/path');
});

it('should ignore slash at the end of the root', function() {
var config = mkConfig({rootUrl: 'http://example.com/path'});
config.getAbsoluteUrl('sub/path').must.be('http://example.com/path/sub/path');
});

it('should ignore slash at the begining of the passed relUrl', function() {
var config = mkConfig({rootUrl: 'http://example.com/path/'});
config.getAbsoluteUrl('/sub/path').must.be('http://example.com/path/sub/path');
});
});

describe('getScreenshotsDir', function() {
Expand Down

0 comments on commit 3f13891

Please sign in to comment.