From 53b71ed48c92bb3a03a5875514701d9ce2f8050c Mon Sep 17 00:00:00 2001 From: Kirill Enykeev Date: Thu, 28 Jan 2016 13:40:05 +0600 Subject: [PATCH] Update tests to support single port depolyment and custom server --- gulpfile.js | 4 +++- package.json | 4 +++- tests/test-actions.js | 4 ++-- tests/test-history.js | 8 ++++---- tests/test-rules.js | 6 +++--- tests/util.js | 28 ++++++++++++++++++++++++++-- 6 files changed, 41 insertions(+), 13 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 098aec111..c26bb73f4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -23,10 +23,12 @@ var gulp = require('gulp') , header = require('gulp-header') , git = require('git-rev-sync') , pkg = require('./package.json') + , yargs = require('yargs') ; var express = require('express') , server + , argv = yargs.argv , app = express(); app.use(express.static(__dirname)); @@ -149,7 +151,7 @@ gulp.task('serve', ['build'], function () { }); gulp.task('test', ['build', 'serve'], function () { - return gulp.src('tests/**/test-*.js', {read: false}) + return gulp.src(argv['test-files'] || 'tests/**/test-*.js', {read: false}) .pipe(mocha({ reporter: 'dot' })) diff --git a/package.json b/package.json index 03b9a6319..2e7c84294 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,8 @@ }, "repository": "stackstorm/st2web", "dependencies": { - "st2client": "^0.4.3" + "st2client": "^0.4.3", + "urijs": "^1.17.0" }, "devDependencies": { "chai": "^3.3.0", @@ -37,6 +38,7 @@ "main-bower-files": "^2.4.0", "request": "^2.49.0", "yamljs": "^0.2.4", + "yargs": "^3.32.0", "zombie": "https://github.com/enykeev/zombie/releases/download/enykeev-1/zombie-4.1.0.tgz" } } diff --git a/tests/test-actions.js b/tests/test-actions.js index d37986bb1..551b44f83 100644 --- a/tests/test-actions.js +++ b/tests/test-actions.js @@ -31,7 +31,7 @@ describe('User visits actions page', function () { before(function () { resource = browser.resources.filter(function (e) { - return new RegExp('^http://172.168.60.10:9101/v1/actions$').test(e.url); + return new RegExp('^https://example.com/api/v1/actions$').test(e.url); }); }); @@ -58,7 +58,7 @@ describe('User visits actions page', function () { before(function () { resource = browser.resources.filter(function (e) { - return new RegExp('^http://172.168.60.10:9101/v1/actions/views/overview/[\\w.-]+$').test(e.url); + return new RegExp('^https://example.com/api/v1/actions/views/overview/[\\w.-]+$').test(e.url); }); }); diff --git a/tests/test-history.js b/tests/test-history.js index db3e03201..eaa1127e7 100644 --- a/tests/test-history.js +++ b/tests/test-history.js @@ -31,7 +31,7 @@ describe('User visits history page', function () { before(function () { resource = browser.resources.filter(function (e) { - return ~e.url.indexOf('http://172.168.60.10:9101/v1/executions?'); //jshint ignore:line + return ~e.url.indexOf('https://example.com/api/v1/executions?'); //jshint ignore:line }); }); @@ -59,7 +59,7 @@ describe('User visits history page', function () { before(function () { resource = browser.resources.filter(function (e) { - return new RegExp('^http://172.168.60.10:9101/v1/executions/\\w+$').test(e.url); + return new RegExp('^https://example.com/api/v1/executions/\\w+$').test(e.url); }); }); @@ -85,7 +85,7 @@ describe('User visits history page', function () { browser.assert.text(util.name('header_description'), execution.action.description, 'Wrong description in header'); browser.assert.text(util.name('status'), util.capitalize(execution.status), 'Wrong status'); - browser.assert.attribute(util.name('execution_id'), 'value', execution.id, 'Wrong execution id'); + browser.assert.text(util.name('execution_id'), execution.id, 'Wrong execution id'); browser.assert.text(util.name('start_timestamp'), util.formatUTC(execution.start_timestamp), 'Wrong start time'); browser.assert.text(util.name('end_timestamp'), util.formatUTC(execution.end_timestamp), 'Wrong end time'); @@ -122,7 +122,7 @@ describe('User visits history page', function () { browser.assert.elements(util.name('rerun_popup'), 0, 'Rerun popup is in DOM when it should not be'); var resource = browser.resources.filter(function (e) { - return e.request.method === 'POST' && new RegExp('^http://172.168.60.10:9101/v1/executions/\\w+/re_run$').test(e.url); + return e.request.method === 'POST' && new RegExp('^https://example.com/api/v1/executions/\\w+/re_run$').test(e.url); }); expect(resource).to.have.length(1, 'Rerun should make a single request'); diff --git a/tests/test-rules.js b/tests/test-rules.js index 877c8ef1c..43c1ab7f9 100644 --- a/tests/test-rules.js +++ b/tests/test-rules.js @@ -31,7 +31,7 @@ describe('User visits rules page', function () { before(function () { resource = browser.resources.filter(function (e) { - return new RegExp('^http://172.168.60.10:9101/v1/rules/views$').test(e.url); + return new RegExp('^https://example.com/api/v1/rules/views$').test(e.url); }); }); @@ -58,7 +58,7 @@ describe('User visits rules page', function () { before(function () { resource = browser.resources.filter(function (e) { - var match = e.url.match(new RegExp('^http://172.168.60.10:9101/v1/rules/([\\w.-]+)$')); + var match = e.url.match(new RegExp('^https://example.com/api/v1/rules/([\\w.-]+)$')); return match && match[1] && match[1] !== 'views'; }); }); @@ -83,7 +83,7 @@ describe('User visits rules page', function () { browser.assert.element(util.name('delete_button'), 'Delete button is missing'); browser.assert.text(util.name('status'), rule.enabled ? 'Enabled' : 'Disabled', 'Wrong status'); - browser.assert.text(util.name('header_name'), rule.name, 'Wrong name in header'); + browser.assert.text(util.name('header_name'), rule.ref, 'Wrong ref in header'); browser.assert.text(util.name('header_description'), rule.description, 'Wrong description in header'); browser.assert.text(util.name('header_if'), 'If ' + rule.trigger.ref, 'Wrong if in header'); browser.assert.text(util.name('header_then'), 'Then ' + rule.action.ref, 'Wrong then in header'); diff --git a/tests/util.js b/tests/util.js index 92247db43..39e2869c3 100644 --- a/tests/util.js +++ b/tests/util.js @@ -1,12 +1,36 @@ /* jshint node:true */ 'use strict'; +var URI = require('urijs'); + +process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; module.exports = function (browser) { + browser.pipeline.addHandler(function(browser, request) { + var url = new URI(request.url); + + if (url.directory().match(/^\/auth/) || url.directory().match(/^\/api/)) { + request.url = url.host(process.env.ST2_HOST).toString(); + } + + return null; + }); + + browser.pipeline.addHandler(function(browser, request, response) { + var url = new URI(response.url); + + if (url.host() === process.env.ST2_HOST) { + response._url = url.host('example.com').toString(); + request.url = response.url; + } + + return response; + }); + return { login: function () { return browser - .fill('username', 'testu') - .fill('password', 'testp') + .fill('username', process.env.ST2_USERNAME) + .fill('password', process.env.ST2_PASSWORD) .pressButton('Connect'); }, capitalize: function (str) {