Skip to content
Browse files

Minor style changes, add changelog note, more unit tests coverage.

  • Loading branch information...
1 parent 298a6f9 commit fca0ac72fb9dc08dfc84b02b0be5ee1090432d9a @cliffano committed Apr 2, 2013
Showing with 52 additions and 22 deletions.
  1. +1 −0 CHANGELOG.md
  2. +0 −10 lib/console_stream.js
  3. +15 −0 lib/consolestream.js
  4. +8 −12 lib/jenkins.js
  5. +10 −0 test/consolestream.js
  6. +18 −0 test/jenkins.js
View
1 CHANGELOG.md
@@ -2,6 +2,7 @@
* Move proxy environment variable handling to bag.http.request and bag.http.proxy
* Add feed command
* Add jenkins#monitor and ninja command
+* Add jenkins#consoleStream (Whyme Lyu)
### 0.1.1
* Move status colouring to cli so that when lib/jenkins is used programatically then it gets plain uncoloured text
View
10 lib/console_stream.js
@@ -1,10 +0,0 @@
-var inherits = require('util').inherits,
- Stream = require('stream').Stream;
-
-function ConsoleStream() {}
-inherits(ConsoleStream, Stream);
-
-ConsoleStream.prototype.readable = true;
-ConsoleStream.prototype.writable = false;
-
-module.exports = ConsoleStream;
View
15 lib/consolestream.js
@@ -0,0 +1,15 @@
+var stream = require('stream'),
+ util = require('util');
+
+/**
+ * class ConsoleStream
+ * Used for streaming Jenkins console output.
+ */
+function ConsoleStream() {}
+
+util.inherits(ConsoleStream, stream.Stream);
+
+ConsoleStream.prototype.readable = true;
+ConsoleStream.prototype.writable = false;
+
+module.exports = ConsoleStream;
View
20 lib/jenkins.js
@@ -2,12 +2,12 @@
var _ = require('underscore'),
async = require('async'),
bag = require('bagofholding'),
+ ConsoleStream = require('./consolestream'),
cron = require('cron'),
dgram = require('dgram'),
feedparser = require('feedparser'),
request = require('request'),
- xml2js = require('xml2js'),
- ConsoleStream = require('./console_stream');
+ xml2js = require('xml2js');
/**
* class Jenkins
@@ -82,16 +82,12 @@ Jenkins.prototype.build = function (jobName, params, cb) {
* @param {String} jobName: Jenkins job name
* @param {Object} opts: optional interval in milliseconds
* @param {Function} cb: standard cb(err, result) callback
- * @return {ConsoleStream} Returns readable stream
+ * @return {ConsoleStream} readable console output stream
*/
Jenkins.prototype.consoleStream = function(jobName, opts, cb) {
- if (!cb) {
- if (typeof opts === 'function') {
- cb = opts;
- opts = undefined;
- } else {
- cb = function(){};
- }
+ if (!cb && typeof opts === 'function') {
+ cb = opts;
+ opts = undefined;
}
const INTERVAL = 1000;
@@ -145,7 +141,7 @@ Jenkins.prototype.consoleStream = function(jobName, opts, cb) {
this.opts.handlers[200] = _success;
this.opts.handlers[404] = _notFound;
- process.nextTick(function() {
+ process.nextTick(function () {
bag.http.request('get', url, self.opts, cb);
});
@@ -161,7 +157,7 @@ Jenkins.prototype.consoleStream = function(jobName, opts, cb) {
*/
Jenkins.prototype.console = function (jobName, opts, cb) {
var stream = this.consoleStream(jobName, opts, cb);
- stream.pipe(process.stdout, {end: false});
+ stream.pipe(process.stdout, { end: false });
};
/**
View
10 test/consolestream.js
@@ -0,0 +1,10 @@
+var buster = require('buster'),
+ ConsoleStream = require('../lib/consolestream');
+
+buster.testCase('consolestream - consolestream', {
+ 'should be readable but not writable': function () {
+ var consoleStream = new ConsoleStream();
+ assert.isTrue(consoleStream.readable);
+ assert.isFalse(consoleStream.writable);
+ }
+});
View
18 test/jenkins.js
@@ -265,6 +265,24 @@ buster.testCase('jenkins - consoleStream', {
}
});
+buster.testCase('jenkins - console', {
+ 'should pipe console stream to standard output': function (done) {
+ var jenkins = new Jenkins('http://localhost:8080');
+ jenkins.consoleStream = function (jobName, opts, cb) {
+ assert.equals(jobName, 'somejob');
+ assert.equals(opts.interval, 10000);
+ return {
+ pipe: function (dest, opts) {
+ assert.equals(dest, process.stdout);
+ assert.isFalse(opts.end);
+ done();
+ }
+ };
+ };
+ jenkins.console('somejob', { interval: 10000 });
+ }
+});
+
buster.testCase('jenkins - stop', {
'should pass error not found when job does not exist': function (done) {
var mockRequest = function (method, url, opts, cb) {

0 comments on commit fca0ac7

Please sign in to comment.
Something went wrong with that request. Please try again.