Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
2 parents fc29649 + 93579bb commit ce96b3ab45de522d020235e33fc219c742ea2d35 John Lindal committed Jul 2, 2012
View
@@ -1,5 +1,7 @@
YUI.add('test', function(Y) {
+
+
/**
* YUI Test Framework
* @module test
@@ -10,10 +12,15 @@ YUI.add('test', function(Y) {
* The root namespace for YUI Test.
*/
-var YUITest = {
- version: "@VERSION@"
-};
+//So we only ever have one YUITest object that's shared
+if (YUI.YUITest) {
+ Y.Test = YUI.YUITest;
+} else { //Ends after the YUITest definitions
+ //Make this global for back compat
+ YUITest = {
+ version: "@VERSION@"
+ };
Y.namespace('Test');
@@ -26,7 +33,6 @@ YUITest.Util = {
JSON: Y.JSON
};
-
/**
* Simple custom event implementation.
* @namespace Test
@@ -143,7 +149,6 @@ YUITest.EventTarget.prototype = {
};
-
/**
* A test suite that can contain a collection of TestCase and TestSuite objects.
@@ -228,7 +233,6 @@ YUITest.TestSuite.prototype = {
}
};
-
/**
* Test case containing various tests to run.
* @param template An object containing any number of test methods, other methods,
@@ -377,7 +381,6 @@ YUITest.TestCase.prototype = {
//noop
}
};
-
/**
* An object object containing test result formatting methods.
* @namespace Test
@@ -622,7 +625,6 @@ YUITest.TestFormat = function(){
};
}();
-
/**
* An object capable of sending test results to a server.
@@ -789,7 +791,6 @@ YUITest.TestFormat = function(){
}
};
-
/**
* Runs test suites and test cases, providing events to allowing for the
@@ -1809,7 +1810,6 @@ YUITest.TestFormat = function(){
}();
-
/**
* The ArrayAssert object provides functions to test JavaScript array objects
* for a variety of cases.
@@ -2185,7 +2185,6 @@ YUITest.ArrayAssert = {
}
};
-
/**
* The Assert object provides functions to test JavaScript values against
@@ -2668,7 +2667,6 @@ YUITest.Assert = {
}
};
-
/**
* Error is thrown whenever an assertion fails. It provides methods
* to more easily get at error information and also provides a base class
@@ -2722,7 +2720,6 @@ YUITest.AssertionError.prototype = {
}
};
-
/**
* ComparisonFailure is subclass of Error that is thrown whenever
* a comparison between two values fails. It provides mechanisms to retrieve
@@ -2781,7 +2778,6 @@ YUITest.ComparisonFailure.prototype.getMessage = function(){
return this.message + "\nExpected: " + this.expected + " (" + (typeof this.expected) + ")" +
"\nActual: " + this.actual + " (" + (typeof this.actual) + ")";
};
-
/**
* An object object containing coverage result formatting methods.
* @namespace Test
@@ -2828,7 +2824,6 @@ YUITest.CoverageFormat = {
};
-
/**
* The DateAssert object provides functions to test JavaScript Date objects
* for a variety of cases.
@@ -2913,7 +2908,6 @@ YUITest.DateAssert = {
}
};
-
/**
* Creates a new mock object.
* @namespace Test
@@ -3139,7 +3133,6 @@ YUITest.Mock.Value.Object = YUITest.Mock.Value(YUITest.Assert.isObject);
*/
YUITest.Mock.Value.Function = YUITest.Mock.Value(YUITest.Assert.isFunction);
-
/**
* The ObjectAssert object provides functions to test JavaScript objects
* for a variety of cases.
@@ -3326,7 +3319,6 @@ YUITest.ObjectAssert = {
}
}
};
-
/**
* Convenience type for storing and aggregating
* test result information.
@@ -3402,7 +3394,6 @@ YUITest.Results.prototype.include = function(results){
this.total += results.total;
this.errors += results.errors;
};
-
/**
* ShouldError is subclass of Error that is thrown whenever
* a test is expected to throw an error but doesn't.
@@ -3433,7 +3424,6 @@ YUITest.ShouldError.prototype = new YUITest.AssertionError();
//restore constructor
YUITest.ShouldError.prototype.constructor = YUITest.ShouldError;
-
/**
* ShouldFail is subclass of AssertionError that is thrown whenever
* a test was expected to fail but did not.
@@ -3464,7 +3454,6 @@ YUITest.ShouldFail.prototype = new YUITest.AssertionError();
//restore constructor
YUITest.ShouldFail.prototype.constructor = YUITest.ShouldFail;
-
/**
* UnexpectedError is subclass of AssertionError that is thrown whenever
* an error occurs within the course of a test and the test was not expected
@@ -3511,7 +3500,6 @@ YUITest.UnexpectedError.prototype = new YUITest.AssertionError();
//restore constructor
YUITest.UnexpectedError.prototype.constructor = YUITest.UnexpectedError;
-
/**
* UnexpectedValue is subclass of Error that is thrown whenever
* a value was unexpected in its scope. This typically means that a test
@@ -3563,7 +3551,6 @@ YUITest.UnexpectedValue.prototype.getMessage = function(){
return this.message + "\nUnexpected: " + this.unexpected + " (" + (typeof this.unexpected) + ") ";
};
-
/**
* Represents a stoppage in test execution to wait for an amount of time before
* continuing.
@@ -3593,14 +3580,15 @@ YUITest.Wait = function (segment, delay) {
};
-
//Setting up our aliases..
Y.Test = YUITest;
Y.Object.each(YUITest, function(item, name) {
var name = name.replace('Test', '');
Y.Test[name] = item;
});
+} //End of else in top wrapper
+
Y.Assert = YUITest.Assert;
Y.Assert.Error = Y.Test.AssertionError;
Y.Assert.ComparisonFailure = Y.Test.ComparisonFailure;
@@ -3643,88 +3631,6 @@ Y.assert = function(condition, message){
*/
Y.fail = Y.Assert.fail;
-var logEvent = function(event) {
-
- //data variables
- var message = "";
- var messageType = "";
-
- switch(event.type){
- case this.BEGIN_EVENT:
- message = "Testing began at " + (new Date()).toString() + ".";
- messageType = "info";
- break;
-
- case this.COMPLETE_EVENT:
- message = Y.substitute("Testing completed at " +
- (new Date()).toString() + ".\n" +
- "Passed:{passed} Failed:{failed} " +
- "Total:{total} ({ignored} ignored)",
- event.results);
- messageType = "info";
- break;
-
- case this.TEST_FAIL_EVENT:
- message = event.testName + ": failed.\n" + event.error.getMessage();
- messageType = "fail";
- break;
-
- case this.TEST_IGNORE_EVENT:
- message = event.testName + ": ignored.";
- messageType = "ignore";
- break;
-
- case this.TEST_PASS_EVENT:
- message = event.testName + ": passed.";
- messageType = "pass";
- break;
-
- case this.TEST_SUITE_BEGIN_EVENT:
- message = "Test suite \"" + event.testSuite.name + "\" started.";
- messageType = "info";
- break;
-
- case this.TEST_SUITE_COMPLETE_EVENT:
- message = Y.substitute("Test suite \"" +
- event.testSuite.name + "\" completed" + ".\n" +
- "Passed:{passed} Failed:{failed} " +
- "Total:{total} ({ignored} ignored)",
- event.results);
- messageType = "info";
- break;
-
- case this.TEST_CASE_BEGIN_EVENT:
- message = "Test case \"" + event.testCase.name + "\" started.";
- messageType = "info";
- break;
-
- case this.TEST_CASE_COMPLETE_EVENT:
- message = Y.substitute("Test case \"" +
- event.testCase.name + "\" completed.\n" +
- "Passed:{passed} Failed:{failed} " +
- "Total:{total} ({ignored} ignored)",
- event.results);
- messageType = "info";
- break;
- default:
- message = "Unexpected event " + event.type;
- message = "info";
- }
-
- if (Y.Test.Runner._log) {
- Y.log(message, messageType, "TestRunner");
- }
-}
-
-var i, name;
-
-for (i in Y.Test.Runner) {
- name = Y.Test.Runner[i];
- if (i.indexOf('_EVENT') > -1) {
- Y.Test.Runner.subscribe(name, logEvent);
- }
-};
-
Y.Test.Runner.once = Y.Test.Runner.subscribe;
Y.Test.Runner.disableLogging = function() {
@@ -3740,11 +3646,100 @@ Y.Test.Runner._log = true;
Y.Test.Runner.on = Y.Test.Runner.attach;
-if (Y.config.win) {
- Y.config.win.YUITest = YUITest;
-}
+//Only allow one instance of YUITest
+if (!YUI.YUITest) {
+ if (Y.config.win) {
+ Y.config.win.YUITest = YUITest;
+ }
+
+ YUI.YUITest = Y.Test;
+
+
+ //Only setup the listeners once.
+ var logEvent = function(event) {
+
+ //data variables
+ var message = "";
+ var messageType = "";
+
+ switch(event.type){
+ case this.BEGIN_EVENT:
+ message = "Testing began at " + (new Date()).toString() + ".";
+ messageType = "info";
+ break;
+
+ case this.COMPLETE_EVENT:
+ message = Y.substitute("Testing completed at " +
+ (new Date()).toString() + ".\n" +
+ "Passed:{passed} Failed:{failed} " +
+ "Total:{total} ({ignored} ignored)",
+ event.results);
+ messageType = "info";
+ break;
+
+ case this.TEST_FAIL_EVENT:
+ message = event.testName + ": failed.\n" + event.error.getMessage();
+ messageType = "fail";
+ break;
+
+ case this.TEST_IGNORE_EVENT:
+ message = event.testName + ": ignored.";
+ messageType = "ignore";
+ break;
+
+ case this.TEST_PASS_EVENT:
+ message = event.testName + ": passed.";
+ messageType = "pass";
+ break;
+
+ case this.TEST_SUITE_BEGIN_EVENT:
+ message = "Test suite \"" + event.testSuite.name + "\" started.";
+ messageType = "info";
+ break;
+
+ case this.TEST_SUITE_COMPLETE_EVENT:
+ message = Y.substitute("Test suite \"" +
+ event.testSuite.name + "\" completed" + ".\n" +
+ "Passed:{passed} Failed:{failed} " +
+ "Total:{total} ({ignored} ignored)",
+ event.results);
+ messageType = "info";
+ break;
+
+ case this.TEST_CASE_BEGIN_EVENT:
+ message = "Test case \"" + event.testCase.name + "\" started.";
+ messageType = "info";
+ break;
+
+ case this.TEST_CASE_COMPLETE_EVENT:
+ message = Y.substitute("Test case \"" +
+ event.testCase.name + "\" completed.\n" +
+ "Passed:{passed} Failed:{failed} " +
+ "Total:{total} ({ignored} ignored)",
+ event.results);
+ messageType = "info";
+ break;
+ default:
+ message = "Unexpected event " + event.type;
+ message = "info";
+ }
+
+ if (Y.Test.Runner._log) {
+ Y.log(message, messageType, "TestRunner");
+ }
+ }
+
+ var i, name;
+
+ for (i in Y.Test.Runner) {
+ name = Y.Test.Runner[i];
+ if (i.indexOf('_EVENT') > -1) {
+ Y.Test.Runner.subscribe(name, logEvent);
+ }
+ };
+} //End if for YUI.YUITest
}, '@VERSION@' ,{requires:['event-simulate','event-custom','substitute','json-stringify']});
Oops, something went wrong.

0 comments on commit ce96b3a

Please sign in to comment.