Skip to content

Commit

Permalink
fix: bug with the substitution of the base host through env var
Browse files Browse the repository at this point in the history
  • Loading branch information
DudaGod committed Aug 29, 2017
1 parent c80999e commit 2b01f9a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
12 changes: 10 additions & 2 deletions lib/view-model.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const _ = require('lodash');
const Uri = require('urijs');
const utils = require('../utils');

const NO_STATE = 'NO_STATE';
Expand Down Expand Up @@ -103,16 +104,17 @@ module.exports = class ViewModel {

_addTestResult(result, props) {
const browserId = result.browserId;
const browserConfig = this._toolConfig.forBrowser(browserId);
const suite = result.suite;
const browserConfig = this._toolConfig.forBrowser(browserId);
const suiteUrl = browserConfig.getAbsoluteUrl(suite.url);
const metaInfo = {
url: suite.fullUrl,
file: suite.file,
sessionId: result.sessionId || 'unknown session id'
};

const testResult = _.assign({
suiteUrl: browserConfig.getAbsoluteUrl(suite.url),
suiteUrl: this._configureSuiteUrl(suiteUrl),
name: browserId,
metaInfo: JSON.stringify(metaInfo, null, 4) || 'Meta info is not available'
}, props);
Expand All @@ -137,6 +139,12 @@ module.exports = class ViewModel {
stateInBrowser.result = testResult;
}

_configureSuiteUrl(suiteUrl) {
return _.isEmpty(this._pluginConfig.baseHost)
? suiteUrl
: Uri(this._pluginConfig.baseHost).resource(suiteUrl).href();
}

static hasFails(node) {
return walk(node, ViewModel.hasFails, node.result && (node.result.error || node.result.fail));
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"gemini-configparser": "^0.4.0",
"handlebars": "^4.0.5",
"lodash": "^4.17.4",
"uglify-js": "^2.7.3"
"uglify-js": "^2.7.3",
"urijs": "^1.18.12"
},
"devDependencies": {
"chai": "^3.5.0",
Expand Down
13 changes: 13 additions & 0 deletions test/lib/view-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,19 @@ describe('ViewModel', () => {
assert.equal(suiteUrl, 'http://expected.url');
});

it('should add base host to suite url from plugin parameter "baseHost"', () => {
const model = mkViewModel_(
{getAbsoluteUrl: sandbox.stub().withArgs('/some/url').returns('http://some.url/bar')},
{baseHost: 'https://some-host.com:1234'}
);

model.addSuccess(stubTest_({suite: {url: '/some/url'}}));

const suiteUrl = getModelResult_(model).suiteUrl;

assert.equal(suiteUrl, 'https://some-host.com:1234/bar');
});

describe('should add base host to result with', () => {
it('empty string if plugin paremeter "baseHost" is not specified', () => {
const model = mkViewModel_();
Expand Down

0 comments on commit 2b01f9a

Please sign in to comment.