Skip to content

Commit

Permalink
Configurable hostname and port for gulp command using command line pa…
Browse files Browse the repository at this point in the history
…rameters or env variables.
  • Loading branch information
jkremser committed Mar 13, 2015
1 parent 8f29a21 commit 58d1637
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
26 changes: 21 additions & 5 deletions gulp/unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ var $ = require('gulp-load-plugins')();

var wiredep = require('wiredep');

var minimist = require('minimist');

var paths = gulp.paths;

function runTests (singleRun) {
Expand Down Expand Up @@ -33,7 +35,7 @@ function runTests (singleRun) {
});
}

function runTestsRest (singleRun, service) {
function runTestsRest (singleRun, service, options) {
var bowerDeps = wiredep({
directory: 'lib',
exclude: ['bootstrap-sass-official'],
Expand All @@ -50,7 +52,11 @@ function runTestsRest (singleRun, service) {
gulp.src(testFiles)
.pipe($.karma({
configFile: 'karma.conf.js',
action: (singleRun)? 'run': 'watch'
action: (singleRun)? 'run': 'watch',
client: {
hostname: options.hostname,
port: options.port
},
}))
.on('error', function (err) {
// Make sure failed tests cause gulp to exit non-zero
Expand All @@ -59,9 +65,19 @@ function runTestsRest (singleRun, service) {
});
}

var knownTestOptions = {
string: ['hostname', 'port'],
default: {
hostname: process.env.HAWKULAR_TEST_HOSTNAME || 'localhost',
port: process.env.HAWKULAR_TEST_PORT || '8080'
}
};

var options = minimist(process.argv.slice(2), knownTestOptions);

gulp.task('test', ['scripts'], function (done) { runTests(true /* singleRun */, done) });
gulp.task('test:auto', ['scripts'], function (done) { runTests(false /* singleRun */, done) });

gulp.task('rest:alert', ['scripts'], function (done) { runTestsRest(true, 'alert', done) });
gulp.task('rest:metric', ['scripts'], function (done) { runTestsRest(true, 'metric', done) });
gulp.task('rest:inventory', ['scripts'], function (done) { runTestsRest(true, 'inventory', done) });
gulp.task('rest:alert', ['scripts'], function (done) { runTestsRest(true, 'alert', options, done) });
gulp.task('rest:metric', ['scripts'], function (done) { runTestsRest(true, 'metric', options, done) });
gulp.task('rest:inventory', ['scripts'], function (done) { runTestsRest(true, 'inventory', options, done) });
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"gulp-uglify": "1.1.0",
"karma-jasmine": "~0.3.1",
"karma-phantomjs-launcher": "~0.1.4",
"minimist": "~1.1.1",
"require-dir": "~0.1.0",
"wiredep": "~2.2.0"
},
Expand Down
5 changes: 4 additions & 1 deletion src/rest/hawkRest-alert-provider.spec.rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ describe('Provider: Hawkular Alerts live REST', function() {
});
};

beforeEach(module('hawkular.services', 'httpReal'));
beforeEach(module('hawkular.services', 'httpReal', function(HawkularAlertProvider) {
HawkularAlertProvider.setHost(__karma__.config.hostname);
HawkularAlertProvider.setPort(__karma__.config.port);
}));

beforeEach(inject(function(_HawkularAlert_, _$resource_, _httpReal_, _$http_) {
HawkularAlert = _HawkularAlert_;
Expand Down
5 changes: 4 additions & 1 deletion src/rest/hawkRest-inventory-provider.spec.rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ describe('Provider: Hawkular live REST', function() {
});
};

beforeEach(module('hawkular.services', 'httpReal'));
beforeEach(module('hawkular.services', 'httpReal', function(HawkularInventoryProvider) {
HawkularInventoryProvider.setHost(__karma__.config.hostname);
HawkularInventoryProvider.setPort(__karma__.config.port);
}));

beforeEach(inject(function(_HawkularInventory_, _$resource_, _httpReal_, _$http_) {
HawkularInventory = _HawkularInventory_;
Expand Down
5 changes: 4 additions & 1 deletion src/rest/hawkRest-metric-factory.spec.rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ describe('Provider: Hawkular live REST', function() {
var HawkularMetric;
var httpReal;

beforeEach(module('hawkular.services', 'httpReal'));
beforeEach(module('hawkular.services', 'httpReal', function(HawkularMetricProvider) {
HawkularMetricProvider.setHost(__karma__.config.hostname);
HawkularMetricProvider.setPort(__karma__.config.port);
}));

beforeEach(inject(function(_HawkularMetric_, _httpReal_) {
HawkularMetric = _HawkularMetric_;
Expand Down

0 comments on commit 58d1637

Please sign in to comment.