diff --git a/lib/config/index.js b/lib/config/index.js index 7826716e4..0705d5ae0 100644 --- a/lib/config/index.js +++ b/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'), @@ -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) { diff --git a/test/config.test.js b/test/config.test.js index 5e6408d39..483ff08bd 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -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() { @@ -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() {