Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:yahoo/mojito into multi-appjson
Browse files Browse the repository at this point in the history
  • Loading branch information
caridy committed Jan 10, 2013
2 parents 2a191b3 + 16c7a61 commit 18a177a
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 18 deletions.
7 changes: 3 additions & 4 deletions .travis.yml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ node_js:
before_install: before_install:
- "export DISPLAY=:99.0" - "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start" - "sh -e /etc/init.d/xvfb start"
- "wget http://selenium.googlecode.com/files/selenium-server-standalone-2.25.0.jar" - "wget -nv http://selenium.googlecode.com/files/selenium-server-standalone-2.28.0.jar"
- "java -jar selenium-server-standalone-2.25.0.jar -p 4444 > /dev/null 2>&1 &" - "java -jar selenium-server-standalone-2.28.0.jar -p 4444 > /dev/null &"
- "sleep 8" - "sleep 6"
script: ./tests/runall.sh
28 changes: 23 additions & 5 deletions lib/management/utils.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ var fs = require('fs'),
existsSync = fs.existsSync || path.existsSync, existsSync = fs.existsSync || path.existsSync,
hb = require('yui/handlebars').Handlebars, hb = require('yui/handlebars').Handlebars,
colors = require('colors'), colors = require('colors'),
NO_TTY = !process.stdout.isTTY || !process.stderr.isTTY; NO_TTY = !process.stdout.isTTY || !process.stderr.isTTY,
con = console;




colors.mode = NO_TTY ? 'none' : 'console'; colors.mode = NO_TTY ? 'none' : 'console';




function log(message) { function log(message) {
console.log(message.cyan.toString()); con.log(message.cyan.toString());
} }




Expand All @@ -41,7 +42,7 @@ function error(message, usage, die) {
msgs.push('\nusage: ' + usage.grey); msgs.push('\nusage: ' + usage.grey);
} }


console.error(msgs.join(' ')); con.error(msgs.join(' '));


if (die) { if (die) {
process.exit(-1); process.exit(-1);
Expand All @@ -50,12 +51,12 @@ function error(message, usage, die) {




function success(message) { function success(message) {
console.log(('✔ ' + message).green.bold.toString()); con.log(('✔ ' + message).green.bold.toString());
} }




function warn(message) { function warn(message) {
console.warn(('⚠ ' + message).yellow.toString()); con.warn(('⚠ ' + message).yellow.toString());
} }




Expand Down Expand Up @@ -525,6 +526,23 @@ function getYUIInstance(modules, callback) {
return y; return y;
} }


/**
* Used for unit testing.
* @private
* @method setConsole
* @param {Object} mocked console
* @return {nothing}
*/
function setConsole(x) {
con = x;
}

exports.test = {
setConsole: setConsole
};

/**
*/
exports.getYUIInstance = getYUIInstance; exports.getYUIInstance = getYUIInstance;


/** /**
Expand Down
2 changes: 1 addition & 1 deletion tests/base/mojito-test.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ YUI.add('mojito-test-extra', function(Y, NAME) {
var A = Y.Assert; var A = Y.Assert;


// move to mojito-test, under Y.mojito namespace? i.e. Y.mojito.BASEDIR // move to mojito-test, under Y.mojito namespace? i.e. Y.mojito.BASEDIR
if (require && ('function' === typeof require.resolve)) { if (('undefined' !== typeof require) && ('function' === typeof require.resolve)) {
// define the abs path to the mojito base dir on nodejs only // define the abs path to the mojito base dir on nodejs only
Y.MOJITO_DIR = require('path').resolve(__dirname, '../../') + '/'; Y.MOJITO_DIR = require('path').resolve(__dirname, '../../') + '/';
} }
Expand Down
2 changes: 1 addition & 1 deletion tests/runall.sh
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh -e #!/bin/sh -ex
# -e exits on any error; exit code is preserved # -e exits on any error; exit code is preserved


fail() { fail() {
Expand Down
93 changes: 86 additions & 7 deletions tests/unit/lib/management/test-utils.server.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ YUI().use('test', function(Y) {
} }
A.areSame(x, y, msg || 'args should be the same'); A.areSame(x, y, msg || 'args should be the same');
} }



suite.add(new Y.Test.Case({ suite.add(new Y.Test.Case({


name: 'Management Utils tests', name: 'Management Utils tests',



'test decode HTML entities': function() {
'decode HTML entities': function() {
A.isFunction(libutils.decodeHTMLEntities); A.isFunction(libutils.decodeHTMLEntities);
A.areSame('', libutils.decodeHTMLEntities('')); A.areSame('', libutils.decodeHTMLEntities(''));
A.areSame('orange & red', libutils.decodeHTMLEntities('orange & red')); A.areSame('orange & red', libutils.decodeHTMLEntities('orange & red'));
Expand All @@ -52,12 +50,93 @@ YUI().use('test', function(Y) {
A.areSame('orange & red', libutils.decodeHTMLEntities('orange & red')); A.areSame('orange & red', libutils.decodeHTMLEntities('orange & red'));
A.areSame('orange © red', libutils.decodeHTMLEntities('orange © red')); A.areSame('orange © red', libutils.decodeHTMLEntities('orange © red'));
A.areSame('orange y red', libutils.decodeHTMLEntities('orange y red')); A.areSame('orange y red', libutils.decodeHTMLEntities('orange y red'));
} },

'test log': function() {
var mockConsole = Y.Mock();
Y.Mock.expect(mockConsole, {
method:"log",
args: [Y.Mock.Value.String],
run: function (message) {
A.isTrue(/test log/.test(message));
}
});
libutils.test.setConsole(mockConsole);
libutils.log("test log");
},

'test error string': function() {
var mockConsole = Y.Mock();
Y.Mock.expect(mockConsole, {
method:"error",
args: [Y.Mock.Value.String],
run: function (message) {
A.isTrue(/Error found/.test(message));
}
});
libutils.test.setConsole(mockConsole);
libutils.error("Error found");
},

'test error usage': function() {
var mockConsole = Y.Mock();
Y.Mock.expect(mockConsole, {
method:"error",
args: [Y.Mock.Value.String],
run: function (message) {
A.isTrue(/Error found/.test(message));
A.isTrue(/usage: /.test(message));
A.isTrue(/for this test/.test(message));
}
});
libutils.test.setConsole(mockConsole);
libutils.error("Error found", "for this test", false);
},

'test error object': function() {
var mockConsole = Y.Mock();
Y.Mock.expect(mockConsole, {
method:"error",
args: [Y.Mock.Value.Any],
run: function (err) {
A.isTrue(/Error found/.test(err));
}
});
err = new Error();
err.name = "myerr";
err.stack = true;
err.message = "Error found";
libutils.test.setConsole(mockConsole);
libutils.error(err);
},

'test success': function() {
var mockConsole = Y.Mock();
Y.Mock.expect(mockConsole, {
method:"log",
args: [Y.Mock.Value.String],
run: function (message) {
A.isTrue(/Successed!/.test(message));
}
});
libutils.test.setConsole(mockConsole);
libutils.success("Successed!");
},


'test warn': function() {
var mockConsole = Y.Mock();
Y.Mock.expect(mockConsole, {
method:"warn",
args: [Y.Mock.Value.String],
run: function (message) {
A.isTrue(/AlertAlert/.test(message));
}
});
libutils.test.setConsole(mockConsole);
libutils.warn("AlertAlert");
}


})); }));



Y.Test.Runner.add(suite); Y.Test.Runner.add(suite);

}); });

0 comments on commit 18a177a

Please sign in to comment.