Permalink
Browse files

Merge branch 'develop' of github.com:yahoo/mojito into multi-appjson

  • Loading branch information...
2 parents 2a191b3 + 16c7a61 commit 18a177a6c1a7190f25832be57163105d9ebf18ed @caridy committed Jan 10, 2013
Showing with 114 additions and 18 deletions.
  1. +3 −4 .travis.yml
  2. +23 −5 lib/management/utils.js
  3. +1 −1 tests/base/mojito-test.js
  4. +1 −1 tests/runall.sh
  5. +86 −7 tests/unit/lib/management/test-utils.server.js
View
@@ -5,7 +5,6 @@ node_js:
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- - "wget http://selenium.googlecode.com/files/selenium-server-standalone-2.25.0.jar"
- - "java -jar selenium-server-standalone-2.25.0.jar -p 4444 > /dev/null 2>&1 &"
- - "sleep 8"
-script: ./tests/runall.sh
+ - "wget -nv http://selenium.googlecode.com/files/selenium-server-standalone-2.28.0.jar"
+ - "java -jar selenium-server-standalone-2.28.0.jar -p 4444 > /dev/null &"
+ - "sleep 6"
View
@@ -14,14 +14,15 @@ var fs = require('fs'),
existsSync = fs.existsSync || path.existsSync,
hb = require('yui/handlebars').Handlebars,
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';
function log(message) {
- console.log(message.cyan.toString());
+ con.log(message.cyan.toString());
}
@@ -41,7 +42,7 @@ function error(message, usage, die) {
msgs.push('\nusage: ' + usage.grey);
}
- console.error(msgs.join(' '));
+ con.error(msgs.join(' '));
if (die) {
process.exit(-1);
@@ -50,12 +51,12 @@ function error(message, usage, die) {
function success(message) {
- console.log(('' + message).green.bold.toString());
+ con.log(('' + message).green.bold.toString());
}
function warn(message) {
- console.warn(('' + message).yellow.toString());
+ con.warn(('' + message).yellow.toString());
}
@@ -525,6 +526,23 @@ function getYUIInstance(modules, callback) {
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;
/**
@@ -215,7 +215,7 @@ YUI.add('mojito-test-extra', function(Y, NAME) {
var A = Y.Assert;
// 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
Y.MOJITO_DIR = require('path').resolve(__dirname, '../../') + '/';
}
View
@@ -1,4 +1,4 @@
-#!/bin/sh -e
+#!/bin/sh -ex
# -e exits on any error; exit code is preserved
fail() {
@@ -35,14 +35,12 @@ YUI().use('test', function(Y) {
}
A.areSame(x, y, msg || 'args should be the same');
}
-
-
+
suite.add(new Y.Test.Case({
name: 'Management Utils tests',
-
- 'decode HTML entities': function() {
+ 'test decode HTML entities': function() {
A.isFunction(libutils.decodeHTMLEntities);
A.areSame('', libutils.decodeHTMLEntities(''));
A.areSame('orange & red', libutils.decodeHTMLEntities('orange & red'));
@@ -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 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);
-
});

0 comments on commit 18a177a

Please sign in to comment.